# HG changeset patch # User Teemu Piippo # Date 1455671412 -7200 # Node ID 5877e49e9a289b162bb9d8e275d60d5208876661 # Parent b2f58a8e3d2452b8e34c00d93f7405df63066505 Moved PreferredLicenseText into HierarchyElement and made the config pointer be passed to LDPaths. Now I can finally remove the Config global pointer. diff -r b2f58a8e3d24 -r 5877e49e9a28 src/dialogs/newpartdialog.cpp --- a/src/dialogs/newpartdialog.cpp Wed Feb 17 02:56:59 2016 +0200 +++ b/src/dialogs/newpartdialog.cpp Wed Feb 17 03:10:12 2016 +0200 @@ -73,10 +73,11 @@ objs << new LDComment ("Name: .dat"); objs << new LDComment ("Author: " + author()); objs << new LDComment ("!LDRAW_ORG Unofficial_Part"); + QString license = preferredLicenseText(); - if (useCaLicense()) - objs << new LDComment (CALicenseText); - + if (not license.isEmpty()) + objs << new LDComment(license); + objs << new LDEmpty(); objs << new LDBfc (getWinding()); objs << new LDEmpty(); diff -r b2f58a8e3d24 -r 5877e49e9a28 src/hierarchyelement.cpp --- a/src/hierarchyelement.cpp Wed Feb 17 02:56:59 2016 +0200 +++ b/src/hierarchyelement.cpp Wed Feb 17 03:10:12 2016 +0200 @@ -80,4 +80,11 @@ MathFunctions* HierarchyElement::math() const { return m_window->mathFunctions(); +} + + +QString HierarchyElement::preferredLicenseText() const +{ + QString caLicenseText = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt"; + return m_config->useCaLicense() ? caLicenseText : ""; } \ No newline at end of file diff -r b2f58a8e3d24 -r 5877e49e9a28 src/hierarchyelement.h --- a/src/hierarchyelement.h Wed Feb 17 02:56:59 2016 +0200 +++ b/src/hierarchyelement.h Wed Feb 17 03:10:12 2016 +0200 @@ -45,6 +45,9 @@ Grid* grid() const; MathFunctions* math() const; + // Utility functions + QString preferredLicenseText() const; + protected: MainWindow* m_window; DocumentManager* m_documents; diff -r b2f58a8e3d24 -r 5877e49e9a28 src/ldObject.cpp --- a/src/ldObject.cpp Wed Feb 17 02:56:59 2016 +0200 +++ b/src/ldObject.cpp Wed Feb 17 03:10:12 2016 +0200 @@ -1136,13 +1136,6 @@ // ============================================================================= // -QString PreferredLicenseText() -{ - return Config->useCaLicense() ? CALicenseText : ""; -} - -// ============================================================================= -// LDObject* LDObject::createCopy() const { LDObject* copy = ParseLine (asText()); diff -r b2f58a8e3d24 -r 5877e49e9a28 src/ldObject.h --- a/src/ldObject.h Wed Feb 17 02:56:59 2016 +0200 +++ b/src/ldObject.h Wed Feb 17 03:10:12 2016 +0200 @@ -468,14 +468,8 @@ QVector rasterizePolygons (int segments); }; -// Other common LDraw stuff -static const QString CALicenseText ("!LICENSE Redistributable under CCAL version 2.0 : " - "see CAreadme.txt"); - enum { LowResolution = 16, HighResolution = 48 }; - -QString PreferredLicenseText(); \ No newline at end of file diff -r b2f58a8e3d24 -r 5877e49e9a28 src/ldpaths.cpp --- a/src/ldpaths.cpp Wed Feb 17 02:56:59 2016 +0200 +++ b/src/ldpaths.cpp Wed Feb 17 03:10:12 2016 +0200 @@ -23,26 +23,29 @@ ConfigOption (QString LDrawPath) -LDPaths::LDPaths (QObject* parent) : - QObject (parent), - m_dialog (nullptr) {} +LDPaths::LDPaths (Configuration *config, QObject* parent) : + QObject(parent), + m_config(config), + m_dialog(nullptr) {} + void LDPaths::checkPaths() { - QString pathconfig = Config->lDrawPath(); + QString pathconfig = m_config->lDrawPath(); if (not configurePaths (pathconfig)) { m_dialog = new LDrawPathDialog (pathconfig, false); - connect (m_dialog, SIGNAL (pathChanged(QString)), this, SLOT (configurePaths (QString))); + connect(m_dialog, &LDrawPathDialog::pathChanged, this, &LDPaths::configurePaths); - if (not m_dialog->exec()) - exit (1); + if (m_dialog->exec() != QDialog::Accepted) + exit(1); else - Config->setLDrawPath (m_dialog->path()); + m_config->setLDrawPath(m_dialog->path()); } } + bool LDPaths::isValid (const QDir& dir) const { if (dir.exists()) @@ -66,6 +69,7 @@ return m_error.isEmpty(); } + bool LDPaths::configurePaths (QString path) { QDir dir (path); @@ -85,24 +89,28 @@ return ok; } + QString& LDPaths::ldConfigPath() { static QString value; return value; } + QDir& LDPaths::primitivesDir() { static QDir value; return value; } + QDir& LDPaths::partsDir() { static QDir value; return value; } + QDir& LDPaths::baseDir() { static QDir value; diff -r b2f58a8e3d24 -r 5877e49e9a28 src/ldpaths.h --- a/src/ldpaths.h Wed Feb 17 02:56:59 2016 +0200 +++ b/src/ldpaths.h Wed Feb 17 03:10:12 2016 +0200 @@ -20,14 +20,14 @@ #include "main.h" class QDir; -class MainWindow; +class Configuration; class LDPaths : public QObject { Q_OBJECT public: - LDPaths (QObject* parent = nullptr); + LDPaths(Configuration* config, QObject* parent = nullptr); void checkPaths(); bool isValid (const class QDir& path) const; @@ -40,6 +40,7 @@ bool configurePaths (QString path); private: + Configuration* m_config; mutable QString m_error; class LDrawPathDialog* m_dialog; }; \ No newline at end of file diff -r b2f58a8e3d24 -r 5877e49e9a28 src/main.cpp --- a/src/main.cpp Wed Feb 17 02:56:59 2016 +0200 +++ b/src/main.cpp Wed Feb 17 03:10:12 2016 +0200 @@ -34,7 +34,6 @@ #include "mainwindow.h" MainWindow* g_win = nullptr; -Configuration* Config = nullptr; const Vertex Origin (0.0f, 0.0f, 0.0f); const Matrix IdentityMatrix ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); @@ -49,9 +48,7 @@ app.setApplicationName (APPNAME); static Configuration configObject; - Config = &configObject; - - LDPaths* paths = new LDPaths; + LDPaths* paths = new LDPaths(&configObject); paths->checkPaths(); paths->deleteLater(); diff -r b2f58a8e3d24 -r 5877e49e9a28 src/main.h --- a/src/main.h Wed Feb 17 02:56:59 2016 +0200 +++ b/src/main.h Wed Feb 17 03:10:12 2016 +0200 @@ -32,5 +32,3 @@ #include "format.h" #include "hierarchyelement.h" #include "configuration.h" - -extern Configuration* Config; \ No newline at end of file diff -r b2f58a8e3d24 -r 5877e49e9a28 src/primitives.cpp --- a/src/primitives.cpp Wed Feb 17 02:56:59 2016 +0200 +++ b/src/primitives.cpp Wed Feb 17 03:10:12 2016 +0200 @@ -510,7 +510,7 @@ if (not m_config->defaultName().isEmpty()) { - license = PreferredLicenseText(); + license = preferredLicenseText(); author = format ("%1 [%2]", m_config->defaultName(), m_config->defaultUser()); } diff -r b2f58a8e3d24 -r 5877e49e9a28 src/toolsets/algorithmtoolset.cpp --- a/src/toolsets/algorithmtoolset.cpp Wed Feb 17 02:56:59 2016 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Wed Feb 17 03:10:12 2016 +0200 @@ -449,7 +449,7 @@ LDComment* titleobj = dynamic_cast (currentDocument()->getObject (0)); // License text for the subfile - QString license (PreferredLicenseText()); + QString license = preferredLicenseText(); // LDraw code body of the new subfile (i.e. code of the selection) QStringList code;