Skip to content

Commit

Permalink
File can be specified in command line for import or opening at startu…
Browse files Browse the repository at this point in the history
…p for issue #34
  • Loading branch information
markummitchell-tu committed Nov 7, 2015
1 parent 2c2171e commit 288e557
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 36 deletions.
4 changes: 2 additions & 2 deletions dev/engauge.pro.user.mmitchell.linux
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2015-10-29T23:53:44. -->
<!-- Written by QtCreator 3.0.1, 2015-11-07T15:23:58. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
Expand Down Expand Up @@ -230,7 +230,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">engauge</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/mark/engauge6/engauge.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-debug</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-debug ../samples/gridlines.gif</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">engauge.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
Expand Down
2 changes: 2 additions & 0 deletions engauge.pro
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ HEADERS += \
src/Help/HelpBrowser.h \
src/Help/HelpWindow.h \
src/Line/LineStyle.h \
src/Load/LoadFileInfo.h \
src/Load/LoadImageFromUrl.h \
src/Logger/Logger.h \
src/Logger/LoggerUpload.h \
Expand Down Expand Up @@ -438,6 +439,7 @@ SOURCES += \
src/Help/HelpBrowser.cpp \
src/Help/HelpWindow.cpp \
src/Line/LineStyle.cpp \
src/Load/LoadFileInfo.cpp \
src/Load/LoadImageFromUrl.cpp \
src/Logger/Logger.cpp \
src/Logger/LoggerUpload.cpp \
Expand Down
34 changes: 15 additions & 19 deletions src/Graphics/GraphicsView.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "DataKey.h"
#include "Document.h"
#include "GraphicsItemType.h"
#include "GraphicsView.h"
#include "LoadFileInfo.h"
#include "Logger.h"
#include "MainWindow.h"
#include "Point.h"
Expand Down Expand Up @@ -104,13 +104,8 @@ void GraphicsView::dragMoveEvent (QDragMoveEvent *event)

void GraphicsView::dropEvent (QDropEvent *event)
{
LOG4CPP_INFO_S ((*mainCat)) << "GraphicsView::dropEvent"
<< " formats=" << event->mimeData()->formats().join (", ").toLatin1().data();

const QString MIME_FORMAT_TEXT_PLAIN ("text/plain");

// This code is not specific to a digitizing state so it is implemented here

// Urls from text/uri-list
QList<QUrl> urlList = event->mimeData ()->urls ();
QString urls;
Expand All @@ -121,10 +116,21 @@ void GraphicsView::dropEvent (QDropEvent *event)
str << " url=" << url.toString () << " ";
}

if (loadsAsDigFile (event->mimeData()->data (MIME_FORMAT_TEXT_PLAIN))) {
QString textPlain (event->mimeData()->data (MIME_FORMAT_TEXT_PLAIN));

LOG4CPP_INFO_S ((*mainCat)) << "GraphicsView::dropEvent"
<< " formats=(" << event->mimeData()->formats().join (", ").toLatin1().data() << ")"
<< " hasUrls=" << (event->mimeData()->hasUrls() ? "yes" : "no")
<< " urlCount=" << urlList.count()
<< " urls=(" << urls.toLatin1().data() << ")"
<< " text=" << textPlain.toLatin1().data()
<< " hasImage=" << (event->mimeData()->hasImage() ? "yes" : "no");

LoadFileInfo loadFileInfo;
if (loadFileInfo.loadsAsDigFile (textPlain)) {

LOG4CPP_INFO_S ((*mainCat)) << "QGraphicsView::dropEvent dig file";
QUrl url (event->mimeData()->data(MIME_FORMAT_TEXT_PLAIN));
QUrl url (textPlain);
emit signalDraggedDigFile (url.toLocalFile());
event->acceptProposedAction();

Expand All @@ -136,7 +142,7 @@ void GraphicsView::dropEvent (QDropEvent *event)
emit signalDraggedImage (image);

} else if (event->mimeData ()->hasUrls () &&
event->mimeData ()->urls().count () > 0) {
urlList.count () > 0) {

// Sometimes images can be dragged in, but sometimes the url points to an html page that
// contains just the image, in which case importing will fail
Expand Down Expand Up @@ -196,16 +202,6 @@ void GraphicsView::leaveEvent (QEvent *event)
QGraphicsView::leaveEvent (event);
}

bool GraphicsView::loadsAsDigFile (const QString &urlString) const
{
LOG4CPP_INFO_S ((*mainCat)) << "GraphicsView::loadsAsDigFile";

QUrl url (urlString);
Document document (url.toLocalFile());

return document.successfulRead();
}

void GraphicsView::mouseMoveEvent (QMouseEvent *event)
{
// LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsView::mouseMoveEvent cursor="
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/GraphicsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class GraphicsView : public QGraphicsView
GraphicsView();

bool inBounds (const QPointF &posScreen);
bool loadsAsDigFile (const QString &urlString) const;

};

#endif // GRAPHICSVIEW_H
28 changes: 28 additions & 0 deletions src/Load/LoadFileInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "Document.h"
#include "LoadFileInfo.h"
#include "Logger.h"
#include <QUrl>

LoadFileInfo::LoadFileInfo()
{
}

LoadFileInfo::~LoadFileInfo()
{
}

bool LoadFileInfo::loadsAsDigFile (const QString &urlString) const
{
LOG4CPP_INFO_S ((*mainCat)) << "LoadFileInfo::loadsAsDigFile";

QString fileName = urlString;

QUrl url (urlString);
if (url.isLocalFile ()) {
fileName = url.toLocalFile();
}

Document document (fileName);

return document.successfulRead();
}
19 changes: 19 additions & 0 deletions src/Load/LoadFileInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef LOAD_FILE_INFO_H
#define LOAD_FILE_INFO_H

#include <QString>

/// Returns information about files
class LoadFileInfo
{
public:
/// Single constructor.
LoadFileInfo();
virtual ~LoadFileInfo();

/// Returns true if specified file name can be loaded as a DIG file
bool loadsAsDigFile (const QString &urlString) const;

};

#endif // LOAD_FILE_INFO_H
4 changes: 3 additions & 1 deletion src/Test/TestCorrelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ void TestCorrelation::initTestCase ()
const QString NO_ERROR_REPORT_LOG_FILE;
const bool NO_GNUPLOT_LOG_FILES = false;
const bool DEBUG_FLAG = false;
const QStringList NO_LOAD_STARTUP_FILES;

initializeLogging ("engauge_test",
"engauge_test.log",
DEBUG_FLAG);

MainWindow w (NO_ERROR_REPORT_LOG_FILE,
NO_GNUPLOT_LOG_FILES);
NO_GNUPLOT_LOG_FILES,
NO_LOAD_STARTUP_FILES);
w.show ();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Test/TestFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ void TestFormats::initTestCase ()
const QString NO_ERROR_REPORT_LOG_FILE;
const bool NO_GNUPLOT_LOG_FILES = false;
const bool DEBUG_FLAG = false;
const QStringList NO_LOAD_STARTUP_FILES;

