Skip to content

Commit

Permalink
Merge pull request #910 from FashionFreedom/issue-909-improve-printin…
Browse files Browse the repository at this point in the history
…g-measurements

feat: add copy to clipboard and measurement number to table
  • Loading branch information
slspencer committed Mar 27, 2023
2 parents fdd4e81 + fb19237 commit 9eb734f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 31 deletions.
89 changes: 69 additions & 20 deletions src/app/seamlyme/tmainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/***************************************************************************
* *
* Copyright (C) 2017 Seamly, LLC *
* *
* https://github.com/fashionfreedom/seamly2d *
* *
***************************************************************************
** @file tmainwindow.cpp
** @author Douglas S Caskey
** @date Mar 25, 2023
**
** @copyright
** Copyright (C) 2015 - 2023 Seamly, LLC
** https://github.com/fashionfreedom/seamly2d
**
** @brief
** Seamly2D is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,11 +19,10 @@
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

 ************************************************************************
/************************************************************************
**
** @file tmainwindow.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
Expand Down Expand Up @@ -72,6 +73,7 @@
#include "version.h"
#include "mapplication.h" // Should be last because of definning qApp

#include <QClipboard>
#include <QComboBox>
#include <QFileDialog>
#include <QFileInfo>
Expand Down Expand Up @@ -99,7 +101,7 @@ Q_LOGGING_CATEGORY(tMainWindow, "t.mainwindow")
QT_WARNING_POP

// We need this enum in case we will add or delete a column. And also make code more readable.
enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBaseValue, ColumnInSizes, ColumnInHeights};
enum {ColumnName = 0, ColumnNumber, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBaseValue, ColumnInSizes, ColumnInHeights};

//---------------------------------------------------------------------------------------------------------------------
TMainWindow::TMainWindow(QWidget *parent)
Expand Down Expand Up @@ -757,7 +759,7 @@ void TMainWindow::print()
}
else
{
columns = 4;
columns = 5;
}
int rows = ui->tableWidget->rowCount();

Expand All @@ -769,10 +771,6 @@ void TMainWindow::print()
height += ui->tableWidget->rowHeight(i);
}

ui->tableWidget->setFixedSize(width, height);
ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

QPrintPreviewDialog *dialog = new QPrintPreviewDialog(this);
connect(dialog, &QPrintPreviewDialog::paintRequested, this, &TMainWindow::printPages);

Expand All @@ -790,7 +788,7 @@ void TMainWindow::printPages(QPrinter *printer)
}
else
{
columns = 4;
columns = 5;
}

QTextDocument doc;
Expand Down Expand Up @@ -839,7 +837,7 @@ void TMainWindow::printPages(QPrinter *printer)
ui->tableWidget->setItem(i, j, new QTableWidgetItem(""));
}
}
if (j > 1)
if (j == 1 || j > 2)
{
text.append("<td align = center>").append(ui->tableWidget->item(i, j)->text()).append("</td>");
}
Expand Down Expand Up @@ -1685,6 +1683,14 @@ void TMainWindow::ShowNewMData(bool fresh)
}
}

//---------------------------------------------------------------------------------------------------------------------
QString TMainWindow::getMeasurementNumber(const QString &name)
{
const VTranslateVars *trv = qApp->TrVars();
const QString numberStr = trv->MNumber(name);
return numberStr;
}

//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ShowMDiagram(const QString &name)
{
Expand Down Expand Up @@ -2273,6 +2279,7 @@ void TMainWindow::InitWindow()
{
ui->toolButtonFindPrevious->setEnabled(state);
});
connect(ui->clipboard_ToolButton, &QToolButton::clicked, this, &TMainWindow::copyToClipboard);
connect(search.data(), &VTableSearch::HasResult, this, [this] (bool state)
{
ui->toolButtonFindNext->setEnabled(state);
Expand Down Expand Up @@ -2569,7 +2576,9 @@ void TMainWindow::RefreshTable(bool freshCall)
}
else
{
AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter);

AddCell(getMeasurementNumber(meash->GetName()), currentRow, ColumnNumber, Qt::AlignVCenter);
AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter);
}

const qreal value = UnitConvertor(*meash->GetValue(), mUnit, pUnit);
Expand Down Expand Up @@ -2601,7 +2610,8 @@ void TMainWindow::RefreshTable(bool freshCall)
}
else
{
AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter);
AddCell(getMeasurementNumber(meash->GetName()), currentRow, ColumnNumber, Qt::AlignVCenter);
AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter);
}

const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit,
Expand Down Expand Up @@ -3293,3 +3303,42 @@ void TMainWindow::zoomToSelected()
{
// do nothing
}

//---------------------------------------------------------------------------------------------------------------------
/**
* @brief copyToClipboard copy dialog selection to clipboard as comma separated values.
*/
void TMainWindow::copyToClipboard()
{
QItemSelectionModel *model = ui->tableWidget->selectionModel();
QModelIndexList selectedIndexes = model->selectedIndexes();

QString clipboardString;

for (int i = 0; i < selectedIndexes.count(); ++i)
{
QModelIndex current = selectedIndexes[i];
QString displayText = current.data(Qt::DisplayRole).toString();

// Check if another column exists beyond this one.
if (i + 1 < selectedIndexes.count())
{
QModelIndex next = selectedIndexes[i+1];

// If the column is on different row, the clipboard should take note.
if (next.row() != current.row())
{
displayText.append("\n");
}
else
{
// Otherwise append a comma separator.
displayText.append(" , ");
}
}
clipboardString.append(displayText);
}

QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(clipboardString);
}
23 changes: 13 additions & 10 deletions src/app/seamlyme/tmainwindow.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/***************************************************************************
* *
* Copyright (C) 2017 Seamly, LLC *
* *
* https://github.com/fashionfreedom/seamly2d *
* *
***************************************************************************
** @file tmainwindow.h
** @author Douglas S Caskey
** @date Mar 25, 2023
**
** @copyright
** Copyright (C) 2015 - 2023 Seamly, LLC
** https://github.com/fashionfreedom/seamly2d
**
** @brief
** Seamly2D is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,11 +19,10 @@
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

************************************************************************
/************************************************************************
**
** @file tmainwindow.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
Expand Down Expand Up @@ -219,6 +220,7 @@ private slots:
QString ClearCustomName(const QString &name) const;

bool EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label);
QString getMeasurementNumber(const QString &name);
void ShowMDiagram(const QString &name);

void Open(const QString &pathTo, const QString &filter);
Expand All @@ -243,6 +245,7 @@ private slots:

template <class T>
void HackWidget(T **widget);
void copyToClipboard();
};

#endif // TMAINWINDOW_H
18 changes: 17 additions & 1 deletion src/app/seamlyme/tmainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<string/>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tabMeasurements">
<attribute name="icon">
Expand All @@ -60,6 +60,17 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QToolButton" name="clipboard_ToolButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/32x32/clipboard_icon.png</normaloff>:/icon/32x32/clipboard_icon.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelFind">
<property name="text">
Expand Down Expand Up @@ -144,6 +155,11 @@
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Number</string>
</property>
</column>
<column>
<property name="text">
<string>Full name</string>
Expand Down

0 comments on commit 9eb734f

Please sign in to comment.