Skip to content

Commit

Permalink
Force import project
Browse files Browse the repository at this point in the history
new commandline option -f/--force allows to open lpr file without warning
  • Loading branch information
xhpohanka committed May 24, 2020
1 parent 6d1a643 commit 4d87159
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/core/MainController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <string>

MainController::MainController(QQmlApplicationEngine& qmlEngine, QString templateFile, QObject* parent)
MainController::MainController(QQmlApplicationEngine& qmlEngine, QString templateFile, bool forceImport, QObject* parent)
: QObject(parent)
, m_guiManager(this, qmlEngine)
, m_logManager(this)
Expand Down Expand Up @@ -44,6 +44,7 @@ MainController::MainController(QQmlApplicationEngine& qmlEngine, QString templat
, m_developerMode(false)
, m_clickSounds(false)
, m_templateFileToImport(templateFile)
, m_forceImport(forceImport)
{
// print Qt Version to verify that the right library is loaded:
qInfo() << "Compiled with Qt Version" << QT_VERSION_STR;
Expand Down Expand Up @@ -193,7 +194,11 @@ void MainController::restoreApp() {
m_projectManager.setCurrentProject("empty", /*createIfNotExist*/ true);
} else if (appState["version"].toDouble() < 0.3) {
onFirstStart();
} else {
} else if (m_templateFileToImport.length() > 0 && m_forceImport) {
m_projectManager.importProjectFile(m_templateFileToImport, true);
m_guiManager.closeTutorialView();
}
else {
m_projectManager.setCurrentProject(appState["currentProject"].toString());
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/core/MainController.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MainController : public QObject
Q_PROPERTY(bool developerMode READ getDeveloperMode WRITE setDeveloperMode NOTIFY developerModeChanged)
Q_PROPERTY(bool clickSounds READ getClickSounds WRITE setClickSounds NOTIFY clickSoundsChanged)
Q_PROPERTY(QString templateFileToImport READ getTemplateFileBaseName NOTIFY templateFileToImportChanged)
Q_PROPERTY(bool forceImport READ getForceImport NOTIFY forceImportChanged)

public:

Expand All @@ -70,7 +71,8 @@ class MainController : public QObject
* @param qmlEngine is the QML enigne to use to create the GUI
* @param parent the QObject parent
*/
explicit MainController(QQmlApplicationEngine& qmlEngine, QString templateFile, QObject *parent = nullptr);
explicit MainController(QQmlApplicationEngine& qmlEngine, QString templateFile,
bool forceImport = false, QObject *parent = nullptr);


signals:
Expand All @@ -85,6 +87,8 @@ class MainController : public QObject

void templateFileToImportChanged();

void forceImportChanged();


public slots:

Expand Down Expand Up @@ -278,6 +282,8 @@ public slots:
bool getClickSounds() const { return m_clickSounds; }
void setClickSounds(bool value) { m_clickSounds = value; emit clickSoundsChanged(); }

bool getForceImport() const { return m_forceImport; }

QString getTemplateFileBaseName() const;
void requestTemplateImport(QString filename);
void onImportTemplateFileAccepted();
Expand Down Expand Up @@ -361,6 +367,7 @@ public slots:
*/
QString m_templateFileToImport;

bool m_forceImport;
};

#endif // MAINCONTROLLER_H
2 changes: 2 additions & 0 deletions src/core/manager/GuiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class GuiManager : public QObject
void overrideGuiScalingChanged();
void overrideGraphicsLevelChanged();
void snapToGridChanged();
void closeTutorialView();
void openTutorialView();

public slots:

Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ int main(int argc, char* argv[]) {

QCommandLineParser parser;
parser.addPositionalArgument("template", "Template to import");
parser.addOptions({
{{"f", "force"}, "force import (no warning dialog)"}
});
parser.addHelpOption();
parser.process(app);
QString templateFile = parser.positionalArguments().size() >= 1 ? parser.positionalArguments().at(0) : "";
bool forceImport = parser.isSet("force");

// prepare QML engine:
qmlRegisterSingletonType(QUrl("qrc:/qml/DefaultStyle.qml"), "CustomStyle", 1, 0, "Style");
Expand All @@ -140,7 +145,7 @@ int main(int argc, char* argv[]) {
engine.rootContext()->setContextProperty("GRAPHICAL_EFFECTS_LEVEL", GRAPHICAL_EFFECTS_LEVEL);

// MainController will take care of initalizing GUI, output etc.:
MainController controller(engine, templateFile);
MainController controller(engine, templateFile, forceImport);
QObject::connect(&app, SIGNAL(aboutToQuit()), &controller, SLOT(onExit()));
QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit())); // to make Qt.quit() to work

Expand Down
16 changes: 15 additions & 1 deletion src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,20 @@ Window {
visible: parent.mouseOver
}
}

Connections {
target: guiManager

onOpenTutorialView: {
if (!tutorialView.open)
tutorialView.open = true
}
onCloseTutorialView: {
if (tutorialView.open)
tutorialView.open = false
}
}

}

// -------------------------------- Template Import Dialog ---------------------------------
Expand All @@ -487,7 +501,7 @@ Window {
id: templateImportDialog
title: "Import Template"
standardButtons: Dialog.Open | Dialog.Cancel
visible: controller.templateFileToImport
visible: controller.templateFileToImport && !controller.forceImport

onAccepted: {
controller.onImportTemplateFileAccepted()
Expand Down

0 comments on commit 4d87159

Please sign in to comment.