initializeLogging ("engauge_test",
"engauge_test.log",
DEBUG_FLAG);

MainWindow w (NO_ERROR_REPORT_LOG_FILE,
NO_GNUPLOT_LOG_FILES);
NO_GNUPLOT_LOG_FILES,
NO_LOAD_STARTUP_FILES);
w.show ();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Test/TestGraphCoords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ void TestGraphCoords::initTestCase ()
const QString NO_ERROR_REPORT_LOG_FILE;
const bool NO_GNUPLOT_LOG_FILES = false;
const bool DEBUG_FLAG = false;
const QStringList NO_LOAD_STARTUP_FILES;

initializeLogging ("engauge_test",
"engauge_test.log",
DEBUG_FLAG);

MainWindow w (NO_ERROR_REPORT_LOG_FILE,
NO_GNUPLOT_LOG_FILES);
NO_GNUPLOT_LOG_FILES,
NO_LOAD_STARTUP_FILES);
w.show ();
}

Expand Down
5 changes: 4 additions & 1 deletion src/Test/TestProjectedPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ void TestProjectedPoint::initTestCase ()
const QString NO_ERROR_REPORT_LOG_FILE;
const bool NO_GNUPLOT_LOG_FILES = false;
const bool DEBUG_FLAG = false;
const QStringList NO_LOAD_STARTUP_FILES;

initializeLogging ("engauge_test",
"engauge_test.log",
DEBUG_FLAG);

MainWindow w (NO_ERROR_REPORT_LOG_FILE,
NO_GNUPLOT_LOG_FILES);
NO_GNUPLOT_LOG_FILES,
NO_LOAD_STARTUP_FILES);
w.show ();
}

Expand Down
5 changes: 4 additions & 1 deletion src/Test/TestSpline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ void TestSpline::initTestCase ()
const QString NO_ERROR_REPORT_LOG_FILE;
const bool NO_GNUPLOT_LOG_FILES = false;
const bool DEBUG_FLAG = false;
const QStringList NO_LOAD_STARTUP_FILES;

initializeLogging ("engauge_test",
"engauge_test.log",
DEBUG_FLAG);

MainWindow w (NO_ERROR_REPORT_LOG_FILE,
NO_GNUPLOT_LOG_FILES);
NO_GNUPLOT_LOG_FILES,
NO_LOAD_STARTUP_FILES);
w.show ();
}

Expand Down
5 changes: 4 additions & 1 deletion src/Test/TestTransformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ void TestTransformation::initTestCase ()
const QString NO_ERROR_REPORT_LOG_FILE;
const bool NO_GNUPLOT_LOG_FILES = false;
const bool DEBUG_FLAG = false;
const QStringList NO_LOAD_STARTUP_FILES;

initializeLogging ("engauge_test",
"engauge_test.log",
DEBUG_FLAG);

