57#if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
61#ifdef ENGAUGE_JPEG2000
80#include <QApplication>
85#include <QDesktopServices>
87#include <QDomDocument>
90#include <QImageReader>
92#include <QKeySequence>
96#include <QPrintDialog>
101#include <QSignalMapper>
102#include <QTextStream>
103#if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
108#include <QToolButton>
110#include <QVBoxLayout>
112#include <QXmlStreamReader>
113#include <QXmlStreamWriter>
127static 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),
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 ();
259void 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());
289void MainWindow::applyZoomFactorAfterLoad()
294 if (m_zoomMapFromInitial.contains (zoomFactorInitial)) {
295 zoomFactor = m_zoomMapFromInitial [zoomFactorInitial];
297 zoomFactor = currentZoomFactor ();
300 zoomFactor = currentZoomFactor();
303 slotViewZoom (zoomFactor);
306void 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;
356ZoomFactor MainWindow::currentZoomFactor ()
const
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)
394void MainWindow::exportAllCoordinateSystemsAfterRegressionTests()
396 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::exportAllCoordinateSystemsAfterRegressionTests curDir=" << QDir::currentPath().toLatin1().data();
403 QString regressionFile = QString (
"%1_%2")
404 .arg (m_regressionFile)
412 exportStrategy.fileExport (regressionFile);
416 ExportToFile exportStrategy;
418 fileExport (regressionFile,
425QString 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);
445void 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);
457 DocumentModelExportFormat modelExportFormat = modelExportOverride (m_cmdMediator->document().modelExport(),
461 m_cmdMediator->document(),
466 m_isDocumentExported =
true;
468 updateChecklistGuide ();
469 m_statusBar->showTemporaryMessage(
"File saved");
474 <<
" file=" << fileName.toLatin1().data()
475 <<
" curDir=" << QDir::currentPath().toLatin1().data();
476 QMessageBox::critical (
nullptr,
478 tr (
"Unable to export to file") +
" " + fileName);
482void 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);
516void 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,
555 m_modelMainWindow.pdfResolution(),
556 m_modelMainWindow.importCropping(),
557 m_isErrorReportRegressionTest);
573 m_modelMainWindow.importCropping(),
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,
618 if ((m_cmdMediator->document().coordSystemCount() > 1) &&
619 ! m_actionViewCoordSystem->isChecked ()) {
622 m_actionViewCoordSystem->trigger ();
628 if (importType == IMPORT_TYPE_ADVANCED) {
638 m_originalFile = originalFileOld;
639 m_originalFileWasImported = originalFileWasImported;
645void 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);
662 ImportImageExtensions importImageExtensions;
665 str <<
"Image Files (" << supportedImageFormatStrings.join (
" ") <<
")";
669 str <<
";; All Files (*.*)";
671 MainDirectoryPersist directoryPersist;
672 QString fileName = QFileDialog::getOpenFileName (
this,
676 if (!fileName.isEmpty ()) {
681 fileImport (fileName,
687QString MainWindow::fileNameForExportOnly ()
const
689 ExportToFile exportStrategy;
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")
711QString MainWindow::fileNameForExtractImageOnly ()
const
714 QString dir = QFileInfo (m_currentFileWithPathAndFileExtension).absolutePath();
715 QString fileName = QString (
"%1/%2.%3")
718 .arg (m_extractImageOnlyExtension);
723void 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;
792void MainWindow::ghostsCreate ()
797 m_ghosts =
new Ghosts (m_cmdMediator->document().coordSystemIndex());
799 for (
unsigned int index = 0; index < m_cmdMediator->document().coordSystemCount(); index++) {
802 if (index != m_ghosts->coordSystemIndexToBeRestored ()) {
807 m_ghosts->captureGraphicsItems (*m_scene);
815 m_ghosts->createGhosts (*m_scene);
818void MainWindow::ghostsDestroy ()
824 m_ghosts->destroyGhosts(*m_scene);
830void MainWindow::handlerFileExtractImage ()
834 if (m_isExtractImageOnly) {
835 QString fileName = fileNameForExtractImageOnly ();
837 MainDirectoryPersist directoryPersist;
840 fileExtractImage(fileName);
846 return m_backgroundStateContext->imageForCurveState();
854void 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);
878void MainWindow::loadCurveListFromCmdMediator ()
882 m_cmbCurve->clear ();
883 QStringList curvesGraphsNames = m_cmdMediator->curvesGraphsNames ();
884 QStringList::iterator itr;
885 for (itr = curvesGraphsNames.begin (); itr != curvesGraphsNames.end (); itr++) {
887 QString curvesGraphName = *itr;
888 m_cmbCurve->addItem (curvesGraphName);
892 m_cmbCurve->setCurrentText (m_cmdMediator->selectedCurveName ());
895void 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 ())
946void 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);
965 m_cmdMediator =
new CmdMediator(*
this,
969 m_cmdStackShadow->loadCommands (*
this,
970 m_cmdMediator->document(),
974 setupAfterLoadNewDocument (errorReportFile,
975 tr (
"Error report opened"),
979 m_actionDigitizeSelect->setChecked (
true);
980 slotDigitizeSelect();
985bool 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,
1007bool 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);
1018 CmdMediator *
cmdMediator =
new CmdMediator (*
this,
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)) {
1040 ChecklistGuideWizard *wizard =
new ChecklistGuideWizard (*
this,
1041 m_cmdMediator->document().coordSystemCount());
1042 if (wizard->exec() == QDialog::Accepted) {
1044 for (
CoordSystemIndex coordSystemIndex = 0; coordSystemIndex < m_cmdMediator->document().coordSystemCount(); coordSystemIndex++) {
1047 m_dockChecklistGuide->setTemplateHtml (wizard->
templateHtml(coordSystemIndex),
1051 CurvesGraphs curvesGraphs;
1054 m_cmdMediator->document().setCurvesGraphs(curvesGraphs);
1058 m_actionViewChecklistGuide->setChecked (
true);
1061 loadCurveListFromCmdMediator();
1064 loadCoordSystemListFromCmdMediator();
1070 m_actionDigitizeAxis->setChecked (
true);
1074 slotDigitizeScale ();
1075 }
else if (modeGraph ()) {
1076 slotDigitizeAxis ();
1085bool MainWindow::loadImageReplacingImage (
const QString &fileName,
1086 const QImage &image,
1087 ImportType importType)
1090 <<
" fileName=" << fileName.toLatin1 ().data ()
1091 <<
" importType=" << importType;
1095 setCurrentPathFromFile (fileName);
1101 m_cmdMediator->document().setPixmap (image);
1103 bool accepted = setupAfterLoadReplacingImage (fileName,
1104 tr (
"File imported"),
1112void MainWindow::loadInputFileForErrorReport(QDomDocument &domInputFile)
const
1114 QFile file (m_originalFile);
1118 if (!file.open (QIODevice::ReadOnly)) {
1122 domInputFile.setContent (&file);
1126void 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 (
"");
1161bool MainWindow::modeGraph ()
const
1163 bool success =
false;
1165 if (m_cmdMediator !=
nullptr) {
1174 bool success =
false;
1176 if (m_cmdMediator !=
nullptr) {
1183bool 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
1207 DocumentModelExportFormat modelExportFormatAfter = modelExportFormatBefore;
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;
1237void 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);
1266bool 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>");
1288 m_cmdMediator->document().saveXml(writer);
1289 writer.writeEndDocument();
1290 QApplication::restoreOverrideCursor ();
1294 m_cmdMediator->setClean ();
1296 setCurrentFile(fileName);
1297 m_engaugeFile = fileName;
1299 m_statusBar->showTemporaryMessage(
"File saved");
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);
1339QString 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();
1450void MainWindow::saveStartingDocumentSnapshot()
1454 QXmlStreamWriter writer (&m_startingDocumentSnapshot);
1455 writer.setAutoFormatting (
true);
1456 m_cmdMediator->document().saveXml (writer);
1471 int index = m_cmbBackground->findData (backgroundImage);
1474 m_cmbBackground->setCurrentIndex(index);
1476 return previousBackground;
1481 return m_cmbCurve->currentText ();
1484void 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 ();
1503void MainWindow::setCurrentPathFromFile (
const QString &fileName)
1505 QDir dir = QFileInfo (fileName).absoluteDir();
1507 if (dir.exists ()) {
1509 bool success = QDir::setCurrent (dir.absolutePath ());
1518void MainWindow::setNonFillZoomFactor (
ZoomFactor newZoomFactor)
1523 m_zoomMapToAction [newZoomFactor]->setChecked (
true);
1524 slotViewZoomFactor (newZoomFactor);
1527void MainWindow::setPixmap (
const QString &curveSelected,
1528 const QPixmap &pixmap)
1532 m_digitizeStateContext->setImageIsLoaded (m_cmdMediator,
1537 m_backgroundStateContext->setPixmap (m_isGnuplot,
1539 m_cmdMediator->document().modelGridRemoval(),
1540 m_cmdMediator->document().modelColorFilter(),
1545void MainWindow::settingsRead (
bool isReset)
1554 settingsReadEnvironment (settings);
1555 settingsReadMainWindow (settings);
1558void MainWindow::settingsReadEnvironment (QSettings &settings)
1562 QDir::currentPath ()).toString ());
1563 settings.endGroup ();
1566void 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);
1628 m_statusBar->setStatusBarMode (statusBarMode);
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,
1661 m_modelMainWindow.setLocale (locale);
1686 MainDirectoryPersist directoryPersist;
1688 QVariant (QDir::currentPath())).toString ());
1690 QVariant (QDir::currentPath())).toString ());
1693 updateSmallDialogs();
1695 settings.endGroup();
1698void MainWindow::settingsWrite ()
1700 MainDirectoryPersist directoryPersist;
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 ();
1771bool 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);
1788 m_backgroundStateContext->setCurveSelected (m_isGnuplot,
1790 m_cmdMediator->document().modelGridRemoval(),
1791 m_cmdMediator->document().modelColorFilter(),
1792 EMPTY_CURVE_NAME_TO_SKIP_BACKGROUND_PROCESSING);
1793 setPixmap (m_cmdMediator->document().curvesGraphsNames().first(),
1794 m_cmdMediator->pixmap ());
1798 if (importType == IMPORT_TYPE_ADVANCED) {
1800 applyZoomFactorAfterLoad();
1802 DlgImportAdvanced dlgImportAdvanced (*
this);
1803 dlgImportAdvanced.exec();
1805 if (dlgImportAdvanced.result() == QDialog::Rejected) {
1809 int numberCoordSystem = signed (dlgImportAdvanced.numberCoordSystem());
1810 m_cmdMediator->document().addCoordSystems (
unsigned (numberCoordSystem - 1));
1811 m_cmdMediator->setDocumentAxesPointsRequired (dlgImportAdvanced.documentAxesPointsRequired());
1814 m_transformation.resetOnLoad();
1815 m_transformationStateContext->resetOnLoad();
1816 m_scene->resetOnLoad();
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;
1836 m_backgroundStateContext->setCurveSelected (m_isGnuplot,
1838 m_cmdMediator->document().modelGridRemoval(),
1839 m_cmdMediator->document().modelColorFilter(),
1840 m_cmbCurve->currentText ());
1841 m_backgroundStateContext->setBackgroundImage (
static_cast<BackgroundImage> (m_cmbBackground->currentIndex ()));
1843 applyZoomFactorAfterLoad();
1845 setCurrentFile(fileName);
1846 m_statusBar->showTemporaryMessage (temporaryMessage);
1847 m_statusBar->wakeUp ();
1849 saveStartingDocumentSnapshot();
1856bool 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();
1870 setPixmap (m_cmdMediator->document().curvesGraphsNames().first(),
1871 m_cmdMediator->pixmap ());
1873 m_isDocumentExported =
false;
1875 m_backgroundStateContext->setBackgroundImage (
static_cast<BackgroundImage> (m_cmbBackground->currentIndex ()));
1877 applyZoomFactorAfterLoad();
1880 if (m_modelMainWindow.imageReplaceRenamesDocument()) {
1881 setCurrentFile(fileName);
1884 m_statusBar->showTemporaryMessage (temporaryMessage);
1885 m_statusBar->wakeUp ();
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);
1913 m_statusBar->showTemporaryMessage (temporaryMessage);
1916void 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);
1933void MainWindow::slotBtnShowAllPressed ()
1941void MainWindow::slotBtnShowAllReleased ()
1949void MainWindow::slotCanRedoChanged (
bool canRedo)
1953 m_actionEditRedo->setEnabled (canRedo || m_cmdStackShadow->canRedo());
1956void MainWindow::slotCanUndoChanged (
bool canUndo)
1960 m_actionEditUndo->setEnabled (canUndo);
1963void MainWindow::slotChecklistClosed()
1967 m_actionViewChecklistGuide->setChecked (
false);
1970void MainWindow::slotCleanChanged(
bool clean)
1974 setWindowModified (!clean);
1977void 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));
2004void MainWindow::slotCmbCoordSystem(
int index)
2008 CmdSelectCoordSystem *cmd =
new CmdSelectCoordSystem (*
this,
2009 m_cmdMediator->document(),
2012 m_cmdMediator->push (cmd);
2015void MainWindow::slotCmbCurve(
int )
2019 m_backgroundStateContext->setCurveSelected (m_isGnuplot,
2021 m_cmdMediator->document().modelGridRemoval(),
2022 m_cmdMediator->document().modelColorFilter(),
2023 m_cmbCurve->currentText ());
2024 m_digitizeStateContext->handleCurveChange (m_cmdMediator);
2025 m_cmdMediator->setSelectedCurveName (m_cmbCurve->currentText ());
2027 updateViewedCurves();
2029 updateFittingWindow();
2030 updateGeometryWindow();
2033void MainWindow::slotContextMenuEventAxis (QString pointIdentifier)
2035 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotContextMenuEventAxis point=" << pointIdentifier.toLatin1 ().data ();
2037 m_digitizeStateContext->handleContextMenuEventAxis (m_cmdMediator,
2041void MainWindow::slotContextMenuEventGraph (QStringList pointIdentifiers)
2043 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotContextMenuEventGraph point=" << pointIdentifiers.join(
",").toLatin1 ().data ();
2045 m_digitizeStateContext->handleContextMenuEventGraph (m_cmdMediator,
2049void MainWindow::slotDigitizeAxis ()
2053 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2055 m_cmbCurve->setEnabled (
false);
2056 m_viewPointStyle->setEnabled (
true);
2057 m_viewSegmentFilter->setEnabled (
true);
2061void MainWindow::slotDigitizeColorPicker ()
2065 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2067 m_cmbCurve->setEnabled (
true);
2068 m_viewPointStyle->setEnabled (
true);
2069 m_viewSegmentFilter->setEnabled (
true);
2073void MainWindow::slotDigitizeCurve ()
2077 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2079 m_cmbCurve->setEnabled (
true);
2080 m_viewPointStyle->setEnabled (
true);
2081 m_viewSegmentFilter->setEnabled (
true);
2085void MainWindow::slotDigitizePointMatch ()
2089 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2091 m_cmbCurve->setEnabled (
true);
2092 m_viewPointStyle->setEnabled (
true);
2093 m_viewSegmentFilter->setEnabled (
true);
2097void MainWindow::slotDigitizeScale ()
2101 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2103 m_cmbCurve->setEnabled (
false);
2104 m_viewPointStyle->setEnabled (
false);
2105 m_viewSegmentFilter->setEnabled (
false);
2109void MainWindow::slotDigitizeSegment ()
2113 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2115 m_cmbCurve->setEnabled (
true);
2116 m_viewPointStyle->setEnabled (
true);
2117 m_viewSegmentFilter->setEnabled (
true);
2121void MainWindow::slotDigitizeSelect ()
2125 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2127 m_cmbCurve->setEnabled (
false);
2128 m_viewPointStyle->setEnabled (
false);
2129 m_viewSegmentFilter->setEnabled (
false);
2133void 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 ();
2156 GraphicsItemsExtractor graphicsItemsExtractor;
2157 const QList<QGraphicsItem*> &items = m_scene->selectedItems();
2160 CmdCopy *cmd =
new CmdCopy (*
this,
2161 m_cmdMediator->document(),
2163 m_digitizeStateContext->appendNewCmd (m_cmdMediator,
2168void 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) {
2185 GraphicsItemsExtractor graphicsItemsExtractor;
2186 const QList<QGraphicsItem*> &items = m_scene->selectedItems();
2189 CmdCut *cmd =
new CmdCut (*
this,
2190 m_cmdMediator->document(),
2192 m_digitizeStateContext->appendNewCmd (m_cmdMediator,
2197void 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) {
2216 ScaleBarAxisPointsUnite scaleBarAxisPoints;
2219 GraphicsItemsExtractor graphicsItemsExtractor;
2220 const QList<QGraphicsItem*> &items = m_scene->selectedItems();
2221 QStringList pointIdentifiers = scaleBarAxisPoints.
unite (m_cmdMediator,
2224 CmdDelete *cmd =
new CmdDelete (*
this,
2225 m_cmdMediator->document(),
2227 m_digitizeStateContext->appendNewCmd (m_cmdMediator,
2232void MainWindow::slotEditMenu ()
2236 m_actionEditPasteAsNew->setEnabled (!QApplication::clipboard()->image().isNull());
2237 m_actionEditPasteAsNewAdvanced->setEnabled (!QApplication::clipboard()->image().isNull());
2240void MainWindow::slotEditPaste ()
2244 QList<QPoint> points;
2245 QList<double> ordinals;
2247 MimePointsImport mimePointsImport;
2252 CmdAddPointsGraph *cmd =
new CmdAddPointsGraph (*
this,
2253 m_cmdMediator->document(),
2254 m_cmbCurve->currentText (),
2257 m_digitizeStateContext->appendNewCmd (m_cmdMediator,
2261void MainWindow::slotEditPasteAsNew ()
2265 filePaste (IMPORT_TYPE_SIMPLE);
2268void MainWindow::slotEditPasteAsNewAdvanced ()
2272 filePaste (IMPORT_TYPE_ADVANCED);
2275void MainWindow::slotFileClose()
2283 m_transformationStateContext->triggerStateTransition(m_isGnuplot,
2291 m_digitizeStateContext->requestImmediateStateTransition (m_cmdMediator,
2295 if (m_fittingCurve !=
nullptr) {
2296 m_scene->removeItem (m_fittingCurve);
2297 m_fittingCurve =
nullptr;
2301 m_scene->resetOnLoad ();
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();
2329void MainWindow::slotFileExport ()
2333 if (m_transformation.transformIsDefined()) {
2335 MainDirectoryPersist directoryPersist;
2336 ExportToFile exportStrategy;
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,
2369 DlgRequiresTransform dlg (
"Export");
2374void MainWindow::slotFileImport ()
2378 fileImportWithPrompts (IMPORT_TYPE_SIMPLE);
2381void MainWindow::slotFileImportAdvanced ()
2385 fileImportWithPrompts (IMPORT_TYPE_ADVANCED);
2388void MainWindow::slotFileImportDraggedImage(QImage image)
2395 IMPORT_TYPE_SIMPLE);
2398void MainWindow::slotFileImportDraggedImageUrl(QUrl url)
2400 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotFileImportDraggedImageUrl url=" << url.toString ().toLatin1 ().data ();
2404 m_loadImageFromUrl->startLoadImage (url);
2407void MainWindow::slotFileImportImage(QString fileName, QImage image)
2409 LOG4CPP_INFO_S ((*
mainCat)) <<
"MainWindow::slotFileImportImage fileName=" << fileName.toLatin1 ().data ();
2412 loadImage (fileName,
2414 IMPORT_TYPE_SIMPLE);
2417void MainWindow::slotFileImportImageReplace ()
2421 fileImportWithPrompts (IMPORT_TYPE_IMAGE_REPLACE);
2424void MainWindow::slotFileOpen()
2432 QString filter = QString (
"%1 (*.%2);; All Files (*.*)")
2433 .arg (ENGAUGE_FILENAME_DESCRIPTION)
2436 MainDirectoryPersist directoryPersist;
2437 QString fileName = QFileDialog::getOpenFileName (
this,
2438 tr(
"Open Document"),
2441 if (!fileName.isEmpty ()) {
2444 loadDocumentFile (fileName);
2450void MainWindow::slotFileOpenDraggedDigFile (QString fileName)
2454 loadDocumentFile (fileName);
2457void 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);
2470bool MainWindow::slotFileSave()
2474 if (m_engaugeFile.isEmpty()) {
2475 return slotFileSaveAs();
2477 return saveDocumentFile (m_engaugeFile);
2481bool 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;
2506 MainDirectoryPersist directoryPersist;
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));
2529void 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;
2551 m_fittingCurve =
new FittingCurve (fittingCurveCoef,
2557 m_fittingCurve->setVisible (m_actionViewFittingWindow->isChecked ());
2558 m_scene->addItem (m_fittingCurve);
2561void MainWindow::slotGeometryWindowClosed()
2565 m_actionViewGeometryWindow->setChecked (
false);
2568void MainWindow::slotHelpAbout()
2572 DlgAbout dlg (*
this);
2576void MainWindow::slotHelpTutorial()
2580 m_tutorialDlg->show ();
2581 m_tutorialDlg->exec ();
2584void MainWindow::slotKeyPress (Qt::Key key,
2585 bool atLeastOneSelectedItem)
2588 <<
" key=" << QKeySequence (key).toString().toLatin1 ().data ()
2589 <<
" atLeastOneSelectedItem=" << (atLeastOneSelectedItem ?
"true" :
"false");
2591 m_digitizeStateContext->handleKeyPress (m_cmdMediator,
2593 atLeastOneSelectedItem);
2596void MainWindow::slotLoadStartupFiles ()
2602 QString fileName = m_loadStartupFiles.front();
2603 m_loadStartupFiles.pop_front();
2606 LoadFileInfo loadFileInfo;
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);
2627void MainWindow::slotMouseMove (QPointF pos)
2632 if (m_cmdMediator !=
nullptr) {
2635 QString coordsScreen, coordsGraph, resolutionGraph;
2636 m_transformation.coordTextForStatusBar (pos,
2643 m_statusBar->setCoordinates (coordsScreen,
2650 m_digitizeStateContext->handleMouseMove (m_cmdMediator,
2655void MainWindow::slotMousePress (QPointF pos)
2659 m_scene->resetPositionHasChangedFlags();
2661 m_digitizeStateContext->handleMousePress (m_cmdMediator,
2665void MainWindow::slotMouseRelease (QPointF pos)
2669 if (pos.x() < 0 || pos.y() < 0) {
2678 m_digitizeStateContext->handleMouseRelease (m_cmdMediator,
2683void MainWindow::slotRecentFileAction ()
2687 QAction *action = qobject_cast<QAction*>(sender ());
2690 QString fileName = action->data().toString();
2691 loadDocumentFile (fileName);
2695void MainWindow::slotRecentFileClear ()
2699 QStringList emptyList;
2705 updateRecentFileList();
2708void MainWindow::slotRedoTextChanged (
const QString &text)
2712 QString completeText (
"Redo");
2713 if (!text.isEmpty ()) {
2714 completeText += QString (
" \"%1\"").arg (text);
2716 m_actionEditRedo->setText (completeText);
2719void MainWindow::slotSettingsAxesChecker ()
2723 m_dlgSettingsAxesChecker->load (*m_cmdMediator);
2724 m_dlgSettingsAxesChecker->show ();
2727void MainWindow::slotSettingsColorFilter ()
2731 m_dlgSettingsColorFilter->load (*m_cmdMediator);
2732 m_dlgSettingsColorFilter->show ();
2735void MainWindow::slotSettingsCoords ()
2739 m_dlgSettingsCoords->load (*m_cmdMediator);
2740 m_dlgSettingsCoords->show ();
2743void MainWindow::slotSettingsCurveList ()
2747 m_dlgSettingsCurveList->load (*m_cmdMediator);
2748 m_dlgSettingsCurveList->show ();
2751void MainWindow::slotSettingsCurveProperties ()
2755 m_dlgSettingsCurveProperties->load (*m_cmdMediator);
2757 m_dlgSettingsCurveProperties->show ();
2760void MainWindow::slotSettingsDigitizeCurve ()
2764 m_dlgSettingsDigitizeCurve->load (*m_cmdMediator);
2765 m_dlgSettingsDigitizeCurve->show ();
2768void MainWindow::slotSettingsExportFormat ()
2773 m_dlgSettingsExportFormat->load (*m_cmdMediator);
2774 m_dlgSettingsExportFormat->show ();
2776 DlgRequiresTransform dlg (
"Export settings");
2781void MainWindow::slotSettingsGeneral ()
2785 m_dlgSettingsGeneral->load (*m_cmdMediator);
2786 m_dlgSettingsGeneral->show ();
2789void MainWindow::slotSettingsGridDisplay()
2793 m_dlgSettingsGridDisplay->load (*m_cmdMediator);
2794 m_dlgSettingsGridDisplay->show ();
2797void MainWindow::slotSettingsGridRemoval ()
2801 m_dlgSettingsGridRemoval->load (*m_cmdMediator);
2802 m_dlgSettingsGridRemoval->show ();
2805void MainWindow::slotSettingsPointMatch ()
2809 m_dlgSettingsPointMatch->load (*m_cmdMediator);
2810 m_dlgSettingsPointMatch->show ();
2813void MainWindow::slotSettingsSegments ()
2817 m_dlgSettingsSegments->load (*m_cmdMediator);
2818 m_dlgSettingsSegments->show ();
2821void MainWindow::slotTableStatusChange ()
2830void MainWindow::slotSettingsMainWindow ()
2834 m_dlgSettingsMainWindow->loadMainWindowModel (*m_cmdMediator,
2836 m_dlgSettingsMainWindow->show ();
2839void MainWindow::slotTimeoutRegressionErrorReport ()
2842 <<
" cmdStackIndex=" << m_cmdMediator->index()
2843 <<
" cmdStackCount=" << m_cmdMediator->count();
2845 if (m_cmdStackShadow->canRedo()) {
2848 QDir::setCurrent (m_startupDirectory);
2850 m_cmdStackShadow->slotRedo();
2853 QDir::setCurrent (m_startupDirectory);
2857#if !defined(OSX_DEBUG) && !defined(OSX_RELEASE)
2858 exportAllCoordinateSystemsAfterRegressionTests ();
2862 m_cmdMediator->setClean();
2868void 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();
2902void MainWindow::slotUndoTextChanged (
const QString &text)
2906 QString completeText (
"Undo");
2907 if (!text.isEmpty ()) {
2908 completeText += QString (
" \"%1\"").arg (text);
2910 m_actionEditUndo->setText (completeText);
2913void MainWindow::slotViewGridLines ()
2920void 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);
2945 m_backgroundStateContext->setBackgroundImage (backgroundImage);
2948void MainWindow::slotViewGroupCurves(QAction * )
2952 updateViewedCurves ();
2955void MainWindow::slotViewGroupStatus(QAction *action)
2961 if (action == m_actionStatusNever) {
2963 }
else if (action == m_actionStatusTemporary) {
2970void MainWindow::slotViewToolBarBackground ()
2974 if (m_actionViewBackground->isChecked ()) {
2975 m_toolBackground->show();
2977 m_toolBackground->hide();
2981void MainWindow::slotViewToolBarChecklistGuide ()
2985 if (m_actionViewChecklistGuide->isChecked ()) {
2986 m_dockChecklistGuide->show();
2988 m_dockChecklistGuide->hide();
2992void MainWindow::slotViewToolBarCoordSystem ()
2996 if (m_actionViewCoordSystem->isChecked ()) {
2997 m_toolCoordSystem->show();
2999 m_toolCoordSystem->hide();
3003void MainWindow::slotViewToolBarDigitize ()
3007 if (m_actionViewDigitize->isChecked ()) {
3008 m_toolDigitize->show();
3010 m_toolDigitize->hide();
3014void 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);
3031void MainWindow::slotViewToolBarGeometryWindow ()
3035 if (m_actionViewGeometryWindow->isChecked ()) {
3036 m_dockGeometryWindow->show();
3038 m_dockGeometryWindow->hide();
3042void MainWindow::slotViewToolBarSettingsViews ()
3046 if (m_actionViewSettingsViews->isChecked ()) {
3047 m_toolSettingsViews->show();
3049 m_toolSettingsViews->hide();
3053void MainWindow::slotViewToolTips ()
3060void MainWindow::slotViewZoom (
int zoom)
3066 m_zoomMapToAction [zoomFactor]->setChecked (
true);
3067 slotViewZoomFactor (
static_cast<ZoomFactor> (zoom));
3070void MainWindow::slotViewZoomFactor (
ZoomFactor zoomFactor)
3075 m_backgroundStateContext->fitInView (*m_view);
3078 ZoomTransition zoomTransition;
3079 double factor = zoomTransition.
mapToFactor (zoomFactor);
3081 QTransform transform;
3082 transform.scale (factor, factor);
3083 m_view->setTransform (transform);
3089void MainWindow::slotViewZoomFactorInt (
int zoom)
3093 slotViewZoomFactor (
static_cast<ZoomFactor> (zoom));
3096void MainWindow::slotViewZoomIn ()
3100 ZoomTransition zoomTransition;
3102 m_view->transform ().m11 (),
3103 m_view->transform ().m22 (),
3104 m_actionZoomFill->isChecked ());
3105 setNonFillZoomFactor (zoomFactorNew);
3109void MainWindow::slotViewZoomInFromWheelEvent ()
3117 m_view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
3122 m_view->setTransformationAnchor(QGraphicsView::NoAnchor);
3126void MainWindow::slotViewZoomOut ()
3131 ZoomTransition zoomTransition;
3133 m_view->transform ().m11 (),
3134 m_view->transform ().m22 (),
3135 m_actionZoomFill->isChecked ());
3136 setNonFillZoomFactor (zoomFactorNew);
3139void MainWindow::slotViewZoomOutFromWheelEvent ()
3147 m_view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
3152 m_view->setTransformationAnchor(QGraphicsView::NoAnchor);
3156void 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";
3200void 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()));
3220void 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 ();
3254 m_digitizeStateContext->updateAfterPointAddition ();
3257 updateChecklistGuide ();
3258 updateFittingWindow ();
3259 updateGeometryWindow();
3264 writeCheckpointToLogFile ();
3266 docScrub.
check (*
this,
3267 m_cmdMediator->document ());
3271 m_view->setFocus ();
3274void 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()) {
3300 m_transformationStateContext->triggerStateTransition(m_isGnuplot,
3306 }
else if (m_transformation.transformIsDefined() && (m_transformationBefore != m_transformation)) {
3310 m_transformationStateContext->updateAxesChecker(*m_cmdMediator,
3315 QPoint posLocal = m_view->mapFromGlobal (QCursor::pos ()) - HACK_SO_GRAPH_COORDINATE_MATCHES_INPUT;
3316 QPointF posScreen = m_view->mapToScene (posLocal);
3318 slotMouseMove (posScreen);
3328void MainWindow::updateChecklistGuide ()
3332 m_dockChecklistGuide->
update (*m_cmdMediator,
3333 m_isDocumentExported);
3336void 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 ());
3385 if (m_transformation.transformIsDefined()) {
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 ());
3423 m_cmdMediator->document().setCoordSystemIndex (coordSystemIndex);
3424 loadCurveListFromCmdMediator ();
3426 updateTransformationAndItsDependencies();
3430 m_transformationStateContext->updateAxesChecker (*m_cmdMediator,
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();
3485void MainWindow::updateFittingWindow ()
3489 if (m_cmdMediator !=
nullptr &&
3490 m_cmbCurve !=
nullptr) {
3493 m_dockFittingWindow->
update (*m_cmdMediator,
3495 m_cmbCurve->currentText (),
3500void MainWindow::updateGeometryWindow ()
3504 if (m_cmdMediator !=
nullptr &&
3505 m_cmbCurve !=
nullptr) {
3508 m_dockGeometryWindow->update (*m_cmdMediator,
3510 m_cmbCurve->currentText (),
3519 m_scene->updateGraphicsLinesToMatchGraphicsPoints(m_cmdMediator->document().modelCurveStyles(),
3523void MainWindow::updateGridLines ()
3528 m_gridLines.
clear ();
3539 m_gridLines.
setVisible (m_actionViewGridLines->isChecked());
3542void MainWindow::updateHighlightOpacity ()
3544 if (m_cmdMediator !=
nullptr) {
3548 m_scene->updateAfterCommand (*m_cmdMediator,
3549 m_modelMainWindow.highlightOpacity(),
3550 m_dockGeometryWindow,
3555void 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);
3589 m_cmdMediator->document().setModelAxesChecker(modelAxesChecker);
3590 if (m_transformation.transformIsDefined()) {
3591 m_transformationStateContext->triggerStateTransition(m_isGnuplot,
3595 m_cmbCurve->currentText());
3597 m_transformationStateContext->triggerStateTransition(m_isGnuplot,
3601 m_cmbCurve->currentText());
3609 m_cmdMediator->document().setModelColorFilter(modelColorFilter);
3610 m_backgroundStateContext->updateColorFilter (m_isGnuplot,
3612 m_cmdMediator->document().modelGridRemoval(),
3614 m_cmbCurve->currentText());
3615 m_digitizeStateContext->handleCurveChange (m_cmdMediator);
3623 m_cmdMediator->document().setModelCoords(modelCoords);
3630 m_cmdMediator->document().setCurvesGraphs (curvesGraphs);
3631 loadCurveListFromCmdMediator();
3639 m_scene->updateCurveStyles(modelCurveStyles);
3640 m_cmdMediator->document().setModelCurveStyles(modelCurveStyles);
3648 m_cmdMediator->document().setModelDigitizeCurve(modelDigitizeCurve);
3649 m_digitizeStateContext->updateModelDigitizeCurve (m_cmdMediator,
3650 modelDigitizeCurve);
3657 m_cmdMediator->document().setModelExport (modelExport);
3664 m_cmdMediator->document().setModelGeneral(modelGeneral);
3671 m_cmdMediator->document().setModelGridDisplay(modelGridDisplay);
3679 m_cmdMediator->document().setModelGridRemoval(modelGridRemoval);
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)) {
3701 m_scene->updateCurveStyles(m_cmdMediator->document().modelCurveStyles());
3704 updateHighlightOpacity();
3705 updateWindowTitle();
3706 updateFittingWindow();
3707 updateGeometryWindow();
3722 m_cmdMediator->document().setModelPointMatch(modelPointMatch);
3729 m_cmdMediator->document().setModelSegments(modelSegments);
3730 m_digitizeStateContext->updateModelSegments(modelSegments);
3733void MainWindow::updateSmallDialogs ()
3750void MainWindow::updateTransformationAndItsDependencies()
3752 m_transformation.update (!m_currentFile.isEmpty (),
3757 m_backgroundStateContext->setCurveSelected (m_isGnuplot,
3759 m_cmdMediator->document().modelGridRemoval(),
3760 m_cmdMediator->document().modelColorFilter(),
3761 m_cmbCurve->currentText ());
3768void MainWindow::updateViewedCurves ()
3772 if (m_actionViewCurvesAll->isChecked ()) {
3774 m_scene->showCurves (
true,
true);
3776 }
else if (m_actionViewCurvesSelected->isChecked ()) {
3780 }
else if (m_actionViewCurvesNone->isChecked ()) {
3782 m_scene->showCurves (
false);
3793 QString activeCurve = m_digitizeStateContext->activeCurve ();
3800 if (activeCurve.isEmpty ()) {
3802 m_viewPointStyle->unsetPointStyle ();
3803 m_viewSegmentFilter->unsetColorFilterSettings ();
3808 PointStyle pointStyle = m_cmdMediator->document().modelCurveStyles().curveStyle(activeCurve).pointStyle();
3809 m_viewPointStyle->setPointStyle (pointStyle);
3811 ColorFilterSettings colorFilterSettings = m_cmdMediator->document().modelColorFilter().colorFilterSettings(activeCurve);
3812 m_viewSegmentFilter->setColorFilterSettings (colorFilterSettings,
3813 m_cmdMediator->pixmap ());
3818void 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);
3869void 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------------" ;
BackgroundImage
Background selection.
@ BACKGROUND_IMAGE_ORIGINAL
@ BACKGROUND_IMAGE_FILTERED
unsigned int CoordSystemIndex
Zero-based index for identifying CoordSystem instantiations.
DigitizeState
Set of possible states of Digitize toolbar.
@ DIGITIZE_STATE_POINT_MATCH
@ DIGITIZE_STATE_COLOR_PICKER
@ DOCUMENT_AXES_POINTS_REQUIRED_2
const QString DOCUMENT_SERIALIZE_ERROR
const QString DOCUMENT_SERIALIZE_APPLICATION
const QString DOCUMENT_SERIALIZE_ERROR_CONTEXT
const QString DOCUMENT_SERIALIZE_OPERATING_SYSTEM_WORD_SIZE
const QString DOCUMENT_SERIALIZE_FILE
const QString DOCUMENT_SERIALIZE_ERROR_COMMENT
const QString DOCUMENT_SERIALIZE_IMAGE
const QString DOCUMENT_SERIALIZE_IMAGE_HEIGHT
const QString DOCUMENT_SERIALIZE_ERROR_LINE
const QString DOCUMENT_SERIALIZE_IMAGE_WIDTH
const QString DOCUMENT_SERIALIZE_ERROR_FILE
const QString DOCUMENT_SERIALIZE_DOCUMENT
const QString DOCUMENT_SERIALIZE_OPERATING_SYSTEM_ENDIAN
const QString DOCUMENT_SERIALIZE_APPLICATION_VERSION_NUMBER
const QString DOCUMENT_SERIALIZE_FILE_IMPORTED
const QString DOCUMENT_SERIALIZE_OPERATING_SYSTEM
const QString DOCUMENT_SERIALIZE_ERROR_REPORT
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
#define ENGAUGE_CHECK_PTR(ptr)
#endif
QString EndianToString(QSysInfo::Endian endian)
QVector< double > FittingCurveCoefficients
Coefficients x0, x1, ... in y = a0 + a1 * x + a2 * x^2 + ...
const double DEFAULT_HIGHLIGHT_OPACITY
const int DEFAULT_MAXIMUM_GRID_LINES
Default for maximum number of grid lines.
const ImportCropping DEFAULT_IMPORT_CROPPING
log4cpp::Category * mainCat
const QString INDENTATION_PAST_TIMESTAMP
MainTitleBarFormat
Format format in MainWindow title bar.
@ MAIN_TITLE_BAR_FORMAT_NO_PATH
@ MAIN_TITLE_BAR_FORMAT_PATH
Filename without path.
bool DEFAULT_DRAG_DROP_EXPORT
bool DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT
int DEFAULT_SIGNIFICANT_DIGITS
bool DEFAULT_SMALL_DIALOGS
const int REGRESSION_INTERVAL
const unsigned int MAX_RECENT_FILE_LIST_SIZE
const QString ENGAUGE_FILENAME_EXTENSION("dig")
const QString EMPTY_FILENAME("")
const unsigned int MAX_RECENT_FILE_LIST_SIZE
NonPdfReturn
Return values from load operation.
@ NON_PDF_RETURN_CANCELED
int DEFAULT_IMPORT_PDF_RESOLUTION
PdfReturn
Return values from load operation.
const QString SETTINGS_ZOOM_FACTOR
const QString SETTINGS_SMALL_DIALOGS
const QString SETTINGS_IMPORT_PDF_RESOLUTION
const QString SETTINGS_ENGAUGE
const QString SETTINGS_CHECKLIST_GUIDE_DOCK_AREA
const QString SETTINGS_FITTING_WINDOW_DOCK_AREA
const QString SETTINGS_MAIN_TITLE_BAR_FORMAT
const QString SETTINGS_MAIN_DIRECTORY_EXPORT_SAVE
const QString SETTINGS_MAXIMUM_GRID_LINES
const QString SETTINGS_IMAGE_REPLACE_RENAMES_DOCUMENT
const QString SETTINGS_MAIN_DIRECTORY_IMPORT_LOAD
const QString SETTINGS_GROUP_ENVIRONMENT
const QString SETTINGS_HELP_SIZE
const QString SETTINGS_HIGHLIGHT_OPACITY
const QString SETTINGS_CHECKLIST_GUIDE_DOCK_GEOMETRY
const QString SETTINGS_LOCALE_LANGUAGE
const QString SETTINGS_SIZE
const QString SETTINGS_IMPORT_CROPPING
const QString SETTINGS_RECENT_FILE_LIST
const QString SETTINGS_HELP_POS
const QString SETTINGS_VIEW_COORD_SYSTEM_TOOLBAR
const QString SETTINGS_VIEW_DIGITIZE_TOOLBAR
const QString SETTINGS_ZOOM_FACTOR_INITIAL
const QString SETTINGS_SIGNIFICANT_DIGITS
const QString SETTINGS_VIEW_BACKGROUND_TOOLBAR
const QString SETTINGS_VIEW_SETTINGS_VIEWS_TOOLBAR
const QString SETTINGS_CHECKLIST_GUIDE_WIZARD
const QString SETTINGS_DRAG_DROP_EXPORT
const QString SETTINGS_VIEW_STATUS_BAR
const QString SETTINGS_ZOOM_CONTROL
const QString SETTINGS_GROUP_MAIN_WINDOW
const QString SETTINGS_VIEW_TOOL_TIPS
const QString SETTINGS_BACKGROUND_IMAGE
const QString SETTINGS_GEOMETRY_WINDOW_DOCK_GEOMETRY
const QString SETTINGS_POS
const QString SETTINGS_DIGITIZER
const QString SETTINGS_CURRENT_DIRECTORY
const QString SETTINGS_FITTING_WINDOW_DOCK_GEOMETRY
const QString SETTINGS_LOCALE_COUNTRY
const QString SETTINGS_GEOMETRY_WINDOW_DOCK_AREA
@ STATUS_BAR_MODE_TEMPORARY
QString engaugeWindowTitle()
Text for title bars of dialogs.
const char * VERSION_NUMBER
@ ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS
@ ZOOM_CONTROL_MENU_WHEEL
const ZoomFactorInitial DEFAULT_ZOOM_FACTOR_INITIAL
ZoomFactor
Zoom factors ordered by zoom level so next one above/below is the next zoom level.
QStringList curveNames(CoordSystemIndex coordSystemIndex) const
Curve names to be placed into Document.
QString templateHtml(CoordSystemIndex coordSystemIndex) const
Template html comprising the checklist for display.
void populateCurvesGraphs(CoordSystemIndex coordSystemIndex, CurvesGraphs &curvesGraphs)
Create entries in CurvesGraphs for each curve name that user provided.
void update(const CmdMediator &cmdMediator, bool documentIsExported)
Update using current CmdMediator/Document state.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
void create(MainWindow &mw)
Create QAction facade.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Container for all graph curves. The axes point curve is external to this class.
Dialog for saving error report for later transmission to the developers.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
Model for DlgSettingsAxesChecker and CmdSettingsAxesChecker.
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
Model for DlgSettingsCoords and CmdSettingsCoords.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
Model for DlgSettingsSegments and CmdSettingsSegments.
void check(MainWindow &mainWindow, const Document &document) const
Check document state.
unsigned int coordSystemCount() const
Number of CoordSystem.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
DocumentModelGridDisplay modelGridDisplay() const
Get method for DocumentModelGridDisplay.
Class for exporting during regression, when the Transformation has not yet been defined.
Strategy class for exporting to a file. This strategy is external to the Document class so that class...
QString filterTsv() const
QFileDialog filter for TSV files.
QString filterCsv() const
QFileDialog filter for CSV files.
void exportToFile(const DocumentModelExportFormat &modelExport, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.
QString fileExtensionTsv() const
File extension for tsv export files.
QString fileExtensionCsv() const
File extension for csv export files.
File that manages a command stack for regression testing of file import/open/export/close.
virtual void update(const CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow, const QString &curveSelected, const Transformation &transformation)
Populate the table with the specified Curve.
Add point and line handling to generic QGraphicsScene.
void printStream(QString indentation, QTextStream &str)
Debugging method that supports print method of this class and printStream method of some other class(...
QGraphicsView class with event handling added. Typically the events are sent to the active digitizing...
Factory class for generating the points, composed of QGraphicsItem objects, along a GridLine.
void setVisible(bool visible)
Make all grid lines visible or hidden.
void clear()
Deallocate and remove all grid lines.
QStringList fileExtensionsWithAsterisks() const
File extensions for use in file dialogs.
bool load(const QString &filename, QImage &image) const
Load image from jpeg2000 file.
bool loadsAsDigFile(const QString &urlString) const
Returns true if specified file name can be loaded as a DIG file.
static void bindToMainWindow(MainWindow *mainWindow)
Bind to MainWindow so this class can access the command stack.
void setDirectoryExportSaveFromSavedPath(const QString &path)
Set the current Export/Save directory at startup to path from previous execution.
void setDirectoryImportOpenFromFilename(const QString &fileName)
Save the current Import/Open directory, after user has accepted the Import/Open dialog.
void setDirectoryExportSaveFromFilename(const QString &fileName)
Save the current Export/Save directory, after user has accepted the Export/Save dialog.
QDir getDirectoryImportOpen() const
Get the current Import/Open directory.
void setDirectoryImportLoadFromSavedPath(const QString &path)
Set the current Import/Open directory at startup to path from previous execution.
QDir getDirectoryExportSave() const
Get the current Export/Save directory.
Model for DlgSettingsMainWindow.
bool smallDialogs() const
Get method for small dialogs flag.
ZoomControl zoomControl() const
Get method for zoom control.
MainTitleBarFormat mainTitleBarFormat() const
Get method for MainWindow titlebar filename format.
void saveErrorReportFileAndExit(const char *comment, const char *file, int line, const char *context)
Save error report and exit.
void updateSettingsGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
Update with new grid removal properties.
void showTemporaryMessage(const QString &temporaryMessage)
Show temporary message in status bar.
CmdMediator * cmdMediator()
Accessor for commands to process the Document.
void updateSettingsGridDisplay(const DocumentModelGridDisplay &modelGridDisplay)
Update with new grid display properties.
virtual bool eventFilter(QObject *, QEvent *)
Catch secret keypresses.
void updateSettingsAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
Update with new axes indicator properties.
virtual void showEvent(QShowEvent *)
Processing performed after gui becomes available.
void updateSettingsDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update with new curve digitization styles.
bool isGnuplot() const
Get method for gnuplot flag.
void updateSettingsCurveStyles(const CurveStyles &modelCurveStyles)
Update with new curve styles.
bool transformIsDefined() const
Return true if all three axis points have been defined.
MainWindowModel modelMainWindow() const
Get method for main window model.
void cmdFileOpen(const QString &fileName)
Open file. This is called from a file script command.
void updateSettingsCurveList(const CurvesGraphs &curvesGraphs)
Update with new curves.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
void updateSettingsExportFormat(const DocumentModelExportFormat &modelExport)
Update with new export properties.
void updateSettingsSegments(const DocumentModelSegments &modelSegments)
Update with new segments properties.
BackgroundImage selectOriginal(BackgroundImage backgroundImage)
Make original background visible, for DigitizeStateColorPicker.
void cmdFileExport(const QString &fileName)
Export file. This is called from a file script command.
friend class CreateFacade
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
void updateSettingsMainWindow(const MainWindowModel &modelMainWindow)
Update with new main window properties.
void cmdFileClose()
Close file. This is called from a file script command.
void updateDigitizeStateIfSoftwareTriggered(DigitizeState digitizeState)
After software-triggered state transition, this method manually triggers the action as if user had cl...
bool modeMap() const
True if document scale is set using a scale bar, otherwise using axis points.
void signalDropRegression(QString)
Send drag and drop regression test url.
void updateSettingsGeneral(const DocumentModelGeneral &modelGeneral)
Update with new general properties.
void signalZoom(int)
Send zoom selection, picked from menu or keystroke, to StatusBar.
void updateSettingsPointMatch(const DocumentModelPointMatch &modelPointMatch)
Update with new point match properties.
MainWindow(const QString &errorReportFile, const QString &fileCmdScriptFile, bool isDropRegression, bool isRegressionTest, bool isGnuplot, bool isReset, bool isExportOnly, bool isExtractImageOnly, const QString &extractImageOnlyExtension, const QStringList &loadStartupFiles, const QStringList &commandLineWithoutLoadStartupFiles, QWidget *parent=nullptr)
Single constructor.
void cmdFileImport(const QString &fileName)
Import file. This is called from a file script command.
void updateGraphicsLinesToMatchGraphicsPoints()
Update the graphics lines so they follow the graphics points, after a drag, addition,...
QImage imageFiltered() const
Background image that has been filtered for the current curve. This asserts if a curve-specific image...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
void updateAfterMouseRelease()
Call MainWindow::updateControls (which is private) after the very specific case - a mouse press/relea...
void resizeEvent(QResizeEvent *event)
Intercept resize event so graphics scene can be appropriately resized when in Fill mode.
Transformation transformation() const
Return read-only copy of transformation.
void updateSettingsColorFilter(const DocumentModelColorFilter &modelColorFilter)
Update with new color filter properties.
void updateCoordSystem(CoordSystemIndex coordSystemIndex)
Select a different CoordSystem.
void updateSettingsCoords(const DocumentModelCoords &modelCoords)
Update with new coordinate properties.
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
void retrievePoints(const Transformation &transformation, QList< QPoint > &points, QList< double > &ordinals) const
Retrieve points from clipboard.
NonPdfReturn load(const QString &fileName, QImage &image, ImportCropping importCropping, bool isErrorReportRegressionTest) const
Try to load the specified file. Success is indicated in the function return value.
PdfReturn load(const QString &fileName, QImage &image, int resolution, ImportCropping importCropping, bool isErrorReportRegressionTest) const
Try to load the specified file. Success is indicated in the function return value.
Details for a specific Point.
static void setIdentifierIndex(unsigned int identifierIndex)
Reset the current index while performing a Redo.
QStringList unite(CmdMediator *cmdMediator, const QStringList &pointIdentifiersIn) const
Add.
void triggerStateTransition(bool isGnuplot, TransformationState transformationState, CmdMediator &cmdMediator, const Transformation &transformation, const QString &selectedGraphCurve)
Trigger a state transition to be performed immediately.
double mapToFactor(ZoomFactor zoomFactor) const
Return the floating precision zoom factor given the enum value.
ZoomFactor zoomOut(ZoomFactor currentZoomFactor, double m11, double m22, bool actionZoomFillIsChecked) const
Zoom out.
ZoomFactor zoomIn(ZoomFactor currentZoomFactor, double m11, double m22, bool actionZoomFillIsChecked) const
Zoom in.
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)
#define LOG4CPP_ERROR_S(logger)