Thu, 09 Feb 2017 20:54:21 +0200
Moved some global constants into appropriate namespaces.
src/colors.cpp | file | annotate | diff | comparison | revisions | |
src/colors.h | file | annotate | diff | comparison | revisions | |
src/dialogs/colorselector.h | file | annotate | diff | comparison | revisions | |
src/dialogs/configdialog.cpp | file | annotate | diff | comparison | revisions | |
src/documentmanager.cpp | file | annotate | diff | comparison | revisions | |
src/documentmanager.h | file | annotate | diff | comparison | revisions | |
src/ldDocument.cpp | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions |
--- a/src/colors.cpp Thu Feb 09 20:44:36 2017 +0200 +++ b/src/colors.cpp Thu Feb 09 20:54:21 2017 +0200 @@ -21,18 +21,19 @@ #include "colors.h" #include "ldpaths.h" -static ColorData* colorData = nullptr; +ColorData* LDColor::colorData = nullptr; +const LDColor LDColor::nullColor {-1}; /* * initColors * * Initializes the color information module. */ -void initColors() +void LDColor::initColors() { print ("Initializing color information.\n"); static ColorData colors; - colorData = &colors; + LDColor::colorData = &colors; } /* @@ -197,16 +198,6 @@ } /* - * LDColor :: nullColor - * - * Returns a color that is guaranteed to be invalid. - */ -LDColor LDColor::nullColor() -{ - return LDColor {-1}; -} - -/* * qHash * * LDColors are hashed by their index. @@ -234,9 +225,6 @@ */ ColorData::ColorData() { - if (colorData == nullptr) - colorData = this; - // Initialize main and edge colors, they're special like that. m_data[MainColor].faceColor = "#AAAAAA"; m_data[MainColor].edgeColor = Qt::black; @@ -250,17 +238,6 @@ } /* - * ColorData :: ~ColorData - * - * Cleanup the colorData pointer after the array is deleted. - */ -ColorData::~ColorData() -{ - if (colorData == this) - colorData = nullptr; -} - -/* * ColorData :: contains * * Returns whether or not the given color index is present in the array.
--- a/src/colors.h Thu Feb 09 20:44:36 2017 +0200 +++ b/src/colors.h Thu Feb 09 20:54:21 2017 +0200 @@ -36,7 +36,6 @@ }; ColorData(); - ~ColorData(); void loadFromLdconfig(); bool contains(int code) const; const Entry& get(int code) const; @@ -68,7 +67,8 @@ bool isDirect() const; QString indexString() const; - static LDColor nullColor(); + static const LDColor nullColor; + static void initColors(); LDColor& operator=(qint32 index) { m_index = index; return *this; } LDColor& operator=(const LDColor &other) = default; @@ -84,6 +84,7 @@ bool operator>=(LDColor other) const { return index() >= other.index(); } private: + static ColorData* colorData; const ColorData::Entry& data() const; qint32 m_index; @@ -110,7 +111,6 @@ QStringList m_tokens; }; -void initColors(); int luma(const QColor& col); enum
--- a/src/dialogs/colorselector.h Thu Feb 09 20:44:36 2017 +0200 +++ b/src/dialogs/colorselector.h Thu Feb 09 20:54:21 2017 +0200 @@ -26,9 +26,9 @@ Q_OBJECT public: - explicit ColorSelector (QWidget* parent, LDColor defaultvalue = LDColor::nullColor()); + explicit ColorSelector (QWidget* parent, LDColor defaultvalue = LDColor::nullColor); virtual ~ColorSelector(); - static bool selectColor (QWidget* parent, LDColor& val, LDColor defval = LDColor::nullColor()); + static bool selectColor (QWidget* parent, LDColor& val, LDColor defval = LDColor::nullColor); LDColor selection() const; private:
--- a/src/dialogs/configdialog.cpp Thu Feb 09 20:44:36 2017 +0200 +++ b/src/dialogs/configdialog.cpp Thu Feb 09 20:54:21 2017 +0200 @@ -397,7 +397,7 @@ return; // don't color separators } - LDColor defaultValue = entry ? entry->color() : LDColor::nullColor(); + LDColor defaultValue = entry ? entry->color() : LDColor::nullColor; LDColor value; if (not ColorSelector::selectColor (this, value, defaultValue))
--- a/src/documentmanager.cpp Thu Feb 09 20:44:36 2017 +0200 +++ b/src/documentmanager.cpp Thu Feb 09 20:54:21 2017 +0200 @@ -27,6 +27,7 @@ ConfigOption (QStringList RecentFiles) ConfigOption (bool TryDownloadMissingFiles = false) +const QStringList DocumentManager::specialSubdirectories {"s", "48", "8"}; enum { @@ -208,7 +209,7 @@ // Ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48 QString partTopDir = Basename (Dirname (partpath)); - for (QString subdir : g_specialSubdirectories) + for (QString subdir : specialSubdirectories) { if ((partTopDir == subdir) != (relativeTopDir == subdir)) goto skipthis;
--- a/src/documentmanager.h Thu Feb 09 20:44:36 2017 +0200 +++ b/src/documentmanager.h Thu Feb 09 20:54:21 2017 +0200 @@ -49,6 +49,8 @@ void openMainModel (QString path); bool preInline (LDDocument* doc, Model& model, bool deep, bool renderinline); + static const QStringList specialSubdirectories; + signals: void documentClosed(LDDocument* document); @@ -62,4 +64,3 @@ QString Basename (QString path); QString Dirname (QString path); -static const QStringList g_specialSubdirectories ({ "s", "48", "8" }); \ No newline at end of file
--- a/src/ldDocument.cpp Thu Feb 09 20:44:36 2017 +0200 +++ b/src/ldDocument.cpp Thu Feb 09 20:54:21 2017 +0200 @@ -507,7 +507,7 @@ QString shortname = Basename (a); QString topdirname = Basename (Dirname (a)); - if (g_specialSubdirectories.contains (topdirname)) + if (DocumentManager::specialSubdirectories.contains (topdirname)) shortname.prepend (topdirname + "\\"); return shortname;
--- a/src/main.cpp Thu Feb 09 20:44:36 2017 +0200 +++ b/src/main.cpp Thu Feb 09 20:54:21 2017 +0200 @@ -41,7 +41,7 @@ paths->deleteLater(); initializeCrashHandler(); - initColors(); + LDColor::initColors(); MainWindow* win = new MainWindow(configObject); win->show();
--- a/src/mainwindow.cpp Thu Feb 09 20:44:36 2017 +0200 +++ b/src/mainwindow.cpp Thu Feb 09 20:54:21 2017 +0200 @@ -450,7 +450,7 @@ void MainWindow::quickColorClicked() { QToolButton* button = static_cast<QToolButton*> (sender()); - LDColor color = LDColor::nullColor(); + LDColor color = LDColor::nullColor; for (const ColorToolbarItem& entry : m_quickColors) { @@ -569,7 +569,7 @@ continue; // This one doesn't use color so it doesn't have a say if (result.isValid() and obj->color() != result) - return LDColor::nullColor(); // No consensus in object color + return LDColor::nullColor; // No consensus in object color if (not result.isValid()) result = obj->color(); @@ -1294,12 +1294,12 @@ ColorToolbarItem ColorToolbarItem::makeSeparator() { - return ColorToolbarItem (LDColor::nullColor(), nullptr); + return ColorToolbarItem (LDColor::nullColor, nullptr); } bool ColorToolbarItem::isSeparator() const { - return color() == LDColor::nullColor(); + return color() == LDColor::nullColor; } LDColor ColorToolbarItem::color() const