MainWindow w (NO_ERROR_REPORT_LOG_FILE,
NO_GNUPLOT_LOG_FILES);
NO_GNUPLOT_LOG_FILES,
NO_LOAD_STARTUP_FILES);
w.show ();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Test/TestValidators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ void TestValidators::initTestCase ()
const QString NO_ERROR_REPORT_LOG_FILE;
const bool NO_GNUPLOT_LOG_FILES = false;
const bool DEBUG_FLAG = false;
const QStringList NO_LOAD_STARTUP_FILES;

initializeLogging ("engauge_test",
"engauge_test.log",
DEBUG_FLAG);

MainWindow w (NO_ERROR_REPORT_LOG_FILE,
NO_GNUPLOT_LOG_FILES);
NO_GNUPLOT_LOG_FILES,
NO_LOAD_STARTUP_FILES);
w.show ();
}

Expand Down
2 changes: 2 additions & 0 deletions src/engauge_test_template.pro
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ HEADERS += \
Help/HelpBrowser.h \
Help/HelpWindow.h \
Line/LineStyle.h \
Load/LoadFileInfo.h \
Load/LoadImageFromUrl.h \
Logger/Logger.h \
Logger/LoggerUpload.h \
Expand Down Expand Up @@ -423,6 +424,7 @@ SOURCES += \
Help/HelpBrowser.cpp \
Help/HelpWindow.cpp \
Line/LineStyle.cpp \
Load/LoadFileInfo.cpp \
Load/LoadImageFromUrl.cpp \
Logger/Logger.cpp \
Logger/LoggerUpload.cpp \
Expand Down
46 changes: 46 additions & 0 deletions src/main/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#ifdef ENGAUGE_JPEG2000
#include "Jpeg2000.h"
#endif // ENGAUGE_JPEG2000
#include "LoadFileInfo.h"
#include "LoadImageFromUrl.h"
#include "Logger.h"
#include "MainWindow.h"
Expand Down Expand Up @@ -75,6 +76,7 @@
#include <QSettings>
#include <QTextStream>
#include <QtHelp>
#include <QTimer>
#include <QToolBar>
#include <QToolButton>
#include "QtToString.h"
Expand Down Expand Up @@ -109,6 +111,7 @@ const unsigned int MAX_RECENT_FILE_LIST_SIZE = 8;

MainWindow::MainWindow(const QString &errorReportFile,
bool isGnuplot,
QStringList loadStartupFiles,
QWidget *parent) :
QMainWindow(parent),
m_isDocumentExported (false),
Expand Down Expand Up @@ -157,6 +160,11 @@ MainWindow::MainWindow(const QString &errorReportFile,
if (!errorReportFile.isEmpty()) {
loadErrorReportFile(initialPath,
errorReportFile);
} else {

// Save file names for later, after gui becomes available. The file names are dropped if error report file is specified
// since only one of the two modes is available at any time, for simplicity
m_loadStartupFiles = loadStartupFiles;
}
}

Expand Down Expand Up @@ -1807,6 +1815,23 @@ void MainWindow::setupAfterLoad (const QString &fileName,
updateAfterCommand(); // Replace stale points by points in new Document
}

void MainWindow::showEvent (QShowEvent *event)
{
LOG4CPP_INFO_S ((*mainCat)) << "MainWindow::showEvent"
<< " files=" << m_loadStartupFiles.join (",").toLatin1().data();

QMainWindow::showEvent (event);

if (m_loadStartupFiles.count() > 0) {

m_timerLoadStartupFiles = new QTimer;
m_timerLoadStartupFiles->setSingleShot (true);
connect (m_timerLoadStartupFiles, SIGNAL (timeout ()), this, SLOT (slotLoadStartupFiles ()));
m_timerLoadStartupFiles->start (0); // Zero delay still waits until execution finishes and gui is available

}
}

void MainWindow::showTemporaryMessage (const QString &temporaryMessage)
{
m_statusBar->showTemporaryMessage (temporaryMessage);
Expand Down Expand Up @@ -2264,6 +2289,27 @@ void MainWindow::slotLeave ()
m_digitizeStateContext->handleLeave ();
}

void MainWindow::slotLoadStartupFiles ()
{
LOG4CPP_INFO_S ((*mainCat)) << "MainWindow::slotLoadStartupFiles";

ENGAUGE_ASSERT (m_loadStartupFiles.count() > 0);

QString fileName = m_loadStartupFiles [0];

// Load next file into this instance of Engauge
LoadFileInfo loadFileInfo;
if (loadFileInfo.loadsAsDigFile(fileName)) {

loadDocumentFile (fileName);

} else {

fileImport (fileName);

}
}

void MainWindow::slotMouseMove (QPointF pos)
{
// LOG4CPP_DEBUG_S ((*mainCat)) << "MainWindow::slotMouseMove pos=" << QPointFToString (pos).toLatin1 ().data ();
Expand Down
Loading

0 comments on commit 288e557

Please sign in to comment.