57 #include "ui_tmainwindow.h"
64 #include "../vpatterndb/calculator.h"
65 #include "../vpatterndb/pmsystems.h"
66 #include "../ifc/ifcdef.h"
67 #include "../ifc/xml/vvitconverter.h"
68 #include "../ifc/xml/vvstconverter.h"
69 #include "../ifc/xml/vpatternconverter.h"
70 #include "../vmisc/vlockguard.h"
71 #include "../vmisc/vsysexits.h"
72 #include "../vmisc/qxtcsvmodel.h"
74 #include "../qmuparser/qmudef.h"
75 #include "../vtools/dialogs/support/edit_formula_dialog.h"
81 #include <QFileDialog>
84 #include <QMessageBox>
86 #include <QPrintPreviewDialog>
96 #define DIALOG_MAX_FORMULA_HEIGHT 64
99 QT_WARNING_DISABLE_CLANG(
"-Wmissing-prototypes")
100 QT_WARNING_DISABLE_INTEL(1418)
102 Q_LOGGING_CATEGORY(tMainWindow, "t.mainwindow")
113 individualMeasurements(nullptr),
121 gradationHeights(nullptr),
122 gradationSizes(nullptr),
123 comboBoxUnits(nullptr),
124 formulaBaseHeight(0),
127 labelGradationHeights(nullptr),
128 labelGradationSizes(nullptr),
129 labelPatternUnit(nullptr),
130 actionDockDiagram(nullptr),
131 dockDiagramVisible(true),
132 isInitialized(false),
135 separatorAct(nullptr),
140 qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
142 ui->lineEditFind->setClearButtonEnabled(
true);
143 ui->lineEditName->setClearButtonEnabled(
true);
144 ui->lineEditFullName->setClearButtonEnabled(
true);
145 ui->lineEditGivenName->setClearButtonEnabled(
true);
146 ui->lineEditFamilyName->setClearButtonEnabled(
true);
147 ui->lineEditEmail->setClearButtonEnabled(
true);
149 ui->lineEditFind->installEventFilter(
this);
150 ui->plainTextEditFormula->installEventFilter(
this);
153 ui->tabWidget->setVisible(
false);
155 ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
156 ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu);
168 #if defined(Q_OS_MAC)
170 ui->toolBarGradation->setIconSize(QSize(24, 24));
172 ui->pushButtonShowInExplorer->setText(tr(
"Show in Finder"));
175 QMenu *menu =
new QMenu(
this);
176 connect(menu, &QMenu::aboutToShow,
this, &TMainWindow::AboutToShowDockMenu);
177 AboutToShowDockMenu();
178 menu->setAsDockMenu();
201 const int row =
ui->tableWidget->currentRow();
203 ui->tableWidget->selectRow(row);
204 search->RefreshList(
ui->lineEditFind->text());
215 const int row =
ui->tableWidget->currentRow();
218 ui->tableWidget->selectRow(row);
230 const int row =
ui->tableWidget->currentRow();
233 ui->tableWidget->selectRow(row);
250 if (not QFileInfo(path).exists())
252 qCCritical(tMainWindow,
"%s", qUtf8Printable(tr(
"File '%1' doesn't exist!").arg(path)));
253 if (
qApp->IsTestMode())
262 for (
int i = 0; i < list.size(); ++i)
264 if (list.at(i)->CurrentFile() == path)
266 list.at(i)->activateWindow();
274 if (not
lock->IsLocked())
316 VException e(tr(
"File contains invalid known measurement(s)."));
326 ui->labelToolTip->setVisible(
false);
327 ui->tabWidget->setVisible(
true);
336 const bool freshCall =
true;
339 if (
ui->tableWidget->rowCount() > 0)
341 ui->tableWidget->selectRow(0);
348 qCCritical(tMainWindow,
"%s\n\n%s\n\n%s", qUtf8Printable(tr(
"File error.")),
350 ui->labelToolTip->setVisible(
true);
351 ui->tabWidget->setVisible(
false);
358 if (
qApp->IsTestMode())
367 qApp->NewMainWindow();
368 return qApp->MainWindow()->LoadFile(path);
393 if (measurements.exec() == QDialog::Rejected)
433 qApp->NewMainWindow();
434 qApp->MainWindow()->FileNew();
441 const QString filter = tr(
"Individual measurements") + QLatin1String(
" (*.vit);;") + tr(
"Multisize measurements") +
442 QLatin1String(
" (*.vst);;") + tr(
"All files") + QLatin1String(
" (*.*)");
444 const QString pathTo =
qApp->SeamlyMeSettings()->GetPathIndividualMeasurements();
446 bool usedNotExistedDir =
false;
447 QDir directory(pathTo);
448 if (not directory.exists())
450 usedNotExistedDir = directory.mkpath(
".");
453 Open(pathTo, filter);
455 if (usedNotExistedDir)
457 QDir directory(pathTo);
458 directory.rmpath(
".");
465 const QString filter = tr(
"Multisize measurements") + QLatin1String(
" (*.vst);;") + tr(
"Individual measurements") +
466 QLatin1String(
" (*.vit);;") + tr(
"All files") + QLatin1String(
" (*.*)");
468 QString pathTo =
qApp->SeamlyMeSettings()->GetPathMultisizeMeasurements();
471 Open(pathTo, filter);
477 const QString filter = tr(
"Measurements") + QLatin1String(
" (*.vst *.vit);;") + tr(
"All files") +
478 QLatin1String(
" (*.*)");
480 QString pathTo =
qApp->SeamlyMeSettings()->GetPathTemplate();
482 Open(pathTo, filter);
494 const QString filter = tr(
"Individual measurements") + QLatin1String(
" (*.vit)");
496 const QString pathTo =
qApp->SeamlyMeSettings()->GetPathIndividualMeasurements();
498 bool usedNotExistedDir =
false;
499 QDir directory(pathTo);
500 if (not directory.exists())
502 usedNotExistedDir = directory.mkpath(
".");
505 const QString mPath = QFileDialog::getOpenFileName(
this, tr(
"Select file"), pathTo, filter);
507 if (not mPath.isEmpty())
515 qApp->NewMainWindow()->CreateFromExisting();
519 if (usedNotExistedDir)
521 QDir directory(pathTo);
522 directory.rmpath(
".");
530 static QPointer<DialogSeamlyMePreferences> guard;
533 QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
536 QScopedPointer<DialogSeamlyMePreferences> dlg(preferences);
541 QGuiApplication::restoreOverrideCursor();
571 if (event->type() == QEvent::LanguageChange)
573 qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
576 ui->retranslateUi(
this);
580 ui->labelMType->setText(tr(
"Multisize measurements"));
591 ui->labelMType->setText(tr(
"Individual measurements"));
593 const qint32 index =
ui->comboBoxGender->currentIndex();
594 ui->comboBoxGender->blockSignals(
true);
595 ui->comboBoxGender->clear();
597 ui->comboBoxGender->setCurrentIndex(index);
598 ui->comboBoxGender->blockSignals(
false);
602 const qint32 index =
ui->comboBoxPMSystem->currentIndex();
603 ui->comboBoxPMSystem->blockSignals(
true);
604 ui->comboBoxPMSystem->clear();
606 ui->comboBoxPMSystem->setCurrentIndex(index);
607 ui->comboBoxPMSystem->blockSignals(
false);
626 QMainWindow::changeEvent(event);
632 QMainWindow::showEvent( event );
633 if ( event->spontaneous() )
645 ui->dockWidgetDiagram->setVisible(
false);
653 if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(
object))
655 if (event->type() == QEvent::KeyPress)
657 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
658 if ((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return))
663 else if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
665 if (
qApp->Settings()->GetOsSeparator())
667 plainTextEdit->insertPlainText(QLocale().decimalPoint());
671 plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
677 else if (QLineEdit *textEdit = qobject_cast<QLineEdit *>(
object))
679 if (event->type() == QEvent::KeyPress)
681 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
682 if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
684 if (
qApp->Settings()->GetOsSeparator())
686 textEdit->insert(QLocale().decimalPoint());
690 textEdit->insert(QLocale::c().decimalPoint());
699 return QMainWindow::eventFilter(
object, event);
711 columns =
ui->tableWidget->columnCount();
719 for (
int column = 0; column < columns; ++column)
721 if (not
ui->tableWidget->isColumnHidden(column))
731 for (
int column = 0; column < columns; ++column)
733 if (not
ui->tableWidget->isColumnHidden(column))
735 QTableWidgetItem *header =
ui->tableWidget->horizontalHeaderItem(colCount);
742 const int rows =
ui->tableWidget->rowCount();
743 for (
int row = 0; row < rows; ++row)
747 for (
int column = 0; column < columns; ++column)
749 if (not
ui->tableWidget->isColumnHidden(column))
751 QTableWidgetItem *item =
ui->tableWidget->item(row, column);
752 csv.
setText(row, colCount, item->text());
763 QString file = tr(
"untitled");
766 file = QFileInfo(
curFile).baseName();
779 columns =
ui->tableWidget->columnCount();
785 int rows =
ui->tableWidget->rowCount();
787 for(
int i = 0; i < columns; ++i ) {
788 width +=
ui->tableWidget->columnWidth(i);
791 for(
int i = 0; i < rows; ++i ) {
792 height +=
ui->tableWidget->rowHeight(i);
795 QPrintPreviewDialog *dialog =
new QPrintPreviewDialog(
this);
798 dialog->showMaximized();
799 dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
808 columns =
ui->tableWidget->columnCount();
818 text.append(
"<table>");
821 text.append(
"<tr><td align = left><b>Base Size:</b></td><td>" +
ui->labelBaseSizeValue->text() +
"</td></tr>");
822 text.append(
"<tr><td align = left><b>Base Height:</b></td><td>" +
ui->labelBaseHeightValue->text() +
"</td></tr>");
826 text.append(
"<tr><td align = left><b>Units:</b></td><td>" +
UnitsToStr(
mUnit) +
"</td></tr>");
827 text.append(
"<tr><td align = left><b>First Name:</b></td><td>" +
ui->lineEditGivenName->text() +
"</td></tr>");
828 text.append(
"<tr><td align = left><b>Last Name:</b></td><td>" +
ui->lineEditFamilyName->text() +
"</td></tr>");
829 text.append(
"<tr><td align = left><b>Gender:</b></td><td>" +
ui->comboBoxGender->currentText() +
"</td></tr>");
830 text.append(
"<tr><td align = left><b>Email:</b></td><td>" +
ui->lineEditEmail->text() +
"</td></tr>");
832 text.append(
"<tr><td align = left><b>Notes:</b></td><td>" +
ui->plainTextEditNotes->toPlainText() +
"</td></tr></table>");
835 text.append(
"<table><thead>");
837 for (
int i = 0; i < columns; i++)
839 text.append(
"<th>").append(
ui->tableWidget->horizontalHeaderItem(i)->data(Qt::DisplayRole).toString()).append(
"</th>");
841 text.append(
"</tr></thead>");
842 text.append(
"<tbody>");
843 for (
int i = 0; i <
ui->tableWidget->rowCount(); i++)
846 for (
int j = 0; j < columns; j++)
848 QTableWidgetItem *item =
ui->tableWidget->item(i, j);
849 if (!item || item->text().isEmpty())
854 ui->tableWidget->setItem(i, j,
new QTableWidgetItem(
"0"));
858 ui->tableWidget->setItem(i, j,
new QTableWidgetItem(
""));
863 text.append(
"<td align = center>").append(
ui->tableWidget->item(i, j)->text()).append(
"</td>");
867 text.append(
"<td align = left>").append(
ui->tableWidget->item(i, j)->text()).append(
"</td>");
870 text.append(
"</tr>");
872 text.append(
"</tbody></table>");
874 printer->setPageMargins(QMarginsF(10, 10, 10, 10), QPageLayout::Millimeter);
876 doc.setPageSize(printer->pageLayout().paintRectPixels(
static_cast<int>(
PrintDPI)).size());
903 qt_ntfs_permission_lookup++;
905 const bool isFileWritable = QFileInfo(
curFile).isWritable();
907 qt_ntfs_permission_lookup--;
910 if (not isFileWritable)
912 QMessageBox messageBox(
this);
913 messageBox.setIcon(QMessageBox::Question);
914 messageBox.setText(tr(
"The measurements document has no write permissions."));
915 messageBox.setInformativeText(
"Do you want to change the premissions?");
916 messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
917 messageBox.setDefaultButton(QMessageBox::Yes);
919 if (messageBox.exec() == QMessageBox::Yes)
922 qt_ntfs_permission_lookup++;
924 bool changed = QFile::setPermissions(
curFile,
925 QFileInfo(
curFile).permissions() | QFileDevice::WriteUser);
927 qt_ntfs_permission_lookup--;
932 QMessageBox messageBox(
this);
933 messageBox.setIcon(QMessageBox::Warning);
934 messageBox.setText(tr(
"Cannot set permissions for %1 to writable.").arg(
curFile));
935 messageBox.setInformativeText(tr(
"Could not save the file."));
936 messageBox.setDefaultButton(QMessageBox::Ok);
937 messageBox.setStandardButtons(QMessageBox::Ok);
951 QMessageBox messageBox;
952 messageBox.setIcon(QMessageBox::Warning);
953 messageBox.setText(tr(
"Could not save the file"));
954 messageBox.setDefaultButton(QMessageBox::Ok);
955 messageBox.setDetailedText(error);
956 messageBox.setStandardButtons(QMessageBox::Ok);
984 QString fileName = QLatin1String(
"measurements");
985 if (!filePath.isEmpty())
987 dir = QFileInfo(filePath).path();
988 fileName = QFileInfo(filePath).baseName();
991 filters = tr(
"Individual measurements") + QLatin1String(
" (*.vit)");
992 suffix = QLatin1String(
"vit");
996 filters = tr(
"Multisize measurements") + QLatin1String(
" (*.vst)");
997 suffix = QLatin1String(
"vst");
1004 dir =
qApp->SeamlyMeSettings()->GetDefPathIndividualMeasurements();
1005 filters = tr(
"Individual measurements") + QLatin1String(
" (*.vit)");
1006 suffix = QLatin1String(
"vit");
1010 dir =
qApp->SeamlyMeSettings()->GetDefPathMultisizeMeasurements();
1011 filters = tr(
"Multisize measurements") + QLatin1String(
" (*.vst)");
1012 suffix = QLatin1String(
"vst");
1018 filters = tr(
"Individual measurements") + QLatin1String(
" (*.vit)");
1019 suffix = QLatin1String(
"vit");
1023 filters = tr(
"Multisize measurements") + QLatin1String(
" (*.vst)");
1024 suffix = QLatin1String(
"vst");
1027 fileName += QLatin1String(
".") + suffix;
1033 dir =
qApp->SeamlyMeSettings()->GetPathIndividualMeasurements();
1037 dir =
qApp->SeamlyMeSettings()->GetPathMultisizeMeasurements();
1043 dir = QFileInfo(
curFile).absolutePath();
1046 bool usedNotExistedDir =
false;
1047 QDir directory(dir);
1048 if (not directory.exists())
1050 usedNotExistedDir = directory.mkpath(
".");
1053 fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as"), dir + QLatin1String(
"/") + fileName,
1054 filters,
nullptr, QFileDialog::DontUseNativeDialog);
1056 auto RemoveTempDir = [usedNotExistedDir, dir]()
1058 if (usedNotExistedDir)
1060 QDir directory(dir);
1061 directory.rmpath(
".");
1065 if (fileName.isEmpty())
1071 QFileInfo fileInfo(fileName);
1072 if (fileInfo.suffix().isEmpty() && fileInfo.suffix() != suffix)
1074 fileName += QLatin1String(
".") + suffix;
1077 if (fileInfo.exists() && fileName != filePath)
1083 qCWarning(tMainWindow,
"%s",
1084 qUtf8Printable(tr(
"Failed to lock. This file already opened in another window.")));
1098 if (result ==
false)
1100 QMessageBox messageBox;
1101 messageBox.setIcon(QMessageBox::Warning);
1102 messageBox.setInformativeText(tr(
"Could not save file"));
1103 messageBox.setDefaultButton(QMessageBox::Ok);
1104 messageBox.setDetailedText(error);
1105 messageBox.setStandardButtons(QMessageBox::Ok);
1118 if (fileName != filePath)
1121 if (!
lock->IsLocked())
1123 qCCritical(tMainWindow,
"%s", qUtf8Printable(tr(
"Failed to lock. This file already opened in another window. "
1124 "Expect collisions when running 2 copies of the program.")));
1137 ui->window_Menu->clear();
1144 if (QAction *action = qobject_cast<QAction*>(sender()))
1146 const QVariant v = action->data();
1147 if (v.canConvert<
int>())
1149 const int offset = qvariant_cast<int>(v);
1151 windows.at(offset)->raise();
1152 windows.at(offset)->activateWindow();
1158 #if defined(Q_OS_MAC)
1159 void TMainWindow::AboutToShowDockMenu()
1161 if (QMenu *menu = qobject_cast<QMenu *>(sender()))
1166 menu->addSeparator();
1168 menu->addAction(
ui->actionOpenIndividual);
1169 menu->addAction(
ui->actionOpenMultisize);
1170 menu->addAction(
ui->actionOpenTemplate);
1172 menu->addSeparator();
1174 QAction *actionPreferences = menu->addAction(tr(
"Preferences"));
1175 actionPreferences->setMenuRole(QAction::NoRole);
1181 void TMainWindow::OpenAt(QAction *where)
1183 const QString path =
curFile.left(
curFile.indexOf(where->text())) + where->text();
1189 process.start(QStringLiteral(
"/usr/bin/open"), QStringList() << path, QIODevice::ReadOnly);
1190 process.waitForFinished();
1258 QString system =
ui->comboBoxPMSystem->itemData(index).toString();
1259 system.remove(0, 1);
1271 const int row =
ui->tableWidget->currentRow();
1278 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(), 0);
1285 search->RefreshList(
ui->lineEditFind->text());
1287 if (
ui->tableWidget->rowCount() > 0)
1289 ui->tableWidget->selectRow(row);
1295 ui->actionExportToCSV->setEnabled(
false);
1297 ui->lineEditName->blockSignals(
true);
1298 ui->lineEditName->setText(
"");
1299 ui->lineEditName->blockSignals(
false);
1301 ui->plainTextEditDescription->blockSignals(
true);
1302 ui->plainTextEditDescription->setPlainText(
"");
1303 ui->plainTextEditDescription->blockSignals(
false);
1305 ui->lineEditFullName->blockSignals(
true);
1306 ui->lineEditFullName->setText(
"");
1307 ui->lineEditFullName->blockSignals(
false);
1311 ui->labelCalculatedValue->blockSignals(
true);
1312 ui->doubleSpinBoxBaseValue->blockSignals(
true);
1313 ui->doubleSpinBoxInSizes->blockSignals(
true);
1314 ui->doubleSpinBoxInHeights->blockSignals(
true);
1316 ui->labelCalculatedValue->setText(
"");
1317 ui->doubleSpinBoxBaseValue->setValue(0);
1318 ui->doubleSpinBoxInSizes->setValue(0);
1319 ui->doubleSpinBoxInHeights->setValue(0);
1321 ui->labelCalculatedValue->blockSignals(
false);
1322 ui->doubleSpinBoxBaseValue->blockSignals(
false);
1323 ui->doubleSpinBoxInSizes->blockSignals(
false);
1324 ui->doubleSpinBoxInHeights->blockSignals(
false);
1328 ui->labelCalculatedValue->blockSignals(
true);
1329 ui->labelCalculatedValue->setText(
"");
1330 ui->labelCalculatedValue->blockSignals(
false);
1332 ui->plainTextEditFormula->blockSignals(
true);
1333 ui->plainTextEditFormula->setPlainText(
"");
1334 ui->plainTextEditFormula->blockSignals(
false);
1342 const int row =
ui->tableWidget->currentRow();
1349 const QTableWidgetItem *nameField =
ui->tableWidget->item(row,
ColumnName);
1353 search->RefreshList(
ui->lineEditFind->text());
1354 ui->tableWidget->selectRow(0);
1360 const int row =
ui->tableWidget->currentRow();
1367 const QTableWidgetItem *nameField =
ui->tableWidget->item(row,
ColumnName);
1371 search->RefreshList(
ui->lineEditFind->text());
1372 ui->tableWidget->selectRow(row-1);
1378 const int row =
ui->tableWidget->currentRow();
1385 const QTableWidgetItem *nameField =
ui->tableWidget->item(row,
ColumnName);
1389 search->RefreshList(
ui->lineEditFind->text());
1390 ui->tableWidget->selectRow(row+1);
1396 const int row =
ui->tableWidget->currentRow();
1403 const QTableWidgetItem *nameField =
ui->tableWidget->item(row,
ColumnName);
1407 search->RefreshList(
ui->lineEditFind->text());
1408 ui->tableWidget->selectRow(
ui->tableWidget->rowCount()-1);
1414 const int row =
ui->tableWidget->currentRow();
1421 const QTableWidgetItem *nameField =
ui->tableWidget->item(row,
ColumnName);
1432 qCCritical(tMainWindow,
"%s\n\n%s\n\n%s",
1433 qUtf8Printable(tr(
"Can't find measurement '%1'.").arg(nameField->text())),
1439 dialog->setWindowTitle(tr(
"Edit measurement"));
1440 dialog->
SetFormula(
qApp->TrVars()->TryFormulaFromUser(
ui->plainTextEditFormula->toPlainText().replace(
"\n",
" "),
1445 if (dialog->exec() == QDialog::Accepted)
1448 const QTableWidgetItem *nameField =
ui->tableWidget->item(row,
ColumnName);
1455 search->RefreshList(
ui->lineEditFind->text());
1457 ui->tableWidget->selectRow(row);
1466 qint32 currentRow = -1;
1468 if (
ui->tableWidget->currentRow() == -1)
1470 currentRow =
ui->tableWidget->rowCount();
1475 currentRow =
ui->tableWidget->currentRow()+1;
1476 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
1480 search->AddRow(currentRow);
1482 search->RefreshList(
ui->lineEditFind->text());
1484 ui->tableWidget->selectRow(currentRow);
1486 ui->actionExportToCSV->setEnabled(
true);
1495 if (dialog->exec() == QDialog::Accepted)
1499 const QStringList list = dialog->getNewMeasurementNames();
1500 if (
ui->tableWidget->currentRow() == -1)
1502 currentRow =
ui->tableWidget->rowCount() + list.size() - 1;
1503 for (
int i = 0; i < list.size(); ++i)
1514 search->AddRow(currentRow);
1519 currentRow =
ui->tableWidget->currentRow() + list.size();
1520 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
1521 QString after = nameField->data(Qt::UserRole).toString();
1522 for (
int i = 0; i < list.size(); ++i)
1532 search->AddRow(currentRow);
1538 search->RefreshList(
ui->lineEditFind->text());
1540 ui->tableWidget->selectRow(currentRow);
1542 ui->actionExportToCSV->setEnabled(
true);
1556 const QString filter(tr(
"Pattern files (*.val)"));
1558 QString pathTo =
qApp->SeamlyMeSettings()->GetPathTemplate();
1561 const QString mPath = QFileDialog::getOpenFileName(
this, tr(
"Import from a pattern"), pathTo, filter);
1562 if (mPath.isEmpty())
1570 qCCritical(tMainWindow,
"%s", qUtf8Printable(tr(
"This file already opened in another window.")));
1574 QStringList measurements;
1579 doc->setXMLContent(converter.
Convert());
1580 measurements = doc->ListMeasurements();
1584 qCCritical(tMainWindow,
"%s\n\n%s\n\n%s", qUtf8Printable(tr(
"File error.")),
1593 if (
ui->tableWidget->currentRow() == -1)
1595 currentRow =
ui->tableWidget->rowCount() + measurements.size() - 1;
1596 for (
int i = 0; i < measurements.size(); ++i)
1603 currentRow =
ui->tableWidget->currentRow() + measurements.size();
1604 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
1605 QString after = nameField->data(Qt::UserRole).toString();
1606 for (
int i = 0; i < measurements.size(); ++i)
1609 after = measurements.at(i);
1615 search->RefreshList(
ui->lineEditFind->text());
1617 ui->tableWidget->selectRow(currentRow);
1625 const int row =
ui->tableWidget->currentRow();
1628 search->RefreshList(
ui->lineEditFind->text());
1629 ui->tableWidget->selectRow(row);
1635 const int row =
ui->tableWidget->currentRow();
1638 search->RefreshList(
ui->lineEditFind->text());
1639 ui->tableWidget->selectRow(row);
1651 if (
ui->tableWidget->rowCount() > 0)
1655 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
1674 ui->plainTextEditDescription->blockSignals(
true);
1675 if (meash->isCustom())
1677 ui->plainTextEditDescription->setPlainText(meash->GetDescription());
1678 ui->lineEditFullName->setText(meash->getGuiText());
1684 ui->plainTextEditDescription->setPlainText(
qApp->TrVars()->Description(meash->GetName()));
1685 ui->lineEditFullName->setText(
qApp->TrVars()->guiText(meash->GetName()));
1686 ui->lineEditName->setText(nameField->text());
1689 ui->plainTextEditDescription->blockSignals(
false);
1693 ui->labelCalculatedValue->blockSignals(
true);
1694 ui->doubleSpinBoxBaseValue->blockSignals(
true);
1695 ui->doubleSpinBoxInSizes->blockSignals(
true);
1696 ui->doubleSpinBoxInHeights->blockSignals(
true);
1701 ui->labelCalculatedValue->setText(
qApp->LocaleToString(value) +
" " +postfix);
1705 ui->doubleSpinBoxBaseValue->setValue(meash->GetBase());
1706 ui->doubleSpinBoxInSizes->setValue(meash->GetKsize());
1707 ui->doubleSpinBoxInHeights->setValue(meash->GetKheight());
1710 ui->labelCalculatedValue->blockSignals(
false);
1711 ui->doubleSpinBoxBaseValue->blockSignals(
false);
1712 ui->doubleSpinBoxInSizes->blockSignals(
false);
1713 ui->doubleSpinBoxInHeights->blockSignals(
false);
1717 EvalFormula(meash->GetFormula(),
false, meash->GetData(),
ui->labelCalculatedValue);
1719 ui->plainTextEditFormula->blockSignals(
true);
1724 formula =
qApp->TrVars()->FormulaToUser(meash->GetFormula(),
qApp->Settings()->GetOsSeparator());
1729 formula = meash->GetFormula();
1732 ui->plainTextEditFormula->setPlainText(formula);
1733 ui->plainTextEditFormula->blockSignals(
false);
1747 return qApp->TrVars()->MNumber(name);
1754 const QString number = trv->
MNumber(name);
1756 if (number.isEmpty())
1758 ui->labelDiagram->setText(tr(
"<html><head/><body><p><span style=\" font-size:340pt;\">?</span></p>"
1759 "<p align=\"center\">Unknown measurement</p></body></html>"));
1763 ui->labelDiagram->setText(QString(
"<html><head/><body><p align=\"center\">%1</p>"
1764 "<p align=\"center\"><b>%2</b>. <i>%3</i></p></body></html>")
1768 ui->labelDiagram->adjustSize();
1771 ui->dockWidgetDiagram->setMaximumWidth(
ui->labelDiagram->width()+50);
1777 SCASSERT(
ui->plainTextEditFormula !=
nullptr)
1780 const QTextCursor cursor =
ui->plainTextEditFormula->textCursor();
1786 ui->pushButtonGrow->setIcon(QIcon::fromTheme(
"go-next",
1787 QIcon(
":/icons/win.icon.theme/16x16/actions/go-next.png")));
1793 ui->pushButtonGrow->setIcon(QIcon::fromTheme(
"go-down",
1794 QIcon(
":/icons/win.icon.theme/16x16/actions/go-down.png")));
1799 setUpdatesEnabled(
false);
1801 setUpdatesEnabled(
true);
1803 ui->plainTextEditFormula->setFocus();
1804 ui->plainTextEditFormula->setTextCursor(cursor);
1810 const int row =
ui->tableWidget->currentRow();
1817 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
1828 qCWarning(tMainWindow,
"%s\n\n%s\n\n%s",
1829 qUtf8Printable(tr(
"Can't find measurement '%1'.").arg(nameField->text())),
1834 QString newName = text;
1836 if (meash->isCustom())
1843 QString name = newName;
1846 name = name + QLatin1String(
"_") + QString().number(num);
1855 search->RefreshList(
ui->lineEditFind->text());
1857 ui->tableWidget->blockSignals(
true);
1858 ui->tableWidget->selectRow(row);
1859 ui->tableWidget->blockSignals(
false);
1863 qCWarning(tMainWindow,
"%s", qUtf8Printable(tr(
"The name of known measurement forbidden to change.")));
1870 const int row =
ui->tableWidget->currentRow();
1877 const QTableWidgetItem *nameField =
ui->tableWidget->item(row,
ColumnName);
1880 QString text =
ui->plainTextEditFormula->toPlainText();
1881 text.replace(
"\n",
" ");
1883 QTableWidgetItem *formulaField =
ui->tableWidget->item(row,
ColumnFormula);
1884 if (formulaField->text() == text)
1888 ui->labelCalculatedValue->setText(result->text() +
" " +postfix);
1895 ui->labelCalculatedValue->setText(tr(
"Error") +
" (" + postfix +
"). " + tr(
"Empty field."));
1907 qCWarning(tMainWindow,
"%s\n\n%s\n\n%s",
1908 qUtf8Printable(tr(
"Can't find measurement '%1'.").arg(nameField->text())),
1913 if (not
EvalFormula(text,
true, meash->GetData(),
ui->labelCalculatedValue))
1920 const QString formula =
qApp->TrVars()->FormulaFromUser(text,
qApp->Settings()->GetOsSeparator());
1931 const QTextCursor cursor =
ui->plainTextEditFormula->textCursor();
1934 search->RefreshList(
ui->lineEditFind->text());
1936 ui->tableWidget->blockSignals(
true);
1937 ui->tableWidget->selectRow(row);
1938 ui->tableWidget->blockSignals(
false);
1940 ui->plainTextEditFormula->setTextCursor(cursor);
1946 const int row =
ui->tableWidget->currentRow();
1953 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
1959 search->RefreshList(
ui->lineEditFind->text());
1961 ui->tableWidget->blockSignals(
true);
1962 ui->tableWidget->selectRow(row);
1963 ui->tableWidget->blockSignals(
false);
1971 const int row =
ui->tableWidget->currentRow();
1978 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
1984 search->RefreshList(
ui->lineEditFind->text());
1986 ui->tableWidget->blockSignals(
true);
1987 ui->tableWidget->selectRow(row);
1988 ui->tableWidget->blockSignals(
false);
1996 const int row =
ui->tableWidget->currentRow();
2003 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
2009 search->RefreshList(
ui->lineEditFind->text());
2011 ui->tableWidget->blockSignals(
true);
2012 ui->tableWidget->selectRow(row);
2013 ui->tableWidget->blockSignals(
false);
2021 const int row =
ui->tableWidget->currentRow();
2028 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
2033 const QTextCursor cursor =
ui->plainTextEditDescription->textCursor();
2037 ui->tableWidget->blockSignals(
true);
2038 ui->tableWidget->selectRow(row);
2039 ui->tableWidget->blockSignals(
false);
2041 ui->plainTextEditDescription->setTextCursor(cursor);
2048 const int row =
ui->tableWidget->currentRow();
2055 const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName);
2066 qCWarning(tMainWindow,
"%s\n\n%s\n\n%s",
2067 qUtf8Printable(tr(
"Can't find measurement '%1'.").arg(nameField->text())),
2072 if (meash->isCustom())
2080 ui->tableWidget->blockSignals(
true);
2081 ui->tableWidget->selectRow(row);
2082 ui->tableWidget->blockSignals(
false);
2086 qCWarning(tMainWindow,
"%s", qUtf8Printable(tr(
"The full name of known measurement forbidden to change.")));
2111 connect(
ui->actionReadOnly, &QAction::triggered,
this, [
this](
bool ro)
2113 if (not mIsReadOnly)
2115 individualMeasurements->SetReadOnly(ro);
2116 MeasurementsWasSaved(false);
2118 UpdateWindowTitle();
2122 if (QAction *action = qobject_cast< QAction * >(this->sender()))
2124 action->setChecked(true);
2130 for (
int i = 0; i < MaxRecentFiles; ++i)
2132 QAction *action =
new QAction(
this);
2133 recentFileActs[i] = action;
2134 connect(action, &QAction::triggered,
this, [
this]()
2136 QAction *action = qobject_cast<QAction *>(sender());
2139 const QString filePath = action->data().toString();
2140 if (not filePath.isEmpty())
2146 ui->menuFile->insertAction(ui->actionPreferences, recentFileActs[i]);
2147 recentFileActs[i]->setVisible(
false);
2150 separatorAct =
new QAction(
this);
2151 separatorAct->setSeparator(
true);
2152 separatorAct->setVisible(
false);
2153 ui->menuFile->insertAction(ui->actionPreferences, separatorAct );
2156 connect(ui->actionQuit, &QAction::triggered,
this, &TMainWindow::close);
2163 actionDockDiagram = ui->dockWidgetDiagram->toggleViewAction();
2164 actionDockDiagram->setMenuRole(QAction::NoRole);
2165 ui->measurements_Menu->addAction(actionDockDiagram);
2166 ui->mainToolBar->addAction(actionDockDiagram);
2167 actionDockDiagram->setEnabled(
false);
2168 actionDockDiagram->setIcon(QIcon(
"://seamlymeicon/24x24/mannequin.png"));
2172 AboutToShowWindowMenu();
2175 connect(ui->shortcuts_Action, &QAction::triggered,
this, [
this]()
2177 MeShortcutsDialog *shortcutsDialog = new MeShortcutsDialog(this);
2178 shortcutsDialog->setAttribute(Qt::WA_DeleteOnClose, true);
2179 shortcutsDialog->show();
2181 connect(ui->actionAboutQt, &QAction::triggered,
this, [
this]()
2183 QMessageBox::aboutQt(this, tr(
"About Qt"));
2185 connect(ui->actionAboutSeamlyMe, &QAction::triggered,
this, [
this]()
2187 DialogAboutSeamlyMe *aboutDialog = new DialogAboutSeamlyMe(this);
2188 aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true);
2189 aboutDialog->show();
2193 UpdateRecentFileActions();
2201 ui->labelToolTip->setVisible(
false);
2202 ui->tabWidget->setVisible(
true);
2205 ui->tabWidget->setCurrentIndex(0);
2207 ui->plainTextEditNotes->setEnabled(
true);
2208 ui->toolBarGradation->setVisible(
true);
2212 ui->labelMType->setText(tr(
"Multisize measurements"));
2245 connect(
gradationHeights,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
2251 connect(
gradationSizes,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
2254 connect(
ui->doubleSpinBoxBaseValue,
2255 static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
2257 connect(
ui->doubleSpinBoxInSizes,
2258 static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
2260 connect(
ui->doubleSpinBoxInHeights,
2261 static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
2268 ui->labelMType->setText(tr(
"Individual measurements"));
2270 ui->lineEditGivenName->setEnabled(
true);
2271 ui->lineEditFamilyName->setEnabled(
true);
2272 ui->dateEditBirthDate->setEnabled(
true);
2273 ui->comboBoxGender->setEnabled(
true);
2274 ui->lineEditEmail->setEnabled(
true);
2293 ui->comboBoxGender->clear();
2296 ui->comboBoxGender->setCurrentIndex(index);
2299 const QLocale dateLocale = QLocale(
qApp->Settings()->GetLocale());
2300 ui->dateEditBirthDate->setLocale(dateLocale);
2301 ui->dateEditBirthDate->setDisplayFormat(dateLocale.dateFormat());
2310 connect(
ui->comboBoxGender,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
this,
2317 Qt::UniqueConnection);
2322 ui->comboBoxPMSystem->setEnabled(
true);
2323 ui->comboBoxPMSystem->clear();
2326 ui->comboBoxPMSystem->setCurrentIndex(index);
2327 connect(
ui->comboBoxPMSystem,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
this,
2330 connect(
ui->lineEditFind, &QLineEdit::textChanged, [
this] (
const QString &term){search->Find(term);});
2331 connect(
ui->toolButtonFindPrevious, &QToolButton::clicked, [
this] (){search->FindPrevious();});
2332 connect(
ui->toolButtonFindNext, &QToolButton::clicked, [
this] (){search->FindNext();});
2336 ui->toolButtonFindPrevious->setEnabled(state);
2341 ui->toolButtonFindNext->setEnabled(state);
2347 ui->actionAddCustom->setEnabled(
true);
2348 ui->actionAddKnown->setEnabled(
true);
2349 ui->actionImportFromPattern->setEnabled(
true);
2350 ui->actionSaveAs->setEnabled(
true);
2352 ui->lineEditName->setValidator(
new QRegularExpressionValidator(QRegularExpression(
2366 connect(
ui->pushButtonShowInExplorer, &QPushButton::clicked,
this, [
this]()
2368 ShowInGraphicalShell(curFile);
2394 ui->tableWidget->resizeColumnsToContents();
2395 ui->tableWidget->resizeRowsToContents();
2396 ui->tableWidget->horizontalHeader()->setStretchLastSection(
true);
2416 QString header = table->horizontalHeaderItem(column)->text();
2417 const int index = header.indexOf(QLatin1String(
"("));
2420 header.remove(index-1, 100);
2422 const QString unitHeader = QString(
"%1 (%2)").arg(header, unit);
2423 table->horizontalHeaderItem(column)->setText(unitHeader);
2429 setWindowModified(!saved);
2430 not
mIsReadOnly ?
ui->actionSave->setEnabled(!saved):
ui->actionSave->setEnabled(
false);
2439 ui->lineEditPathToFile->setText(QLatin1String(
"<") + tr(
"Empty") + QLatin1String(
">"));
2440 ui->lineEditPathToFile->setToolTip(tr(
"File was not saved yet."));
2441 ui->lineEditPathToFile->setCursorPosition(0);
2442 ui->pushButtonShowInExplorer->setEnabled(
false);
2446 ui->lineEditPathToFile->setText(QDir::toNativeSeparators(
curFile));
2447 ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(
curFile));
2448 ui->lineEditPathToFile->setCursorPosition(0);
2449 ui->pushButtonShowInExplorer->setEnabled(
true);
2450 auto settings =
qApp->SeamlyMeSettings();
2451 QStringList files = settings->GetRecentFileList();
2452 files.removeAll(fileName);
2453 files.prepend(fileName);
2458 settings->SetRecentFileList(files);
2480 if (this->isWindowModified())
2482 if (
curFile.isEmpty() &&
ui->tableWidget->rowCount() == 0)
2487 QScopedPointer<QMessageBox> messageBox(
new QMessageBox(tr(
"Unsaved changes"),
2488 tr(
"Measurements have been modified.\n"
2489 "Do you want to save your changes?"),
2490 QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No,
2491 QMessageBox::Cancel,
this, Qt::Sheet));
2493 messageBox->setDefaultButton(QMessageBox::Yes);
2494 messageBox->setEscapeButton(QMessageBox::Cancel);
2496 messageBox->setButtonText(QMessageBox::Yes,
curFile.isEmpty() ||
mIsReadOnly ? tr(
"Save...") : tr(
"Save"));
2497 messageBox->setButtonText(QMessageBox::No, tr(
"Don't Save"));
2499 messageBox->setWindowModality(Qt::ApplicationModal);
2500 const QMessageBox::StandardButton ret =
static_cast<QMessageBox::StandardButton
>(messageBox->exec());
2504 case QMessageBox::Yes:
2513 case QMessageBox::No:
2515 case QMessageBox::Cancel:
2527 QTableWidgetItem *item =
new QTableWidgetItem(text);
2528 item->setTextAlignment(aligment);
2529 item->setToolTip(text);
2532 Qt::ItemFlags flags = item->flags();
2533 flags &= ~(Qt::ItemIsEditable);
2534 item->setFlags(flags);
2538 QBrush brush = item->foreground();
2539 brush.setColor(Qt::red);
2540 item->setForeground(brush);
2543 ui->tableWidget->setItem(row, column, item);
2551 ui->toolBarGradation->addWidget(label);
2553 QComboBox *comboBox =
new QComboBox;
2554 comboBox->addItems(list);
2555 ui->toolBarGradation->addWidget(comboBox);
2577 const qint32 index =
gradationSizes->findText(QString(
"%1").arg(value));
2601 ui->tableWidget->blockSignals(
true);
2602 ui->tableWidget->clearContents();
2609 for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap)
2612 orderedTable.insert(meash->Index(), meash);
2615 qint32 currentRow = -1;
2617 ui->tableWidget->setRowCount ( orderedTable.size() );
2618 for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap)
2627 item->setData(Qt::UserRole, meash->GetName());
2629 if (meash->isCustom())
2643 meash->IsFormulaOk());
2648 formula =
qApp->TrVars()->FormulaToUser(meash->GetFormula(),
qApp->Settings()->GetOsSeparator());
2653 formula = meash->GetFormula();
2660 QTableWidgetItem *item =
AddCell(
qApp->TrVars()->MToUser(meash->GetName()), currentRow, 0,
2662 item->setData(Qt::UserRole, meash->GetName());
2664 if (meash->isCustom())
2678 Qt::AlignHCenter | Qt::AlignVCenter, meash->IsFormulaOk());
2681 Qt::AlignHCenter | Qt::AlignVCenter);
2684 Qt::AlignHCenter | Qt::AlignVCenter);
2687 Qt::AlignHCenter | Qt::AlignVCenter);
2693 ui->tableWidget->resizeColumnsToContents();
2694 ui->tableWidget->resizeRowsToContents();
2696 ui->tableWidget->horizontalHeader()->setStretchLastSection(
true);
2697 ui->tableWidget->blockSignals(
false);
2699 if (
ui->tableWidget->rowCount() > 0)
2701 ui->actionExportToCSV->setEnabled(
true);
2722 if (
ui->tableWidget->rowCount() > 0)
2724 ui->toolButtonRemove->setEnabled(
true);
2728 ui->toolButtonRemove->setEnabled(
false);
2731 if (
ui->tableWidget->rowCount() >= 2)
2733 if (
ui->tableWidget->currentRow() == 0)
2735 ui->toolButtonTop->setEnabled(
false);
2736 ui->toolButtonUp->setEnabled(
false);
2737 ui->toolButtonDown->setEnabled(
true);
2738 ui->toolButtonBottom->setEnabled(
true);
2740 else if (
ui->tableWidget->currentRow() ==
ui->tableWidget->rowCount()-1)
2742 ui->toolButtonTop->setEnabled(
true);
2743 ui->toolButtonUp->setEnabled(
true);
2744 ui->toolButtonDown->setEnabled(
false);
2745 ui->toolButtonBottom->setEnabled(
false);
2749 ui->toolButtonTop->setEnabled(
true);
2750 ui->toolButtonUp->setEnabled(
true);
2751 ui->toolButtonDown->setEnabled(
true);
2752 ui->toolButtonBottom->setEnabled(
true);
2757 ui->toolButtonTop->setEnabled(
false);
2758 ui->toolButtonUp->setEnabled(
false);
2759 ui->toolButtonDown->setEnabled(
false);
2760 ui->toolButtonBottom->setEnabled(
false);
2767 ui->lineEditName->setEnabled(enabled);
2768 ui->plainTextEditDescription->setEnabled(enabled);
2769 ui->lineEditFullName->setEnabled(enabled);
2773 ui->doubleSpinBoxBaseValue->setEnabled(enabled);
2774 ui->doubleSpinBoxInSizes->setEnabled(enabled);
2775 ui->doubleSpinBoxInHeights->setEnabled(enabled);
2779 ui->plainTextEditFormula->setEnabled(enabled);
2780 ui->pushButtonGrow->setEnabled(enabled);
2781 ui->toolButtonExpr->setEnabled(enabled);
2784 ui->lineEditFind->setEnabled(enabled);
2785 if (enabled && not
ui->lineEditFind->text().isEmpty())
2787 ui->toolButtonFindPrevious->setEnabled(enabled);
2788 ui->toolButtonFindNext->setEnabled(enabled);
2792 ui->toolButtonFindPrevious->setEnabled(
false);
2793 ui->toolButtonFindNext->setEnabled(
false);
2801 bool isFileWritable =
true;
2805 qt_ntfs_permission_lookup++;
2807 isFileWritable = QFileInfo(
curFile).isWritable();
2809 qt_ntfs_permission_lookup--;
2815 fileName = tr(
"untitled %1").arg(
qApp->MainWindows().size() + 1);
2819 fileName += QLatin1String(
"[*]");
2823 fileName += QLatin1String(
" (") + tr(
"read only") + QLatin1String(
")");
2829 #if defined(Q_OS_MAC)
2830 static QIcon fileIcon = QIcon(QCoreApplication::applicationDirPath() +
2831 QLatin1String(
"/../Resources/measurements.icns"));
2835 if (not isWindowModified())
2841 static QIcon darkIcon;
2843 if (darkIcon.isNull())
2845 darkIcon = QIcon(
darkenPixmap(fileIcon.pixmap(16, 16)));
2850 setWindowIcon(icon);
2857 QString clear = name;
2870 if (formula.isEmpty())
2872 label->setText(tr(
"Error") +
" (" + postfix +
"). " + tr(
"Empty field."));
2873 label->setToolTip(tr(
"Empty field"));
2884 f =
qApp->TrVars()->FormulaFromUser(formula,
qApp->Settings()->GetOsSeparator());
2890 f.replace(
"\n",
" ");
2891 QScopedPointer<Calculator> cal(
new Calculator());
2894 if (qIsInf(result) || qIsNaN(result))
2896 label->setText(tr(
"Error") +
" (" + postfix +
").");
2897 label->setToolTip(tr(
"Invalid result. Value is infinite or NaN. Please, check your calculations."));
2903 label->setText(
qApp->LocaleToString(result) +
" " +postfix);
2904 label->setToolTip(tr(
"Value"));
2909 label->setText(tr(
"Error") +
" (" + postfix +
"). " + tr(
"Parser error: %1").arg(e.
GetMsg()));
2910 label->setToolTip(tr(
"Parser error: %1").arg(e.
GetMsg()));
2919 const QString mPath = QFileDialog::getOpenFileName(
this, tr(
"Open file"), pathTo, filter);
2921 if (not mPath.isEmpty())
2929 qApp->NewMainWindow()->LoadFile(mPath);
2937 ui->actionReadOnly->setChecked(ro);
2940 ui->actionReadOnly->setIcon(QIcon(
"://seamlymeicon/24x24/padlock_locked.png"));
2944 ui->actionReadOnly->setIcon(QIcon(
"://seamlymeicon/24x24/padlock_opened.png"));
2953 if (
const QTableWidgetItem *nameField =
ui->tableWidget->item(
ui->tableWidget->currentRow(),
ColumnName))
2955 const bool isCustom = not (nameField->text().indexOf(
CustomMSign) == 0);
2956 ui->lineEditName->setReadOnly(isCustom);
2957 ui->plainTextEditDescription->setReadOnly(isCustom);
2958 ui->lineEditFullName->setReadOnly(isCustom);
2962 ui->lineEditName->blockSignals(isCustom);
2963 ui->lineEditFullName->blockSignals(isCustom);
2996 return convertToList(convertToSet<QString>(mNew).subtract(convertToSet<QString>(mFilter)));
3002 const int row =
ui->tableWidget->currentRow();
3011 search->RefreshList(
ui->lineEditFind->text());
3013 ui->tableWidget->selectRow(row);
3021 if (not QFileInfo(path).exists())
3023 qCCritical(tMainWindow,
"%s", qUtf8Printable(tr(
"File '%1' doesn't exist!").arg(path)));
3024 if (
qApp->IsTestMode())
3033 for (
int i = 0; i < list.size(); ++i)
3035 if (list.at(i)->CurrentFile() == path)
3037 list.at(i)->activateWindow();
3045 if (not
lock->IsLocked())
3066 VException e(tr(
"File has unknown format."));
3072 VException e(tr(
"Export from multisize measurements is not supported."));
3085 VException e(tr(
"File contains invalid known measurement(s)."));
3095 ui->labelToolTip->setVisible(
false);
3096 ui->tabWidget->setVisible(
true);
3101 const bool freshCall =
true;
3104 if (
ui->tableWidget->rowCount() > 0)
3106 ui->tableWidget->selectRow(0);
3117 qCCritical(tMainWindow,
"%s\n\n%s\n\n%s", qUtf8Printable(tr(
"File error.")),
3119 ui->labelToolTip->setVisible(
true);
3120 ui->tabWidget->setVisible(
false);
3127 if (
qApp->IsTestMode())
3136 qApp->NewMainWindow();
3137 return qApp->MainWindow()->LoadFile(path);
3145 qCDebug(tMainWindow,
"Updating recent file actions.");
3146 const QStringList files =
qApp->SeamlyMeSettings()->GetRecentFileList();
3147 const int numRecentFiles = qMin(files.size(),
static_cast<int>(
MaxRecentFiles));
3148 qCDebug(tMainWindow,
"Updating recent file actions = %i ",numRecentFiles);
3150 for (
int i = 0; i < numRecentFiles; ++i)
3152 const QString text = QString(
"&%1. %2").arg(i + 1).arg(
strippedName(files.at(i)));
3153 qCDebug(tMainWindow,
"file %i = %s", numRecentFiles, qUtf8Printable(text));
3172 QAction *action = menu->addAction(tr(
"&New Window"));
3173 connect(action, &QAction::triggered,
this, []()
3175 qApp->NewMainWindow();
3176 qApp->MainWindow()->activateWindow();
3178 action->setMenuRole(QAction::NoRole);
3179 menu->addSeparator();
3182 for (
int i = 0; i < windows.count(); ++i)
3186 QString title = QString(
"%1. %2").arg(i+1).arg(window->windowTitle());
3187 const int index = title.lastIndexOf(
"[*]");
3190 window->isWindowModified() ? title.replace(index, 3,
"*") : title.replace(index, 3,
"");
3193 QAction *action = menu->addAction(title,
this, SLOT(
ShowWindow()));
3195 action->setCheckable(
true);
3196 action->setMenuRole(QAction::NoRole);
3197 if (window->isActiveWindow())
3199 action->setChecked(
true);
3207 QMessageBox::StandardButton answer = QMessageBox::Abort;
3208 if (not
qApp->IsTestMode())
3212 case QLockFile::LockFailedError:
3213 answer = QMessageBox::warning(
this, tr(
"Locking file"),
3214 tr(
"This file already opened in another window. Ignore if you want "
3215 "to continue (not recommended, can cause a data corruption)."),
3216 QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort);
3218 case QLockFile::PermissionError:
3219 answer = QMessageBox::question(
this, tr(
"Locking file"),
3220 tr(
"The lock file could not be created, for lack of permissions. "
3221 "Ignore if you want to continue (not recommended, can cause "
3222 "a data corruption)."),
3223 QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort);
3225 case QLockFile::UnknownError:
3226 answer = QMessageBox::question(
this, tr(
"Locking file"),
3227 tr(
"Unknown error happened, for instance a full partition "
3228 "prevented writing out the lock file. Ignore if you want to "
3229 "continue (not recommended, can cause a data corruption)."),
3230 QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort);
3233 answer = QMessageBox::Abort;
3238 if (answer == QMessageBox::Abort)
3240 qCDebug(tMainWindow,
"Failed to lock %s", qUtf8Printable(path));
3241 qCDebug(tMainWindow,
"Error type: %d", error);
3242 if (
qApp->IsTestMode())
3246 case QLockFile::LockFailedError:
3247 qCCritical(tMainWindow,
"%s",
3248 qUtf8Printable(tr(
"This file already opened in another window.")));
3250 case QLockFile::PermissionError:
3251 qCCritical(tMainWindow,
"%s",
3252 qUtf8Printable(tr(
"The lock file could not be created, for lack of permissions.")));
3254 case QLockFile::UnknownError:
3255 qCCritical(tMainWindow,
"%s",
3256 qUtf8Printable(tr(
"Unknown error happened, for instance a full partition "
3257 "prevented writing out the lock file.")));
3276 ui->doubleSpinBoxBaseValue->setDecimals(2);
3277 ui->doubleSpinBoxBaseValue->setSingleStep(0.01);
3279 ui->doubleSpinBoxInSizes->setDecimals(2);
3280 ui->doubleSpinBoxInSizes->setSingleStep(0.01);
3282 ui->doubleSpinBoxInHeights->setDecimals(2);
3283 ui->doubleSpinBoxInHeights->setSingleStep(0.01);
3286 ui->doubleSpinBoxBaseValue->setDecimals(1);
3287 ui->doubleSpinBoxBaseValue->setSingleStep(0.1);
3289 ui->doubleSpinBoxInSizes->setDecimals(1);
3290 ui->doubleSpinBoxInSizes->setSingleStep(0.1);
3292 ui->doubleSpinBoxInHeights->setDecimals(1);
3293 ui->doubleSpinBoxInHeights->setSingleStep(0.1);
3296 ui->doubleSpinBoxBaseValue->setDecimals(5);
3297 ui->doubleSpinBoxBaseValue->setSingleStep(0.00001);
3299 ui->doubleSpinBoxInSizes->setDecimals(5);
3300 ui->doubleSpinBoxInSizes->setSingleStep(0.00001);
3302 ui->doubleSpinBoxInHeights->setDecimals(5);
3303 ui->doubleSpinBoxInHeights->setSingleStep(0.00001);
3321 if (indexUnit != -1)
3326 connect(
comboBoxUnits,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
this,
3345 gender->addItem(tr(
"unknown",
"gender"), QVariant(
static_cast<int>(
GenderType::Unknown)));
3346 gender->addItem(tr(
"male",
"gender"), QVariant(
static_cast<int>(
GenderType::Male)));
3347 gender->addItem(tr(
"female",
"gender"), QVariant(
static_cast<int>(
GenderType::Female)));
3371 QItemSelectionModel *model =
ui->tableWidget->selectionModel();
3372 QModelIndexList selectedIndexes = model->selectedIndexes();
3374 QString clipboardString;
3376 for (
int i = 0; i < selectedIndexes.count(); ++i)
3378 QModelIndex current = selectedIndexes[i];
3379 QString displayText = current.data(Qt::DisplayRole).toString();
3382 if (i + 1 < selectedIndexes.count())
3384 QModelIndex next = selectedIndexes[i+1];
3387 if (next.row() != current.row())
3389 displayText.append(
"\n");
3394 displayText.append(
" , ");
3397 clipboardString.append(displayText);
3400 QClipboard *clipboard = QApplication::clipboard();
3401 clipboard->setText(clipboardString);
The Calculator class for calculation formula.
MeasurementsType Type() const
static QString imageUrl(const QString &number)
The QxtCsvModel class provides a QAbstractTableModel for CSV Files.
void setText(int row, int column, const QString &value)
Sets the content of the cell at row row and column column to value.
bool insertColumn(int col, const QModelIndex &parent=QModelIndex())
\reimp
void setHeaderText(int column, const QString &value)
Sets the content of the header for column column to value.
bool insertRow(int row, const QModelIndex &parent=QModelIndex())
\reimp
void toCSV(QIODevice *file, bool withHeader=false, QChar separator=',', QTextCodec *codec=nullptr) const
Outputs the content of the model as a CSV file to the device dest using codec.
void SetBaseMSize(int size)
QString GetCustomName() const
bool EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label)
QString ClearCustomName(const QString &name) const
void SetDefaultHeight(int value)
void CreateWindowMenu(QMenu *menu)
QLabel * labelGradationSizes
QString CurrentFile() const
QAction * actionDockDiagram
virtual void exportToCSVData(const QString &fileName, const DialogExportToCSV &dialog) Q_DECL_FINAL
QComboBox * gradationSizes
void UpdateRecentFileActions()
void SaveBirthDate(const QDate &date)
QStringList FilterMeasurements(const QStringList &mNew, const QStringList &mFilter)
void printPages(QPrinter *printer)
void ShowNewMData(bool fresh)
QVector< QObject * > hackedWidgets
virtual void zoomToSelected() Q_DECL_OVERRIDE
void PatternUnitChanged(int index)
void RefreshTable(bool freshCall=false)
QAction * recentFileActs[MaxRecentFiles]
void SavePMSystem(int index)
void ShowHeaderUnits(QTableWidget *table, int column, const QString &unit)
void SetDefaultSize(int value)
void InitGender(QComboBox *gender)
VMeasurements * individualMeasurements
bool LoadFile(const QString &path)
void SaveMName(const QString &text)
void MFields(bool enabled)
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
virtual void changeEvent(QEvent *event) Q_DECL_OVERRIDE
void HackWidget(T **widget)
virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE
QTableWidgetItem * AddCell(const QString &text, int row, int column, int aligment, bool ok=true)
QComboBox * gradationHeights
void MeasurementsWasSaved(bool saved)
void SetBaseMHeight(int height)
bool LoadFromExistingFile(const QString &path)
void SetCurrentFile(const QString &fileName)
void RefreshData(bool freshCall=false)
void SaveMBaseValue(double value)
QComboBox * comboBoxUnits
TMainWindow(QWidget *parent=nullptr)
Q_REQUIRED_RESULT QComboBox * SetGradationList(QLabel *label, const QStringList &list)
void SaveMSizeIncrease(double value)
void ChangedHeight(int index)
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
void ShowMDiagram(const QString &name)
virtual ~TMainWindow() Q_DECL_OVERRIDE
void copyToClipboard()
copyToClipboard copy dialog selection to clipboard as comma separated values.
void SaveGender(int index)
bool SaveMeasurements(const QString &fileName, QString &error)
void CreateFromExisting()
void AboutToShowWindowMenu()
virtual void updateGroups() Q_DECL_OVERRIDE
void UpdatePadlock(bool ro)
QString getMeasurementNumber(const QString &name)
QLabel * labelPatternUnit
std::shared_ptr< VLockGuard< char > > lock
void SaveMHeightIncrease(double value)
QLabel * labelGradationHeights
virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE
void ChangedSize(int index)
QSharedPointer< VTableSearch > search
bool IgnoreLocking(int error, const QString &path)
void Open(const QString &pathTo, const QString &filter)
int GetCurrentFormatVarsion() const
QString GetVersionStr() const
int m_curFileFormatVersion
QString m_curFileFormatVersionStr
void exportToCSV(QString &file)
void ToolBarStyle(QToolBar *bar)
bool ContinueFormatRewrite(const QString ¤tFormatVersion, const QString &maxFormatVersion)
static QString PrepareStandardTemplates(const QString ¤tPath)
static QString PrepareMultisizeTables(const QString ¤tPath)
QByteArray GetGeometry() const
void SetToolbarsState(const QByteArray &value)
QByteArray GetToolbarsState() const
void SetWindowState(const QByteArray &value)
QByteArray GetWindowState() const
void SetGeometry(const QByteArray &value)
The VContainer class container of all variables.
static qreal height()
height return height
static void ClearUniqueNames()
static bool IsUnique(const QString &name)
void ClearVariables(const VarType &type=VarType::Unknown)
const QHash< QString, QSharedPointer< VInternalVariable > > * DataVariables() const
static qreal size()
size return size
QSharedPointer< T > GetVariable(QString name) const
GetVariable return varible by name.
const QMap< QString, QSharedPointer< VMeasurement > > DataMeasurements() const
The VExceptionBadId class for exception bad id.
virtual QString ErrorMessage() const Q_DECL_OVERRIDE
ErrorMessage return main error message.
The VException class parent for all exception. Could be use for abstract exception.
virtual QString ErrorMessage() const
ErrorMessage return main error message.
virtual QString DetailedInformation() const
DetailedInformation return detailed information about error.
The VMeasurement class keep data row of multisize table.
static QStringList WholeListSizes(Unit patternUnit)
static QStringList WholeListHeights(Unit patternUnit)
void MoveUp(const QString &name)
void MoveTop(const QString &name)
void SetMDescription(const QString &name, const QString &text)
void MoveDown(const QString &name)
void addEmpty(const QString &name, const QString &formula=QString())
void SetGender(const GenderType &gender)
void SetNotes(const QString &text)
void SetMBaseValue(const QString &name, double value)
void SetEmail(const QString &text)
QStringList ListAll() const
QStringList listKnown() const
void SetFamilyName(const QString &text)
void ReadMeasurements() const
void SetSize(qreal *size)
void SetPMSystem(const QString &system)
void Remove(const QString &name)
void SetReadOnly(bool ro)
void SetMFullName(const QString &name, const QString &text)
void SetHeight(qreal *height)
void SetMValue(const QString &name, const QString &text)
MeasurementsType Type() const
void SetMSizeIncrease(const QString &name, double value)
void MoveBottom(const QString &name)
void AddEmptyAfter(const QString &after, const QString &name, const QString &formula=QString())
void SetGivenName(const QString &text)
void SetMHeightIncrease(const QString &name, double value)
QString FamilyName() const
virtual void setXMLContent(const QString &fileName) Q_DECL_OVERRIDE
GenderType Gender() const
virtual bool SaveDocument(const QString &fileName, QString &error) Q_DECL_OVERRIDE
QString GivenName() const
bool IsDefinedKnownNamesValid() const
void SetMName(const QString &name, const QString &text)
void SetBirthDate(const QDate &date)
void HasResult(bool state)
QString guiText(const QString &measurement) const
QString MNumber(const QString &measurement) const
static const QString MeasurementMaxVerStr
static Q_DECL_CONSTEXPR const int MeasurementMaxVer
static const QString MeasurementMaxVerStr
static Q_DECL_CONSTEXPR const int MeasurementMaxVer
Error class of the parser.
const QString & GetMsg() const
Returns the message string for this error.
QPixmap darkenPixmap(const QPixmap &pixmap)
QString strippedName(const QString &fullFileName)
strippedName the function call around curFile to exclude the path to the file.
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
QList< T > convertToList(const C< T > &set)
const QString CustomMSign
const QString measurement_
void InitPMSystems(QComboBox *systemCombo)
#define VER_INTERNALNAME_ME_STR
#define DIALOG_MAX_FORMULA_HEIGHT
QT_WARNING_PUSH void VlpCreateLock(std::shared_ptr< VLockGuard< Guarded >> &r, const QString &lockName, int stale=0, int timeout=0)
static const auto V_EX_NOINPUT