57 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
61 #ifdef ENGAUGE_JPEG2000
63 #endif // ENGAUGE_JPEG2000
80 #include <QApplication>
82 #include <QCloseEvent>
85 #include <QDesktopServices>
86 #include <QDockWidget>
87 #include <QDomDocument>
88 #include <QFileDialog>
90 #include <QImageReader>
92 #include <QKeySequence>
94 #include <QMessageBox>
95 #include <QMouseEvent>
96 #include <QPrintDialog>
99 #include <QPushButton>
101 #include <QSignalMapper>
102 #include <QTextStream>
103 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
108 #include <QToolButton>
110 #include <QVBoxLayout>
111 #include <QWhatsThis>
112 #include <QXmlStreamReader>
113 #include <QXmlStreamWriter>
127 static const char *ENGAUGE_FILENAME_DESCRIPTION =
"Engauge Document";
133 const QString &fileCmdScriptFile,
134 bool isDropRegression,
135 bool isRegressionTest,
139 bool isExtractImageOnly,
140 const QString &extractImageOnlyExtension,
141 const QStringList &loadStartupFiles,
142 const QStringList &commandLineWithoutLoadStartupFiles,
145 m_originalFileWasImported (false),
146 m_isDocumentExported (false),
152 m_loadImageFromUrl (nullptr),
153 m_cmdMediator (nullptr),
154 m_digitizeStateContext (nullptr),
155 m_transformationStateContext (nullptr),
156 m_backgroundStateContext (nullptr),
157 m_networkClient (nullptr),
158 m_isGnuplot (isGnuplot),
159 m_commandLineWithoutLoadStartupFiles (commandLineWithoutLoadStartupFiles),
161 m_timerRegressionErrorReport(nullptr),
162 m_fileCmdScript (nullptr),
163 m_isErrorReportRegressionTest (isRegressionTest),
164 m_timerRegressionFileCmdScript(nullptr),
165 m_fittingCurve (nullptr),
166 m_isExportOnly (isExportOnly),
167 m_isExtractImageOnly (isExtractImageOnly),
168 m_extractImageOnlyExtension (extractImageOnlyExtension)
171 <<
" curDir=" << QDir::currentPath().toLatin1().data();
173 #if defined(OSX_DEBUG) || defined(OSX_RELEASE)
174 qApp->setApplicationName (
"Engauge Digitizer");
175 qApp->setOrganizationDomain (
"Mark Mitchell");
180 m_startupDirectory = QDir::currentPath();
185 createFacade.
create (*
this);
189 settingsRead (isReset);
191 setUnifiedTitleAndToolBarOnMac(
true);
193 installEventFilter(
this);
197 QString originalPath = QDir::currentPath();
198 QDir::setCurrent (m_startupDirectory);
200 m_loadStartupFiles = loadStartupFiles;
201 m_regressionFile = exportRegressionFilenameFromInputFilename (loadStartupFiles.first ());
202 slotLoadStartupFiles ();
205 }
else if (isExtractImageOnly) {
206 m_loadStartupFiles = loadStartupFiles;
207 m_regressionFile = exportRegressionFilenameFromInputFilename (loadStartupFiles.first ());
208 slotLoadStartupFiles ();
209 handlerFileExtractImage ();
211 }
else if (!errorReportFile.isEmpty()) {
212 loadErrorReportFile(errorReportFile);
213 if (m_isErrorReportRegressionTest) {
214 startRegressionTestErrorReport(errorReportFile);
216 }
else if (!fileCmdScriptFile.isEmpty()) {
218 startRegressionTestFileCmdScript();
219 }
else if (isDropRegression) {
221 startRegressionDropTest (loadStartupFiles);
226 m_loadStartupFiles = loadStartupFiles;
228 QDir::setCurrent (originalPath);
233 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
236 delete m_tutorialDlg;
237 delete m_cmdMediator;
238 delete m_cmdStackShadow;
239 delete m_digitizeStateContext;
240 delete m_transformationStateContext;
241 delete m_backgroundStateContext;
242 delete m_dlgSettingsAxesChecker;
243 delete m_dlgSettingsColorFilter;
244 delete m_dlgSettingsCoords;
245 delete m_dlgSettingsCurveList;
246 delete m_dlgSettingsCurveProperties;
247 delete m_dlgSettingsDigitizeCurve;
248 delete m_dlgSettingsExportFormat;
249 delete m_dlgSettingsGeneral;
250 delete m_dlgSettingsGridDisplay;
251 delete m_dlgSettingsGridRemoval;
252 delete m_dlgSettingsMainWindow;
253 delete m_dlgSettingsPointMatch;
254 delete m_dlgSettingsSegments;
255 delete m_fileCmdScript;
256 m_gridLines.
clear ();
259 void MainWindow::addDockWindow (QDockWidget *dockWidget,
261 const QString &settingsTokenArea,
262 const QString &settingsTokenGeometry,
263 Qt::DockWidgetArea dockWidgetArea)
268 const bool DOCKED_EQUALS_NOT_FLOATING =
false;
269 Qt::DockWidgetArea area = static_cast<Qt::DockWidgetArea> (settings.value (settingsTokenArea,
270 Qt::NoDockWidgetArea).toInt());
272 if (area == Qt::NoDockWidgetArea) {
274 addDockWidget (dockWidgetArea,
276 dockWidget->setFloating(DOCKED_EQUALS_NOT_FLOATING);
277 if (settings.contains (settingsTokenGeometry)) {
278 dockWidget->restoreGeometry (settings.value (settingsTokenGeometry).toByteArray());
289 void MainWindow::applyZoomFactorAfterLoad()
294 if (m_zoomMapFromInitial.contains (zoomFactorInitial)) {
295 zoomFactor = m_zoomMapFromInitial [zoomFactorInitial];
297 zoomFactor = currentZoomFactor ();
300 zoomFactor = currentZoomFactor();
303 slotViewZoom (zoomFactor);
306 void MainWindow::closeEvent(QCloseEvent *event)
320 setWindowModified (
false);
337 m_regressionFile = exportRegressionFilenameFromInputFilename (fileName);
338 fileImport (fileName,
346 m_regressionFile = exportRegressionFilenameFromInputFilename (fileName);
347 loadDocumentFile(fileName);
353 return m_cmdMediator;
356 ZoomFactor MainWindow::currentZoomFactor ()
const
360 ZoomFactor zoomFactor = static_cast<ZoomFactor> (z);
361 if (m_zoomMapToAction [zoomFactor]->isChecked ()) {
373 if (event->type () == QEvent::KeyPress) {
375 QKeyEvent *eventKeyPress = static_cast<QKeyEvent *> (event);
378 if ((eventKeyPress->key() == Qt::Key_E) &&
379 ((eventKeyPress->modifiers() & Qt::ShiftModifier) != 0) &&
380 ((eventKeyPress->modifiers() & Qt::ControlModifier) != 0)) {
390 return QObject::eventFilter (target, event);
393 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
394 void MainWindow::exportAllCoordinateSystemsAfterRegressionTests()
396 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::exportAllCoordinateSystemsAfterRegressionTests curDir=" << QDir::currentPath().toLatin1().data();
403 QString regressionFile = QString (
"%1_%2")
404 .arg (m_regressionFile)
418 fileExport (regressionFile,
425 QString MainWindow::exportRegressionFilenameFromInputFilename (
const QString &fileName)
const
430 befores <<
".dig" <<
".gif" <<
".html" <<
".htm" <<
".jp2" <<
".jpg" <<
".pbm"
431 <<
".pdf" <<
".pgm" <<
".png" <<
".ppm" <<
".xbm" <<
".xpm" <<
".xml";
433 QString outFileName = fileName;
435 QStringList::iterator itr;
436 for (itr = befores.begin(); itr != befores.end(); itr++) {
437 QString suffix = *itr;
439 outFileName = outFileName.replace (suffix,
".csv_actual", Qt::CaseInsensitive);
445 void MainWindow::fileExport(
const QString &fileName,
449 <<
" curDir=" << QDir::currentPath().toLatin1().data()
450 <<
" fileName=" << fileName.toLatin1().data();
452 QFile file (fileName);
453 if (file.open(QIODevice::WriteOnly)) {
455 QTextStream str (&file);
466 m_isDocumentExported =
true;
468 updateChecklistGuide ();
474 <<
" file=" << fileName.toLatin1().data()
475 <<
" curDir=" << QDir::currentPath().toLatin1().data();
476 QMessageBox::critical (
nullptr,
478 tr (
"Unable to export to file") +
" " + fileName);
482 void MainWindow::fileExtractImage (
const QString &fileName)
485 <<
" curDir=" << QDir::currentPath().toLatin1().data()
486 <<
" fileName=" << fileName.toLatin1().data();
488 QFile file (fileName);
489 if (file.open(QIODevice::WriteOnly)) {
491 QPixmap pixmap = m_cmdMediator->
pixmap();
495 if (m_isErrorReportRegressionTest) {
496 QString csvFile = QString (
"%1_1")
497 .arg (exportRegressionFilenameFromInputFilename (m_regressionFile));
501 process.start (
"bash -c \"cksum " + fileName +
" | awk '{print $1}' > " + csvFile +
"\"");
502 process.waitForFinished (-1);
508 <<
" file=" << fileName.toLatin1().data()
509 <<
" curDir=" << QDir::currentPath().toLatin1().data();
510 QMessageBox::critical (
nullptr,
512 tr (
"Unable to extract image to file") +
" " + fileName);
516 void MainWindow::fileImport (
const QString &fileName,
517 ImportType importType)
520 <<
" fileName=" << fileName.toLatin1 ().data ()
521 <<
" curDir=" << QDir::currentPath().toLatin1().data()
522 <<
" importType=" << importType;
524 QString originalFileOld = m_originalFile;
525 bool originalFileWasImported = m_originalFileWasImported;
527 m_originalFile = fileName;
528 m_originalFileWasImported =
true;
530 if (importType == IMPORT_TYPE_ADVANCED) {
543 #ifdef ENGAUGE_JPEG2000
545 loaded = jpeg2000.
load (fileName,
547 #endif // ENGAUGE_JPEG2000
557 m_isErrorReportRegressionTest);
567 #endif // ENGAUGE_PDF
574 m_isErrorReportRegressionTest);
586 QString msg = QString(
"%1 %2 %3 %4.")
587 .arg (tr (
"Cannot read file"))
589 .arg (tr (
"from directory"))
590 .arg (QDir::currentPath());
592 if (fileName.contains (
"???")) {
597 msg += QObject::tr (
"The file appears to have characters from multiple language "
598 "alphabets, which does not work in the Windows command line");
601 QMessageBox::warning (
this,
606 m_originalFile = originalFileOld;
607 m_originalFileWasImported = originalFileWasImported;
611 loaded = loadImage (fileName,
619 ! m_actionViewCoordSystem->isChecked ()) {
622 m_actionViewCoordSystem->trigger ();
628 if (importType == IMPORT_TYPE_ADVANCED) {
638 m_originalFile = originalFileOld;
639 m_originalFileWasImported = originalFileWasImported;
645 void MainWindow::fileImportWithPrompts (ImportType importType)
648 <<
" importType=" << importType;
652 bool okToContinue =
true;
653 if (importType != IMPORT_TYPE_IMAGE_REPLACE) {
654 okToContinue = maybeSave ();
660 QTextStream str (&filter);
665 str <<
"Image Files (" << supportedImageFormatStrings.join (
" ") <<
")";
669 str <<
";; All Files (*.*)";
672 QString fileName = QFileDialog::getOpenFileName (
this,
676 if (!fileName.isEmpty ()) {
681 fileImport (fileName,
687 QString MainWindow::fileNameForExportOnly ()
const
692 if (m_isErrorReportRegressionTest) {
695 fileName = QString (
"%1_1")
696 .arg (exportRegressionFilenameFromInputFilename (m_regressionFile));
701 QString dir = QFileInfo (m_currentFileWithPathAndFileExtension).absolutePath();
702 fileName = QString (
"%1/%2.%3")
711 QString MainWindow::fileNameForExtractImageOnly ()
const
714 QString dir = QFileInfo (m_currentFileWithPathAndFileExtension).absolutePath();
715 QString fileName = QString (
"%1/%2.%3")
718 .arg (m_extractImageOnlyExtension);
723 void MainWindow::filePaste (ImportType importType)
726 <<
" importType=" << importType;
728 QString originalFileOld = m_originalFile;
729 bool originalFileWasImported = m_originalFileWasImported;
731 QString fileName (
"clipboard");
732 m_originalFile = fileName;
733 m_originalFileWasImported =
true;
735 if (importType == IMPORT_TYPE_ADVANCED) {
746 QImage image = QApplication::clipboard()->image();
750 loaded = !image.isNull();
754 QMessageBox::warning (
this,
756 QString(
"%1 %2 %3 %4.")
757 .arg (tr (
"Cannot read file"))
759 .arg (tr (
"from directory"))
760 .arg (QDir::currentPath ()));
763 m_originalFile = originalFileOld;
764 m_originalFileWasImported = originalFileWasImported;
768 loaded = loadImage (fileName,
775 if (importType == IMPORT_TYPE_ADVANCED) {
785 m_originalFile = originalFileOld;
786 m_originalFileWasImported = originalFileWasImported;
792 void MainWindow::ghostsCreate ()
818 void MainWindow::ghostsDestroy ()
830 void MainWindow::handlerFileExtractImage ()
834 if (m_isExtractImageOnly) {
835 QString fileName = fileNameForExtractImageOnly ();
840 fileExtractImage(fileName);
854 void MainWindow::loadCoordSystemListFromCmdMediator ()
858 m_cmbCoordSystem->clear();
862 for (
unsigned int i = 0; i < numberCoordSystem; i++) {
863 int index1Based = signed (i + 1);
864 m_cmbCoordSystem->addItem (QString::number (index1Based),
869 m_cmbCoordSystem->setCurrentIndex (0);
872 bool enable = (m_cmbCoordSystem->count() > 1);
873 m_cmbCoordSystem->setEnabled (enable);
874 m_btnShowAll->setEnabled (enable);
875 m_btnPrintAll->setEnabled (enable);
878 void MainWindow::loadCurveListFromCmdMediator ()
882 m_cmbCurve->clear ();
884 QStringList::iterator itr;
885 for (itr = curvesGraphsNames.begin (); itr != curvesGraphsNames.end (); itr++) {
887 QString curvesGraphName = *itr;
888 m_cmbCurve->addItem (curvesGraphName);
895 void MainWindow::loadDocumentFile (
const QString &fileName)
897 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::loadDocumentFile fileName=" << fileName.toLatin1 ().data ();
899 QApplication::setOverrideCursor(Qt::WaitCursor);
905 setCurrentPathFromFile (fileName);
906 rebuildRecentFileListForCurrentFile(fileName);
907 m_currentFile = fileName;
909 delete m_cmdMediator;
912 setupAfterLoadNewDocument (fileName,
917 m_actionDigitizeSelect->setChecked (
true);
918 slotDigitizeSelect();
920 m_engaugeFile = fileName;
921 m_originalFile = fileName;
922 m_originalFileWasImported =
false;
927 QApplication::restoreOverrideCursor();
931 QApplication::restoreOverrideCursor();
933 QMessageBox::warning (
this,
935 QString(
"%1 %2 %3 %4:\n%5.")
936 .arg (tr (
"Cannot read file"))
938 .arg (tr (
"from directory"))
939 .arg (QDir::currentPath ())
946 void MainWindow::loadErrorReportFile(
const QString &errorReportFile)
949 <<
" file=" << errorReportFile.toLatin1().data();
951 QFile file (errorReportFile);
952 if (!file.exists()) {
954 QFileInfo fileInfo (errorReportFile);
956 QMessageBox::critical (
this,
958 tr (
"File not found") +
": " + fileInfo.absoluteFilePath());
963 QXmlStreamReader reader (&file);
964 file.open(QIODevice::ReadOnly | QIODevice::Text);
974 setupAfterLoadNewDocument (errorReportFile,
975 tr (
"Error report opened"),
979 m_actionDigitizeSelect->setChecked (
true);
980 slotDigitizeSelect();
985 bool MainWindow::loadImage (
const QString &fileName,
987 ImportType importType)
990 <<
" fileName=" << fileName.toLatin1 ().data ()
991 <<
" importType=" << importType;
994 if (importType == IMPORT_TYPE_IMAGE_REPLACE) {
995 success = loadImageReplacingImage (fileName,
999 success = loadImageNewDocument (fileName,
1007 bool MainWindow::loadImageNewDocument (
const QString &fileName,
1008 const QImage &image,
1009 ImportType importType)
1012 <<
" fileName=" << fileName.toLatin1 ().data ()
1013 <<
" importType=" << importType;
1017 QApplication::setOverrideCursor(Qt::WaitCursor);
1020 QApplication::restoreOverrideCursor();
1022 setCurrentPathFromFile (fileName);
1026 delete m_cmdMediator;
1029 bool accepted = setupAfterLoadNewDocument (fileName,
1030 tr (
"File imported"),
1036 if (m_actionHelpChecklistGuideWizard->isChecked () &&
1037 (m_fileCmdScript ==
nullptr)) {
1042 if (wizard->exec() == QDialog::Accepted) {
1058 m_actionViewChecklistGuide->setChecked (
true);
1061 loadCurveListFromCmdMediator();
1064 loadCoordSystemListFromCmdMediator();
1070 m_actionDigitizeAxis->setChecked (
true);
1074 slotDigitizeScale ();
1075 }
else if (modeGraph ()) {
1076 slotDigitizeAxis ();
1085 bool MainWindow::loadImageReplacingImage (
const QString &fileName,
1086 const QImage &image,
1087 ImportType importType)
1090 <<
" fileName=" << fileName.toLatin1 ().data ()
1091 <<
" importType=" << importType;
1095 setCurrentPathFromFile (fileName);
1103 bool accepted = setupAfterLoadReplacingImage (fileName,
1104 tr (
"File imported"),
1112 void MainWindow::loadInputFileForErrorReport(QDomDocument &domInputFile)
const
1114 QFile file (m_originalFile);
1118 if (!file.open (QIODevice::ReadOnly)) {
1122 domInputFile.setContent (&file);
1126 void MainWindow::loadToolTips()
1128 if (m_actionViewToolTips->isChecked ()) {
1131 m_actionDigitizeSelect->setToolTip (m_actionDigitizeSelect->text());
1132 m_actionDigitizeAxis->setToolTip (m_actionDigitizeAxis->text());
1133 m_actionDigitizeScale->setToolTip (m_actionDigitizeScale->text());
1134 m_actionDigitizeCurve->setToolTip (m_actionDigitizeCurve->text());
1135 m_actionDigitizePointMatch->setToolTip (m_actionDigitizePointMatch->text());
1136 m_actionDigitizeColorPicker->setToolTip (m_actionDigitizeColorPicker->text());
1137 m_actionDigitizeSegment->setToolTip (m_actionDigitizeSegment->text());
1138 m_cmbBackground->setToolTip (tr (
"Background image."));
1139 m_cmbCurve->setToolTip (tr (
"Currently selected curve."));
1140 m_viewPointStyle->setToolTip (tr (
"Point style for currently selected curve."));
1141 m_viewSegmentFilter->setToolTip (tr (
"Segment Fill filter for currently selected curve."));
1146 m_actionDigitizeSelect->setToolTip (
"");
1147 m_actionDigitizeAxis->setToolTip (
"");
1148 m_actionDigitizeScale->setToolTip (
"");
1149 m_actionDigitizeCurve->setToolTip (
"");
1150 m_actionDigitizePointMatch->setToolTip (
"");
1151 m_actionDigitizeColorPicker->setToolTip (
"");
1152 m_actionDigitizeSegment->setToolTip (
"");
1153 m_cmbBackground->setToolTip (
"");
1154 m_cmbCurve->setToolTip (
"");
1155 m_viewPointStyle->setToolTip (
"");
1156 m_viewSegmentFilter->setToolTip (
"");
1161 bool MainWindow::modeGraph ()
const
1163 bool success =
false;
1165 if (m_cmdMediator !=
nullptr) {
1174 bool success =
false;
1176 if (m_cmdMediator !=
nullptr) {
1183 bool MainWindow::maybeSave()
1185 if (m_cmdMediator !=
nullptr) {
1187 QMessageBox::StandardButton ret = QMessageBox::warning (
this,
1189 tr(
"The document has been modified.\n"
1190 "Do you want to save your changes?"),
1191 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
1192 if (ret == QMessageBox::Save) {
1193 return slotFileSave();
1194 }
else if (ret == QMessageBox::Cancel) {
1205 const QString &fileName)
const
1213 QString csvExtension = QString (
".%1")
1215 QString tsvExtension = QString (
".%1")
1217 QString fileExtensionVersusCsv = fileName.right (csvExtension.size());
1218 QString fileExtensionVersusTsv = fileName.right (tsvExtension.size());
1222 if (csvExtension.compare (fileExtensionVersusCsv, Qt::CaseInsensitive) == 0) {
1224 }
else if (tsvExtension.compare (fileExtensionVersusTsv, Qt::CaseInsensitive) == 0) {
1229 return modelExportFormatAfter;
1234 return m_modelMainWindow;
1237 void MainWindow::rebuildRecentFileListForCurrentFile(
const QString &filePath)
1241 setWindowFilePath (filePath);
1245 recentFilePaths.removeAll (filePath);
1246 recentFilePaths.prepend (filePath);
1248 recentFilePaths.removeLast ();
1252 updateRecentFileList();
1259 if (m_actionZoomFill->isChecked ()) {
1263 QMainWindow::resizeEvent(event);
1266 bool MainWindow::saveDocumentFile (
const QString &fileName)
1268 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::saveDocumentFile fileName=" << fileName.toLatin1 ().data ();
1270 QFile file(fileName);
1271 if (!file.open(QFile::WriteOnly)) {
1272 QMessageBox::warning (
this,
1274 QString (
"%1 %2: \n%3.")
1275 .arg(tr (
"Cannot write file"))
1277 .arg(file.errorString()));
1281 rebuildRecentFileListForCurrentFile (fileName);
1283 QApplication::setOverrideCursor (Qt::WaitCursor);
1284 QXmlStreamWriter writer(&file);
1285 writer.setAutoFormatting(
true);
1286 writer.writeStartDocument();
1287 writer.writeDTD(
"<!DOCTYPE engauge>");
1289 writer.writeEndDocument();
1290 QApplication::restoreOverrideCursor ();
1294 m_cmdMediator->setClean ();
1296 setCurrentFile(fileName);
1297 m_engaugeFile = fileName;
1307 const char *comment)
1311 if ((m_cmdMediator !=
nullptr) && !m_isErrorReportRegressionTest) {
1313 QString report = saveErrorReportFileAndExitXml (context,
1319 if (dlg.exec() == QDialog::Accepted) {
1322 QString fileName = dlg.getSaveFileName (
this,
1324 "error_report.xml");
1325 if (!fileName.isEmpty ()) {
1327 QFile fileError (fileName);
1328 QTextStream str (&fileError);
1329 fileError.open (QIODevice::WriteOnly | QIODevice::Text);
1339 QString MainWindow::saveErrorReportFileAndExitXml (
const char *context,
1342 const char *comment)
const
1344 const bool DEEP_COPY =
true;
1346 QString xmlErrorReport;
1347 QXmlStreamWriter writer (&xmlErrorReport);
1348 writer.setAutoFormatting(
true);
1356 writer.writeEndElement();
1360 QXmlStreamReader reader (m_startingDocumentSnapshot);
1361 while (!reader.atEnd ()) {
1363 if (reader.tokenType() != QXmlStreamReader::StartDocument &&
1364 reader.tokenType() != QXmlStreamReader::EndDocument &&
1365 reader.tokenType() != QXmlStreamReader::Invalid) {
1366 writer.writeCurrentToken (reader);
1374 writer.writeEndElement();
1380 writer.writeEndElement();
1383 m_cmdMediator->
saveXml(writer);
1391 writer.writeEndElement();
1393 writer.writeEndElement();
1396 QDomDocument domErrorReport (
"ErrorReport");
1397 domErrorReport.setContent (xmlErrorReport);
1400 if (!m_originalFileWasImported) {
1404 QDomDocument domInputFile;
1405 loadInputFileForErrorReport (domInputFile);
1406 QDomDocumentFragment fragmentFileFrom = domErrorReport.createDocumentFragment();
1407 if (!domInputFile.isNull()) {
1408 fragmentFileFrom.appendChild (domErrorReport.importNode (domInputFile.documentElement(), DEEP_COPY));
1411 if (nodesFileTo.count () > 0) {
1412 QDomNode nodeFileTo = nodesFileTo.at (0);
1413 nodeFileTo.appendChild (fragmentFileFrom);
1421 for (
int i = 0 ; i < nodesDocument.count(); i++) {
1422 QDomNode nodeDocument = nodesDocument.at (i);
1424 if (!elemImage.isNull()) {
1433 QDomNode nodeReplacement;
1434 QDomElement elemReplacement = nodeReplacement.toElement();
1439 nodeDocument.insertBefore (nodeReplacement,
1441 nodeDocument.removeChild(elemImage);
1447 return domErrorReport.toString();
1450 void MainWindow::saveStartingDocumentSnapshot()
1454 QXmlStreamWriter writer (&m_startingDocumentSnapshot);
1455 writer.setAutoFormatting (
true);
1469 BackgroundImage previousBackground = static_cast<BackgroundImage> (m_cmbBackground->currentData().toInt());
1471 int index = m_cmbBackground->findData (backgroundImage);
1474 m_cmbBackground->setCurrentIndex(index);
1476 return previousBackground;
1481 return m_cmbCurve->currentText ();
1484 void MainWindow::setCurrentFile (
const QString &fileName)
1488 QString fileNameStripped;
1489 if (!fileName.isEmpty()) {
1493 QFileInfo fileInfo (fileName);
1494 fileNameStripped = fileInfo.completeBaseName();
1497 m_currentFile = fileNameStripped;
1498 m_currentFileWithPathAndFileExtension = fileName;
1500 updateWindowTitle ();
1503 void MainWindow::setCurrentPathFromFile (
const QString &fileName)
1505 QDir dir = QFileInfo (fileName).absoluteDir();
1507 if (dir.exists ()) {
1509 bool success = QDir::setCurrent (dir.absolutePath ());
1518 void MainWindow::setNonFillZoomFactor (
ZoomFactor newZoomFactor)
1523 m_zoomMapToAction [newZoomFactor]->setChecked (
true);
1524 slotViewZoomFactor (newZoomFactor);
1527 void MainWindow::setPixmap (
const QString &curveSelected,
1528 const QPixmap &pixmap)
1537 m_backgroundStateContext->
setPixmap (m_isGnuplot,
1545 void MainWindow::settingsRead (
bool isReset)
1554 settingsReadEnvironment (settings);
1555 settingsReadMainWindow (settings);
1558 void MainWindow::settingsReadEnvironment (QSettings &settings)
1562 QDir::currentPath ()).toString ());
1563 settings.endGroup ();
1566 void MainWindow::settingsReadMainWindow (QSettings &settings)
1572 QSize (600, 600)).toSize ());
1574 QPoint (200, 200)).toPoint ());
1577 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
1579 QSize (900, 600)).toSize();
1580 m_helpWindow->resize (helpSize);
1583 m_helpWindow->move (helpPos);
1594 m_actionViewBackground->setChecked (viewBackgroundToolBar);
1595 m_toolBackground->setVisible (viewBackgroundToolBar);
1598 int indexBackground = m_cmbBackground->findData (QVariant (backgroundImage));
1599 m_cmbBackground->setCurrentIndex (indexBackground);
1604 m_actionViewDigitize->setChecked (viewDigitizeToolBar);
1605 m_toolDigitize->setVisible (viewDigitizeToolBar);
1610 m_actionViewSettingsViews->setChecked (viewSettingsViewsToolBar);
1611 m_toolSettingsViews->setVisible (viewSettingsViewsToolBar);
1616 m_actionViewCoordSystem->setChecked (viewCoordSystemToolbar);
1617 m_toolCoordSystem->setVisible (viewCoordSystemToolbar);
1622 m_actionViewToolTips->setChecked (viewToolTips);
1633 addDockWindow (m_dockChecklistGuide,
1637 Qt::RightDockWidgetArea);
1638 addDockWindow (m_dockFittingWindow,
1642 Qt::RightDockWidgetArea);
1643 addDockWindow (m_dockGeometryWindow,
1647 Qt::RightDockWidgetArea);
1652 QLocale localeDefault;
1654 QVariant (localeDefault.language())).toInt());
1656 QVariant (localeDefault.country())).toInt());
1657 QLocale locale (language,
1688 QVariant (QDir::currentPath())).toString ());
1690 QVariant (QDir::currentPath())).toString ());
1693 updateSmallDialogs();
1695 settings.endGroup();
1698 void MainWindow::settingsWrite ()
1706 settings.endGroup ();
1711 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
1715 if (m_dockChecklistGuide->isFloating()) {
1725 if (m_dockFittingWindow->isFloating()) {
1733 if (m_dockGeometryWindow->isFloating()) {
1768 settings.endGroup ();
1771 bool MainWindow::setupAfterLoadNewDocument (
const QString &fileName,
1772 const QString &temporaryMessage ,
1773 ImportType importType)
1776 <<
" file=" << fileName.toLatin1().data()
1777 <<
" message=" << temporaryMessage.toLatin1().data()
1778 <<
" importType=" << importType;
1783 const QString EMPTY_CURVE_NAME_TO_SKIP_BACKGROUND_PROCESSING;
1787 m_digitizeStateContext->
resetOnLoad (m_cmdMediator);
1792 EMPTY_CURVE_NAME_TO_SKIP_BACKGROUND_PROCESSING);
1794 m_cmdMediator->
pixmap ());
1798 if (importType == IMPORT_TYPE_ADVANCED) {
1800 applyZoomFactorAfterLoad();
1803 dlgImportAdvanced.exec();
1805 if (dlgImportAdvanced.result() == QDialog::Rejected) {
1809 int numberCoordSystem = signed (dlgImportAdvanced.numberCoordSystem());
1818 connect (m_actionEditUndo, SIGNAL (triggered ()), m_cmdMediator, SLOT (undo ()));
1819 connect (m_actionEditUndo, SIGNAL (triggered ()), m_cmdStackShadow, SLOT (slotUndo ()));
1820 connect (m_actionEditRedo, SIGNAL (triggered ()), m_cmdMediator, SLOT (redo ()));
1821 connect (m_actionEditRedo, SIGNAL (triggered ()), m_cmdStackShadow, SLOT (slotRedo ()));
1822 connect (m_cmdMediator, SIGNAL (canRedoChanged(
bool)),
this, SLOT (slotCanRedoChanged (
bool)));
1823 connect (m_cmdMediator, SIGNAL (canUndoChanged(
bool)),
this, SLOT (slotCanUndoChanged (
bool)));
1824 connect (m_cmdMediator, SIGNAL (redoTextChanged (
const QString &)),
this, SLOT (slotRedoTextChanged (
const QString &)));
1825 connect (m_cmdMediator, SIGNAL (undoTextChanged (
const QString &)),
this, SLOT (slotUndoTextChanged (
const QString &)));
1826 loadCurveListFromCmdMediator ();
1827 loadCoordSystemListFromCmdMediator ();
1830 m_isDocumentExported =
false;
1840 m_cmbCurve->currentText ());
1841 m_backgroundStateContext->
setBackgroundImage (static_cast<BackgroundImage> (m_cmbBackground->currentIndex ()));
1843 applyZoomFactorAfterLoad();
1845 setCurrentFile(fileName);
1849 saveStartingDocumentSnapshot();
1856 bool MainWindow::setupAfterLoadReplacingImage (
const QString &fileName,
1857 const QString &temporaryMessage ,
1858 ImportType importType)
1861 <<
" file=" << fileName.toLatin1().data()
1862 <<
" message=" << temporaryMessage.toLatin1().data()
1863 <<
" importType=" << importType;
1868 m_cmdMediator->clear();
1871 m_cmdMediator->
pixmap ());
1873 m_isDocumentExported =
false;
1875 m_backgroundStateContext->
setBackgroundImage (static_cast<BackgroundImage> (m_cmbBackground->currentIndex ()));
1877 applyZoomFactorAfterLoad();
1881 setCurrentFile(fileName);
1887 saveStartingDocumentSnapshot();
1897 <<
" files=" << m_loadStartupFiles.join (
",").toLatin1().data();
1899 QMainWindow::showEvent (event);
1901 if (m_loadStartupFiles.count() > 0) {
1903 m_timerLoadStartupFiles =
new QTimer;
1904 m_timerLoadStartupFiles->setSingleShot (
true);
1905 connect (m_timerLoadStartupFiles, SIGNAL (timeout ()),
this, SLOT (slotLoadStartupFiles ()));
1906 m_timerLoadStartupFiles->start (0);
1916 void MainWindow::slotBtnPrintAll ()
1922 QPrinter printer (QPrinter::HighResolution);
1923 QPrintDialog dlg (&printer,
this);
1924 if (dlg.exec() == QDialog::Accepted) {
1925 QPainter painter (&printer);
1926 m_view->render (&painter);
1933 void MainWindow::slotBtnShowAllPressed ()
1941 void MainWindow::slotBtnShowAllReleased ()
1949 void MainWindow::slotCanRedoChanged (
bool canRedo)
1953 m_actionEditRedo->setEnabled (canRedo || m_cmdStackShadow->
canRedo());
1956 void MainWindow::slotCanUndoChanged (
bool canUndo)
1960 m_actionEditUndo->setEnabled (canUndo);
1963 void MainWindow::slotChecklistClosed()
1967 m_actionViewChecklistGuide->setChecked (
false);
1970 void MainWindow::slotCleanChanged(
bool clean)
1974 setWindowModified (!clean);
1977 void MainWindow::slotCmbBackground(
int currentIndex)
1981 switch (currentIndex) {
1983 if (!m_actionViewBackgroundNone->isChecked()) {
1984 m_actionViewBackgroundNone->toggle();
1989 if (!m_actionViewBackgroundOriginal->isChecked ()) {
1990 m_actionViewBackgroundOriginal->toggle();
1995 if (!m_actionViewBackgroundFiltered->isChecked ()) {
1996 m_actionViewBackgroundFiltered->toggle();
2001 m_backgroundStateContext->
setBackgroundImage (static_cast<BackgroundImage> (currentIndex));
2004 void MainWindow::slotCmbCoordSystem(
int index)
2010 static_cast<CoordSystemIndex> (index));
2012 m_cmdMediator->push (cmd);
2015 void MainWindow::slotCmbCurve(
int )
2023 m_cmbCurve->currentText ());
2027 updateViewedCurves();
2029 updateFittingWindow();
2030 updateGeometryWindow();
2033 void MainWindow::slotContextMenuEventAxis (QString pointIdentifier)
2035 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotContextMenuEventAxis point=" << pointIdentifier.toLatin1 ().data ();
2041 void MainWindow::slotContextMenuEventGraph (QStringList pointIdentifiers)
2043 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotContextMenuEventGraph point=" << pointIdentifiers.join(
",").toLatin1 ().data ();
2049 void MainWindow::slotDigitizeAxis ()
2055 m_cmbCurve->setEnabled (
false);
2061 void MainWindow::slotDigitizeColorPicker ()
2067 m_cmbCurve->setEnabled (
true);
2073 void MainWindow::slotDigitizeCurve ()
2079 m_cmbCurve->setEnabled (
true);
2085 void MainWindow::slotDigitizePointMatch ()
2091 m_cmbCurve->setEnabled (
true);
2097 void MainWindow::slotDigitizeScale ()
2103 m_cmbCurve->setEnabled (
false);
2109 void MainWindow::slotDigitizeSegment ()
2115 m_cmbCurve->setEnabled (
true);
2121 void MainWindow::slotDigitizeSelect ()
2127 m_cmbCurve->setEnabled (
false);
2133 void MainWindow::slotEditCopy ()
2138 bool tableFittingIsActive, tableFittingIsCopyable;
2139 bool tableGeometryIsActive, tableGeometryIsCopyable;
2140 m_dockFittingWindow->
getTableStatus (tableFittingIsActive, tableFittingIsCopyable);
2141 m_dockGeometryWindow->
getTableStatus (tableGeometryIsActive, tableGeometryIsCopyable);
2143 if (tableFittingIsActive) {
2146 m_dockFittingWindow->
doCopy ();
2148 }
else if (tableGeometryIsActive) {
2151 m_dockGeometryWindow->
doCopy ();
2157 const QList<QGraphicsItem*> &items = m_scene->selectedItems();
2168 void MainWindow::slotEditCut ()
2173 bool tableFittingIsActive, tableFittingIsCopyable;
2174 bool tableGeometryIsActive, tableGeometryIsCopyable;
2175 m_dockFittingWindow->
getTableStatus (tableFittingIsActive, tableFittingIsCopyable);
2176 m_dockGeometryWindow->
getTableStatus (tableGeometryIsActive, tableGeometryIsCopyable);
2178 if (tableFittingIsActive || tableGeometryIsActive) {
2186 const QList<QGraphicsItem*> &items = m_scene->selectedItems();
2197 void MainWindow::slotEditDelete ()
2202 bool tableFittingIsActive, tableFittingIsCopyable;
2203 bool tableGeometryIsActive, tableGeometryIsCopyable;
2204 m_dockFittingWindow->
getTableStatus (tableFittingIsActive, tableFittingIsCopyable);
2205 m_dockGeometryWindow->
getTableStatus (tableGeometryIsActive, tableGeometryIsCopyable);
2207 if (tableFittingIsActive || tableGeometryIsActive) {
2220 const QList<QGraphicsItem*> &items = m_scene->selectedItems();
2221 QStringList pointIdentifiers = scaleBarAxisPoints.
unite (m_cmdMediator,
2232 void MainWindow::slotEditMenu ()
2236 m_actionEditPasteAsNew->setEnabled (!QApplication::clipboard()->image().isNull());
2237 m_actionEditPasteAsNewAdvanced->setEnabled (!QApplication::clipboard()->image().isNull());
2240 void MainWindow::slotEditPaste ()
2244 QList<QPoint> points;
2245 QList<double> ordinals;
2254 m_cmbCurve->currentText (),
2261 void MainWindow::slotEditPasteAsNew ()
2265 filePaste (IMPORT_TYPE_SIMPLE);
2268 void MainWindow::slotEditPasteAsNewAdvanced ()
2272 filePaste (IMPORT_TYPE_ADVANCED);
2275 void MainWindow::slotFileClose()
2295 if (m_fittingCurve !=
nullptr) {
2296 m_scene->removeItem (m_fittingCurve);
2297 m_fittingCurve =
nullptr;
2304 m_backgroundStateContext->
close ();
2307 m_scene->setSceneRect (QRectF (0, 0, 1, 1));
2310 m_dockFittingWindow->
clear ();
2313 m_dockGeometryWindow->
clear ();
2316 delete m_cmdMediator;
2319 m_cmdMediator =
nullptr;
2324 m_gridLines.
clear();
2329 void MainWindow::slotFileExport ()
2339 if (m_isExportOnly) {
2340 fileName = fileNameForExportOnly ();
2343 QString filter = QString (
"%1;;%2;;All files (*.*)")
2348 QString defaultFileName = QString (
"%1/%2.%3")
2350 .arg (m_currentFile)
2353 QString filterCsv = exportStrategy.
filterCsv ();
2355 fileName = dlg.getSaveFileName (
this,
2362 if (!fileName.isEmpty ()) {
2365 fileExport(fileName,
2374 void MainWindow::slotFileImport ()
2378 fileImportWithPrompts (IMPORT_TYPE_SIMPLE);
2381 void MainWindow::slotFileImportAdvanced ()
2385 fileImportWithPrompts (IMPORT_TYPE_ADVANCED);
2388 void MainWindow::slotFileImportDraggedImage(QImage image)
2395 IMPORT_TYPE_SIMPLE);
2398 void MainWindow::slotFileImportDraggedImageUrl(QUrl url)
2400 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotFileImportDraggedImageUrl url=" << url.toString ().toLatin1 ().data ();
2407 void MainWindow::slotFileImportImage(QString fileName, QImage image)
2409 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotFileImportImage fileName=" << fileName.toLatin1 ().data ();
2412 loadImage (fileName,
2414 IMPORT_TYPE_SIMPLE);
2417 void MainWindow::slotFileImportImageReplace ()
2421 fileImportWithPrompts (IMPORT_TYPE_IMAGE_REPLACE);
2424 void MainWindow::slotFileOpen()
2432 QString filter = QString (
"%1 (*.%2);; All Files (*.*)")
2433 .arg (ENGAUGE_FILENAME_DESCRIPTION)
2437 QString fileName = QFileDialog::getOpenFileName (
this,
2438 tr(
"Open Document"),
2441 if (!fileName.isEmpty ()) {
2444 loadDocumentFile (fileName);
2450 void MainWindow::slotFileOpenDraggedDigFile (QString fileName)
2454 loadDocumentFile (fileName);
2457 void MainWindow::slotFilePrint()
2461 QPrinter printer (QPrinter::HighResolution);
2462 QPrintDialog dlg (&printer,
this);
2463 if (dlg.exec() == QDialog::Accepted) {
2464 QPainter painter (&printer);
2465 m_view->render (&painter);
2470 bool MainWindow::slotFileSave()
2474 if (m_engaugeFile.isEmpty()) {
2475 return slotFileSaveAs();
2477 return saveDocumentFile (m_engaugeFile);
2481 bool MainWindow::slotFileSaveAs()
2486 QString filenameDefault = m_currentFile;
2488 filenameDefault = QString (
"%1.%2")
2489 .arg (m_currentFile)
2493 if (!m_engaugeFile.isEmpty()) {
2494 filenameDefault = m_engaugeFile;
2497 QString filterDigitizer = QString (
"%1 (*.%2)")
2498 .arg (ENGAUGE_FILENAME_DESCRIPTION)
2500 QString filterAll (
"All files (*. *)");
2502 QStringList filters;
2503 filters << filterDigitizer;
2504 filters << filterAll;
2508 QFileDialog dlg(
this);
2509 dlg.setFileMode (QFileDialog::AnyFile);
2510 dlg.selectNameFilter (filterDigitizer);
2511 dlg.setNameFilters (filters);
2512 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
2514 dlg.setWindowModality(Qt::WindowModal);
2516 dlg.setAcceptMode(QFileDialog::AcceptSave);
2517 dlg.selectFile(filenameDefault);
2521 QStringList files = dlg.selectedFiles();
2523 return saveDocumentFile(files.at(0));
2529 void MainWindow::slotFittingWindowClosed()
2533 m_actionViewFittingWindow->setChecked (
false);
2544 <<
" order=" << fittingCurveCoef.size() - 1;
2546 if (m_fittingCurve !=
nullptr) {
2547 m_scene->removeItem (m_fittingCurve);
2548 delete m_fittingCurve;
2557 m_fittingCurve->setVisible (m_actionViewFittingWindow->isChecked ());
2558 m_scene->addItem (m_fittingCurve);
2561 void MainWindow::slotGeometryWindowClosed()
2565 m_actionViewGeometryWindow->setChecked (
false);
2568 void MainWindow::slotHelpAbout()
2576 void MainWindow::slotHelpTutorial()
2580 m_tutorialDlg->show ();
2581 m_tutorialDlg->exec ();
2584 void MainWindow::slotKeyPress (Qt::Key key,
2585 bool atLeastOneSelectedItem)
2588 <<
" key=" << QKeySequence (key).toString().toLatin1 ().data ()
2589 <<
" atLeastOneSelectedItem=" << (atLeastOneSelectedItem ?
"true" :
"false");
2593 atLeastOneSelectedItem);
2596 void MainWindow::slotLoadStartupFiles ()
2602 QString fileName = m_loadStartupFiles.front();
2603 m_loadStartupFiles.pop_front();
2609 loadDocumentFile (fileName);
2613 fileImport (fileName,
2614 IMPORT_TYPE_SIMPLE);
2618 if (m_loadStartupFiles.count() > 0) {
2622 QProcess::startDetached (QCoreApplication::applicationFilePath(),
2623 m_commandLineWithoutLoadStartupFiles + m_loadStartupFiles);
2627 void MainWindow::slotMouseMove (QPointF pos)
2632 if (m_cmdMediator !=
nullptr) {
2635 QString coordsScreen, coordsGraph, resolutionGraph;
2655 void MainWindow::slotMousePress (QPointF pos)
2665 void MainWindow::slotMouseRelease (QPointF pos)
2669 if (pos.x() < 0 || pos.y() < 0) {
2683 void MainWindow::slotRecentFileAction ()
2687 QAction *action = qobject_cast<QAction*>(sender ());
2690 QString fileName = action->data().toString();
2691 loadDocumentFile (fileName);
2695 void MainWindow::slotRecentFileClear ()
2699 QStringList emptyList;
2705 updateRecentFileList();
2708 void MainWindow::slotRedoTextChanged (
const QString &text)
2712 QString completeText (
"Redo");
2713 if (!text.isEmpty ()) {
2714 completeText += QString (
" \"%1\"").arg (text);
2716 m_actionEditRedo->setText (completeText);
2719 void MainWindow::slotSettingsAxesChecker ()
2723 m_dlgSettingsAxesChecker->
load (*m_cmdMediator);
2724 m_dlgSettingsAxesChecker->show ();
2727 void MainWindow::slotSettingsColorFilter ()
2731 m_dlgSettingsColorFilter->
load (*m_cmdMediator);
2732 m_dlgSettingsColorFilter->show ();
2735 void MainWindow::slotSettingsCoords ()
2739 m_dlgSettingsCoords->
load (*m_cmdMediator);
2740 m_dlgSettingsCoords->show ();
2743 void MainWindow::slotSettingsCurveList ()
2747 m_dlgSettingsCurveList->
load (*m_cmdMediator);
2748 m_dlgSettingsCurveList->show ();
2751 void MainWindow::slotSettingsCurveProperties ()
2755 m_dlgSettingsCurveProperties->
load (*m_cmdMediator);
2757 m_dlgSettingsCurveProperties->show ();
2760 void MainWindow::slotSettingsDigitizeCurve ()
2764 m_dlgSettingsDigitizeCurve->
load (*m_cmdMediator);
2765 m_dlgSettingsDigitizeCurve->show ();
2768 void MainWindow::slotSettingsExportFormat ()
2773 m_dlgSettingsExportFormat->
load (*m_cmdMediator);
2774 m_dlgSettingsExportFormat->show ();
2781 void MainWindow::slotSettingsGeneral ()
2785 m_dlgSettingsGeneral->
load (*m_cmdMediator);
2786 m_dlgSettingsGeneral->show ();
2789 void MainWindow::slotSettingsGridDisplay()
2793 m_dlgSettingsGridDisplay->
load (*m_cmdMediator);
2794 m_dlgSettingsGridDisplay->show ();
2797 void MainWindow::slotSettingsGridRemoval ()
2801 m_dlgSettingsGridRemoval->
load (*m_cmdMediator);
2802 m_dlgSettingsGridRemoval->show ();
2805 void MainWindow::slotSettingsPointMatch ()
2809 m_dlgSettingsPointMatch->
load (*m_cmdMediator);
2810 m_dlgSettingsPointMatch->show ();
2813 void MainWindow::slotSettingsSegments ()
2817 m_dlgSettingsSegments->
load (*m_cmdMediator);
2818 m_dlgSettingsSegments->show ();
2821 void MainWindow::slotTableStatusChange ()
2830 void MainWindow::slotSettingsMainWindow ()
2836 m_dlgSettingsMainWindow->show ();
2839 void MainWindow::slotTimeoutRegressionErrorReport ()
2842 <<
" cmdStackIndex=" << m_cmdMediator->index()
2843 <<
" cmdStackCount=" << m_cmdMediator->count();
2845 if (m_cmdStackShadow->
canRedo()) {
2848 QDir::setCurrent (m_startupDirectory);
2853 QDir::setCurrent (m_startupDirectory);
2857 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
2858 exportAllCoordinateSystemsAfterRegressionTests ();
2862 m_cmdMediator->setClean();
2868 void MainWindow::slotTimeoutRegressionFileCmdScript ()
2872 if (m_fileCmdScript->
canRedo()) {
2875 QDir::setCurrent (m_startupDirectory);
2877 m_fileCmdScript->
redo(*
this);
2880 QDir::setCurrent (m_startupDirectory);
2885 if (m_cmdMediator !=
nullptr) {
2887 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
2888 exportAllCoordinateSystemsAfterRegressionTests ();
2892 m_cmdMediator->setClean();
2902 void MainWindow::slotUndoTextChanged (
const QString &text)
2906 QString completeText (
"Undo");
2907 if (!text.isEmpty ()) {
2908 completeText += QString (
" \"%1\"").arg (text);
2910 m_actionEditUndo->setText (completeText);
2913 void MainWindow::slotViewGridLines ()
2920 void MainWindow::slotViewGroupBackground(QAction *action)
2926 int indexBackground;
2927 if (action == m_actionViewBackgroundNone) {
2930 }
else if (action == m_actionViewBackgroundOriginal) {
2933 }
else if (action == m_actionViewBackgroundFiltered) {
2944 m_cmbBackground->setCurrentIndex (indexBackground);
2948 void MainWindow::slotViewGroupCurves(QAction * )
2952 updateViewedCurves ();
2955 void MainWindow::slotViewGroupStatus(QAction *action)
2961 if (action == m_actionStatusNever) {
2963 }
else if (action == m_actionStatusTemporary) {
2970 void MainWindow::slotViewToolBarBackground ()
2974 if (m_actionViewBackground->isChecked ()) {
2975 m_toolBackground->show();
2977 m_toolBackground->hide();
2981 void MainWindow::slotViewToolBarChecklistGuide ()
2985 if (m_actionViewChecklistGuide->isChecked ()) {
2986 m_dockChecklistGuide->show();
2988 m_dockChecklistGuide->hide();
2992 void MainWindow::slotViewToolBarCoordSystem ()
2996 if (m_actionViewCoordSystem->isChecked ()) {
2997 m_toolCoordSystem->show();
2999 m_toolCoordSystem->hide();
3003 void MainWindow::slotViewToolBarDigitize ()
3007 if (m_actionViewDigitize->isChecked ()) {
3008 m_toolDigitize->show();
3010 m_toolDigitize->hide();
3014 void MainWindow::slotViewToolBarFittingWindow()
3018 if (m_actionViewFittingWindow->isChecked()) {
3019 m_dockFittingWindow->show ();
3020 if (m_fittingCurve !=
nullptr) {
3021 m_fittingCurve->setVisible (
true);
3024 m_dockFittingWindow->hide ();
3025 if (m_fittingCurve !=
nullptr) {
3026 m_fittingCurve->setVisible (
false);
3031 void MainWindow::slotViewToolBarGeometryWindow ()
3035 if (m_actionViewGeometryWindow->isChecked ()) {
3036 m_dockGeometryWindow->show();
3038 m_dockGeometryWindow->hide();
3042 void MainWindow::slotViewToolBarSettingsViews ()
3046 if (m_actionViewSettingsViews->isChecked ()) {
3047 m_toolSettingsViews->show();
3049 m_toolSettingsViews->hide();
3053 void MainWindow::slotViewToolTips ()
3060 void MainWindow::slotViewZoom (
int zoom)
3065 ZoomFactor zoomFactor = static_cast<ZoomFactor> (zoom);
3066 m_zoomMapToAction [zoomFactor]->setChecked (
true);
3067 slotViewZoomFactor (static_cast<ZoomFactor> (zoom));
3070 void MainWindow::slotViewZoomFactor (
ZoomFactor zoomFactor)
3075 m_backgroundStateContext->
fitInView (*m_view);
3079 double factor = zoomTransition.
mapToFactor (zoomFactor);
3081 QTransform transform;
3082 transform.scale (factor, factor);
3083 m_view->setTransform (transform);
3089 void MainWindow::slotViewZoomFactorInt (
int zoom)
3093 slotViewZoomFactor (static_cast<ZoomFactor> (zoom));
3096 void MainWindow::slotViewZoomIn ()
3102 m_view->transform ().m11 (),
3103 m_view->transform ().m22 (),
3104 m_actionZoomFill->isChecked ());
3105 setNonFillZoomFactor (zoomFactorNew);
3109 void MainWindow::slotViewZoomInFromWheelEvent ()
3117 m_view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
3122 m_view->setTransformationAnchor(QGraphicsView::NoAnchor);
3126 void MainWindow::slotViewZoomOut ()
3133 m_view->transform ().m11 (),
3134 m_view->transform ().m22 (),
3135 m_actionZoomFill->isChecked ());
3136 setNonFillZoomFactor (zoomFactorNew);
3139 void MainWindow::slotViewZoomOutFromWheelEvent ()
3147 m_view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
3152 m_view->setTransformationAnchor(QGraphicsView::NoAnchor);
3156 void MainWindow::startRegressionDropTest (
const QStringList &loadStartupFiles)
3165 connect (
this, SIGNAL (
signalDropRegression (QString)), m_view, SLOT (slotDropRegression (QString)));
3167 for (
int counter = 0; counter < loadStartupFiles.size (); counter++) {
3168 QString filenameDrop = loadStartupFiles.at (counter);
3173 QSize siz = m_view->size();
3175 QString filenameCsv;
3176 if (filenameDrop.startsWith (
"http")) {
3180 filenameCsv =
"../test/drag_and_drop_http.csv_actual_1";
3185 filenameCsv = QString (
"%1_%2")
3186 .arg (exportRegressionFilenameFromInputFilename (filenameDrop))
3190 QFile file (filenameCsv);
3191 file.open (QIODevice::WriteOnly);
3192 QTextStream str (&file);
3193 str << siz.width() <<
"x" << siz.height() <<
"\n";
3200 void MainWindow::startRegressionTestErrorReport(
const QString ®ressionInputFile)
3211 m_regressionFile = exportRegressionFilenameFromInputFilename (regressionInputFile);
3213 m_timerRegressionErrorReport =
new QTimer();
3214 m_timerRegressionErrorReport->setSingleShot(
false);
3215 connect (m_timerRegressionErrorReport, SIGNAL (timeout()),
this, SLOT (slotTimeoutRegressionErrorReport()));
3220 void MainWindow::startRegressionTestFileCmdScript()
3224 m_timerRegressionFileCmdScript =
new QTimer();
3225 m_timerRegressionFileCmdScript->setSingleShot(
false);
3226 connect (m_timerRegressionFileCmdScript, SIGNAL (timeout()),
this, SLOT (slotTimeoutRegressionFileCmdScript()));
3233 return m_transformation;
3249 updateAfterCommandStatusBarCoords ();
3251 updateHighlightOpacity ();
3257 updateChecklistGuide ();
3258 updateFittingWindow ();
3259 updateGeometryWindow();
3264 writeCheckpointToLogFile ();
3266 docScrub.
check (*
this,
3271 m_view->setFocus ();
3274 void MainWindow::updateAfterCommandStatusBarCoords ()
3281 const QPoint HACK_SO_GRAPH_COORDINATE_MATCHES_INPUT (1, 1);
3285 updateTransformationAndItsDependencies();
3288 if (!m_transformationBefore.transformIsDefined() && m_transformation.
transformIsDefined()) {
3297 }
else if (m_transformationBefore.transformIsDefined() && !m_transformation.
transformIsDefined()) {
3306 }
else if (m_transformation.
transformIsDefined() && (m_transformationBefore != m_transformation)) {
3315 QPoint posLocal = m_view->mapFromGlobal (QCursor::pos ()) - HACK_SO_GRAPH_COORDINATE_MATCHES_INPUT;
3316 QPointF posScreen = m_view->mapToScene (posLocal);
3318 slotMouseMove (posScreen);
3328 void MainWindow::updateChecklistGuide ()
3332 m_dockChecklistGuide->
update (*m_cmdMediator,
3333 m_isDocumentExported);
3336 void MainWindow::updateControls ()
3339 <<
" selectedItems=" << m_scene->selectedItems().count();
3341 m_cmbBackground->setEnabled (!m_currentFile.isEmpty ());
3343 m_actionImportImageReplace->setEnabled (m_cmdMediator !=
nullptr);
3344 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
3345 m_menuFileOpenRecent->setEnabled ((m_actionRecentFiles.count () > 0) &&
3346 (m_actionRecentFiles.at(0)->isVisible ()));
3348 m_actionClose->setEnabled (!m_currentFile.isEmpty ());
3349 m_actionSave->setEnabled (!m_currentFile.isEmpty ());
3350 m_actionSaveAs->setEnabled (!m_currentFile.isEmpty ());
3351 m_actionExport->setEnabled (!m_currentFile.isEmpty ());
3352 m_actionPrint->setEnabled (!m_currentFile.isEmpty ());
3354 if (m_cmdMediator ==
nullptr) {
3355 m_actionEditUndo->setEnabled (
false);
3356 m_actionEditRedo->setEnabled (
false);
3358 m_actionEditUndo->setEnabled (m_cmdMediator->canUndo ());
3359 m_actionEditRedo->setEnabled (m_cmdMediator->canRedo () || m_cmdStackShadow->
canRedo ());
3361 bool tableFittingIsActive, tableFittingIsCopyable;
3362 bool tableGeometryIsActive, tableGeometryIsCopyable;
3363 m_dockFittingWindow->
getTableStatus (tableFittingIsActive, tableFittingIsCopyable);
3364 m_dockGeometryWindow->
getTableStatus (tableGeometryIsActive, tableGeometryIsCopyable);
3365 m_actionEditCut->setEnabled (!tableFittingIsActive &&
3366 !tableGeometryIsActive &&
3367 m_scene->selectedItems().count () > 0);
3368 m_actionEditCopy->setEnabled ((!tableFittingIsActive && !tableGeometryIsActive && m_scene->selectedItems().count () > 0) ||
3369 (tableFittingIsActive && tableFittingIsCopyable) ||
3370 (tableGeometryIsActive && tableGeometryIsCopyable));
3371 m_actionEditPaste->setEnabled (m_digitizeStateContext->
canPaste (m_transformation,
3373 m_actionEditDelete->setEnabled (!tableFittingIsActive &&
3374 !tableGeometryIsActive &&
3375 m_scene->selectedItems().count () > 0);
3378 m_actionDigitizeAxis->setEnabled (modeGraph ());
3379 m_actionDigitizeScale->setEnabled (
modeMap ());
3380 m_actionDigitizeCurve ->setEnabled (!m_currentFile.isEmpty ());
3381 m_actionDigitizePointMatch->setEnabled (!m_currentFile.isEmpty ());
3382 m_actionDigitizeColorPicker->setEnabled (!m_currentFile.isEmpty ());
3383 m_actionDigitizeSegment->setEnabled (!m_currentFile.isEmpty ());
3384 m_actionDigitizeSelect->setEnabled (!m_currentFile.isEmpty ());
3386 m_actionViewGridLines->setEnabled (
true);
3388 m_actionViewGridLines->setEnabled (
false);
3389 m_actionViewGridLines->setChecked (
false);
3391 m_actionViewBackground->setEnabled (!m_currentFile.isEmpty());
3392 m_actionViewChecklistGuide->setEnabled (!m_dockChecklistGuide->
browserIsEmpty());
3393 m_actionViewDigitize->setEnabled (!m_currentFile.isEmpty ());
3394 m_actionViewSettingsViews->setEnabled (!m_currentFile.isEmpty ());
3396 m_actionSettingsCoords->setEnabled (!m_currentFile.isEmpty ());
3397 m_actionSettingsCurveList->setEnabled (!m_currentFile.isEmpty ());
3398 m_actionSettingsCurveProperties->setEnabled (!m_currentFile.isEmpty ());
3399 m_actionSettingsDigitizeCurve->setEnabled (!m_currentFile.isEmpty ());
3400 m_actionSettingsExport->setEnabled (!m_currentFile.isEmpty ());
3401 m_actionSettingsColorFilter->setEnabled (!m_currentFile.isEmpty ());
3402 m_actionSettingsAxesChecker->setEnabled (!m_currentFile.isEmpty ());
3403 m_actionSettingsGridDisplay->setEnabled (!m_currentFile.isEmpty () && m_transformation.
transformIsDefined());
3404 m_actionSettingsGridRemoval->setEnabled (!m_currentFile.isEmpty ());
3405 m_actionSettingsPointMatch->setEnabled (!m_currentFile.isEmpty ());
3406 m_actionSettingsSegments->setEnabled (!m_currentFile.isEmpty ());
3407 m_actionSettingsGeneral->setEnabled (!m_currentFile.isEmpty ());
3409 m_groupBackground->setEnabled (!m_currentFile.isEmpty ());
3410 m_groupCurves->setEnabled (!m_currentFile.isEmpty ());
3411 m_groupZoom->setEnabled (!m_currentFile.isEmpty ());
3413 m_actionZoomIn->setEnabled (!m_currentFile.isEmpty ());
3414 m_actionZoomOut->setEnabled (!m_currentFile.isEmpty ());
3424 loadCurveListFromCmdMediator ();
3426 updateTransformationAndItsDependencies();
3440 switch (digitizeState) {
3442 m_actionDigitizeAxis->setChecked(
true);
3447 m_actionDigitizeColorPicker->setChecked(
true);
3448 slotDigitizeColorPicker();
3452 m_actionDigitizeCurve->setChecked(
true);
3453 slotDigitizeCurve();
3460 m_actionDigitizePointMatch->setChecked(
true);
3461 slotDigitizePointMatch();
3465 m_actionDigitizeScale->setChecked(
true);
3466 slotDigitizeScale();
3470 m_actionDigitizeSegment->setChecked(
true);
3471 slotDigitizeSegment();
3475 m_actionDigitizeSelect->setChecked(
true);
3476 slotDigitizeSelect();
3485 void MainWindow::updateFittingWindow ()
3489 if (m_cmdMediator !=
nullptr &&
3490 m_cmbCurve !=
nullptr) {
3493 m_dockFittingWindow->
update (*m_cmdMediator,
3495 m_cmbCurve->currentText (),
3500 void MainWindow::updateGeometryWindow ()
3504 if (m_cmdMediator !=
nullptr &&
3505 m_cmbCurve !=
nullptr) {
3508 m_dockGeometryWindow->
update (*m_cmdMediator,
3510 m_cmbCurve->currentText (),
3523 void MainWindow::updateGridLines ()
3528 m_gridLines.
clear ();
3539 m_gridLines.
setVisible (m_actionViewGridLines->isChecked());
3542 void MainWindow::updateHighlightOpacity ()
3544 if (m_cmdMediator !=
nullptr) {
3550 m_dockGeometryWindow,
3555 void MainWindow::updateRecentFileList()
3559 #if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
3564 unsigned int count = unsigned (recentFilePaths.size());
3571 for (i = 0; i < signed (count); i++) {
3572 QString strippedName = QFileInfo (recentFilePaths.at(i)).fileName();
3573 m_actionRecentFiles.at (i)->setText (strippedName);
3574 m_actionRecentFiles.at (i)->setData (recentFilePaths.at (i));
3575 m_actionRecentFiles.at (i)->setVisible (
true);
3580 m_actionRecentFiles.at (i)->setVisible (
false);
3590 if (m_transformation.transformIsDefined()) {
3595 m_cmbCurve->currentText());
3601 m_cmbCurve->currentText());
3614 m_cmbCurve->currentText());
3631 loadCurveListFromCmdMediator();
3650 modelDigitizeCurve);
3682 void MainWindow::updateSettingsMainWindow()
3689 m_actionZoomIn->setShortcut (tr (
""));
3690 m_actionZoomOut->setShortcut (tr (
""));
3694 m_actionZoomIn->setShortcut (tr (
"+"));
3695 m_actionZoomOut->setShortcut (tr (
"-"));
3699 if ((m_scene !=
nullptr) &&
3700 (m_cmdMediator !=
nullptr)) {
3704 updateHighlightOpacity();
3705 updateWindowTitle();
3706 updateFittingWindow();
3707 updateGeometryWindow();
3733 void MainWindow::updateSmallDialogs ()
3750 void MainWindow::updateTransformationAndItsDependencies()
3752 m_transformation.update (!m_currentFile.isEmpty (),
3761 m_cmbCurve->currentText ());
3768 void MainWindow::updateViewedCurves ()
3772 if (m_actionViewCurvesAll->isChecked ()) {
3776 }
else if (m_actionViewCurvesSelected->isChecked ()) {
3780 }
else if (m_actionViewCurvesNone->isChecked ()) {
3793 QString activeCurve = m_digitizeStateContext->
activeCurve ();
3800 if (activeCurve.isEmpty ()) {
3813 m_cmdMediator->
pixmap ());
3818 void MainWindow::updateWindowTitle ()
3822 const QString PLACEHOLDER (
"[*]");
3824 QString title = QString (
"%1 %2")
3825 .arg (tr (
"Engauge Digitizer"))
3828 QString fileNameMaybeStripped;
3829 if (!m_currentFileWithPathAndFileExtension.isEmpty()) {
3831 QFileInfo fileInfo (m_currentFileWithPathAndFileExtension);
3838 fileNameMaybeStripped = fileInfo.completeBaseName();
3842 fileNameMaybeStripped = m_currentFileWithPathAndFileExtension;
3846 title += QString (
": %1")
3847 .arg (fileNameMaybeStripped);
3852 title += PLACEHOLDER;
3854 setWindowTitle (title);
3869 void MainWindow::writeCheckpointToLogFile ()
3872 QString checkpointDoc;
3873 QTextStream strDoc (&checkpointDoc);
3878 QString checkpointScene;
3879 QTextStream strScene (&checkpointScene);
3887 <<
"--------------DOCUMENT CHECKPOINT START----------" <<
"\n"
3888 << checkpointDoc.toLatin1().data()
3889 <<
"---------------DOCUMENT CHECKPOINT END-----------" <<
"\n"
3890 <<
"----------------SCENE CHECKPOINT START-----------" <<
"\n"
3891 << checkpointScene.toLatin1().data()
3892 <<
"-----------------SCENE CHECKPOINT END------------" ;