Sat, 24 Mar 2018 12:34:20 +0200
Config is now a namespace
--- a/src/basics.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/basics.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -16,10 +16,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <QApplication> +#include <QSettings> #include <QLineF> #include "basics.h" #include "types/vertex.h" #include "format.h" +#include "version.h" int gcd(int a, int b) { @@ -86,3 +89,15 @@ magnitude = qBound(0, magnitude, countof(suffixes) - 1); return QString::number(size / pow(1000, magnitude)) + suffixes[magnitude]; } + +/* + * Returns a settings object that interfaces the ini file. + */ +QSettings& settingsObject() +{ + static QSettings settings { + qApp->applicationDirPath() + "/" UNIXNAME ".ini", + QSettings::IniFormat + }; + return settings; +}
--- a/src/basics.h Sat Mar 24 12:09:26 2018 +0200 +++ b/src/basics.h Sat Mar 24 12:34:20 2018 +0200 @@ -103,4 +103,5 @@ int gcd(int a, int b); QString joinStrings(const QList<class StringFormatArg>& values, QString delimeter = " "); void roundToDecimals(double& value, int decimals); +class QSettings& settingsObject(); void simplify(int& numerator, int& denominator);
--- a/src/colors.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/colors.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -248,7 +248,7 @@ { *this = {}; - for (const Library& library : ::config->libraries()) + for (const Library& library : config::libraries()) { QDir dir {library.path};
--- a/src/dialogs/colorselector.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/dialogs/colorselector.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -53,8 +53,8 @@ if (color == MainColor) { - faceColor = ::config->mainColor(); - faceColor.setAlphaF(::config->mainColorAlpha()); + faceColor = config::mainColor(); + faceColor.setAlphaF(config::mainColorAlpha()); } QString edgeColor = luma(faceColor) < 80 ? "white" : "black";
--- a/src/dialogs/configdialog.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/dialogs/configdialog.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -74,8 +74,7 @@ QDialog (parent, f), HierarchyElement (parent), ui (*new Ui_ConfigDialog), - m_settings (MainWindow::makeSettings (this)), - libraries {::config->libraries()}, + libraries {config::libraries()}, librariesModel {new LibrariesModel {this->libraries, this}} { ui.setupUi (this); @@ -84,7 +83,7 @@ // Set defaults applyToWidgetOptions([&](QWidget* widget, QString confname) { - QVariant value = m_settings->value (confname, m_config->defaultValueByName (confname)); + QVariant value = ::settingsObject().value(confname, config::defaults().value(confname)); QLineEdit* lineedit; QSpinBox* spinbox; QDoubleSpinBox* doublespinbox; @@ -276,7 +275,7 @@ QString optionname (widget->objectName().mid (strlen ("config"))); - if (m_config->existsEntry (optionname)) + if (config::exists(optionname)) func (widget, optionname); else print ("Couldn't find configuration entry named %1", optionname); @@ -316,13 +315,13 @@ return; } - m_settings->setValue (confname, value); + settingsObject().setValue(confname, value); }); // Rebuild the quick color toolbar m_window->setQuickColors (quickColors); - m_config->setQuickColorToolbar (quickColorString()); - ::config->setLibraries(this->libraries); + config::setQuickColorToolbar (quickColorString()); + config::setLibraries(this->libraries); // Ext program settings for (int i = 0; i < NumExternalPrograms; ++i) @@ -343,7 +342,7 @@ item->action()->setShortcut (item->sequence()); } - m_window->syncSettings(); + settingsObject().sync(); m_documents->loadLogoedStuds(); m_window->renderer()->setBackground(); m_window->doFullRefresh();
--- a/src/dialogs/configdialog.h Sat Mar 24 12:09:26 2018 +0200 +++ b/src/dialogs/configdialog.h Sat Mar 24 12:34:20 2018 +0200 @@ -72,7 +72,6 @@ QList<QListWidgetItem*> quickColorItems; QMap<QPushButton*, QColor> m_buttonColors; ExternalProgramWidgets m_externalProgramWidgets[NumExternalPrograms]; - class QSettings* m_settings; QVector<ColorToolbarItem> quickColors; class LibrariesModel* librariesModel; Libraries libraries;
--- a/src/dialogs/newpartdialog.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/dialogs/newpartdialog.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -29,13 +29,13 @@ { this->ui.setupUi (this); - QString authortext = ::config->defaultName(); + QString authortext = config::defaultName(); - if (not ::config->defaultUser().isEmpty()) - authortext.append(format(" [%1]", ::config->defaultUser())); + if (not config::defaultUser().isEmpty()) + authortext.append(format(" [%1]", config::defaultUser())); this->ui.author->setText (authortext); - this->ui.useCaLicense->setChecked (::config->useCaLicense()); + this->ui.useCaLicense->setChecked (config::useCaLicense()); } NewPartDialog::~NewPartDialog()
--- a/src/documentmanager.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/documentmanager.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -19,6 +19,7 @@ #include <QDir> #include <QFileInfo> #include <QMessageBox> +#include <QSettings> #include "documentmanager.h" #include "lddocument.h" #include "partdownloader.h" @@ -143,7 +144,7 @@ } } - if (m_config->tryDownloadMissingFiles() and not unknowns.isEmpty()) + if (config::tryDownloadMissingFiles() and not unknowns.isEmpty()) { PartDownloader dl (m_window); dl.setSourceType (PartDownloader::PartsTracker); @@ -200,7 +201,7 @@ { name = name.replace("\\", "/"); - for (const Library& library : ::config->libraries()) + for (const Library& library : config::libraries()) { for (const QString& subdirectory : {"parts", "p"}) { @@ -280,7 +281,7 @@ void DocumentManager::addRecentFile (QString path) { - QStringList recentFiles = m_config->recentFiles(); + QStringList recentFiles = config::recentFiles(); int idx = recentFiles.indexOf (path); // If this file already is in the list, pop it out. @@ -298,8 +299,8 @@ // Add the file recentFiles << path; - m_config->setRecentFiles (recentFiles); - m_window->syncSettings(); + config::setRecentFiles (recentFiles); + settingsObject().sync(); m_window->updateRecentFilesMenu(); } @@ -333,7 +334,7 @@ // Possibly substitute with logoed studs: // stud.dat -> stud-logo.dat // stud2.dat -> stud-logo2.dat - if (m_config->useLogoStuds() and renderinline) + if (config::useLogoStuds() and renderinline) { // Ensure logoed studs are loaded first loadLogoedStuds();
--- a/src/editmodes/abstractEditMode.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/editmodes/abstractEditMode.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -207,7 +207,7 @@ */ void AbstractDrawMode::drawLineLength(QPainter &painter, const Vertex &v0, const Vertex &v1, const QPointF& v0p, const QPointF& v1p) const { - if (not m_config->drawLineLengths()) + if (not config::drawLineLengths()) return; const QString label = QString::number(abs(v1 - v0), 'f', 2); @@ -256,7 +256,7 @@ if (drawLineLengths) drawLineLength(painter, polygon3d[i], polygon3d[j], polygon2d[i], polygon2d[j]); - if (drawAngles and m_config->drawAngles()) + if (drawAngles and config::drawAngles()) { QLineF line0 = {polygon2d[prior], polygon2d[i]}; QLineF line1 = {polygon2d[i], polygon2d[j]};
--- a/src/glcompiler.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/glcompiler.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -195,7 +195,7 @@ else if (polygon.color == EdgeColor) { // Edge color is black, unless we have a dark background, in which case lines need to be bright. - color = luma(m_config->backgroundColor()) > 40 ? Qt::black : Qt::white; + color = luma(config::backgroundColor()) > 40 ? Qt::black : Qt::white; } else { @@ -217,7 +217,7 @@ if (blendAlpha != 0.0) { - QColor selectedColor = m_config->selectColorBlend(); + QColor selectedColor = config::selectColorBlend(); double denominator = blendAlpha + 1.0; color.setRed((color.red() + (selectedColor.red() * blendAlpha)) / denominator); color.setGreen((color.green() + (selectedColor.green() * blendAlpha)) / denominator);
--- a/src/glrenderer.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/glrenderer.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -64,7 +64,7 @@ {"Free camera", GLCamera::FreeCamera}, // free } { - m_camera = (Camera) m_config->camera(); + m_camera = (Camera) config::camera(); m_compiler = new GLCompiler (this); m_toolTipTimer = new QTimer (this); m_toolTipTimer->setSingleShot (true); @@ -175,7 +175,7 @@ glShadeModel (GL_SMOOTH); glEnable (GL_MULTISAMPLE); - if (m_config->antiAliasedLines()) + if (config::antiAliasedLines()) { glEnable (GL_LINE_SMOOTH); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); @@ -241,7 +241,7 @@ { initializeOpenGLFunctions(); setBackground(); - glLineWidth (m_config->lineThickness()); + glLineWidth (config::lineThickness()); glLineStipple (1, 0x6666); setAutoFillBackground (false); setMouseTracking (true); @@ -311,7 +311,7 @@ if (not m_isDrawingSelectionScene) { // Otherwise use the background that the user wants. - QColor color = m_config->backgroundColor(); + QColor color = config::backgroundColor(); if (color.isValid()) { @@ -359,13 +359,13 @@ zoomAllToFit(); } - if (m_config->drawWireframe() and not m_isDrawingSelectionScene) + if (config::drawWireframe() and not m_isDrawingSelectionScene) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); - if (m_config->lighting() and not m_isDrawingSelectionScene) + if (config::lighting() and not m_isDrawingSelectionScene) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); @@ -402,7 +402,7 @@ } else { - if (m_config->bfcRedGreenView()) + if (config::bfcRedGreenView()) { glEnable (GL_CULL_FACE); glCullFace (GL_BACK); @@ -417,7 +417,7 @@ { VboSubclass colors; - if (m_config->randomColors()) + if (config::randomColors()) colors = VboSubclass::RandomColors; else colors = VboSubclass::RegularColors; @@ -431,7 +431,7 @@ drawVbos (VboClass::ConditionalLines, VboSubclass::RegularColors); glDisable (GL_LINE_STIPPLE); - if (m_config->drawAxes()) + if (config::drawAxes()) { glDisableClientState (GL_NORMAL_ARRAY); glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); @@ -465,9 +465,9 @@ void GLRenderer::drawVbos(VboClass surface, VboSubclass colors) { // Filter this through some configuration options - if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and m_config->drawSurfaces() == false) - or (surface == VboClass::Lines and m_config->drawEdgeLines() == false) - or (surface == VboClass::ConditionalLines and m_config->drawConditionalLines() == false)) + if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and config::drawSurfaces() == false) + or (surface == VboClass::Lines and config::drawEdgeLines() == false) + or (surface == VboClass::ConditionalLines and config::drawConditionalLines() == false)) { return; } @@ -695,7 +695,7 @@ if (freeCameraAllowed() or camera != Camera::Free) { m_camera = camera; - m_config->setCamera(static_cast<int>(camera)); + config::setCamera(static_cast<int>(camera)); } } @@ -796,14 +796,14 @@ glDisable(GL_DITHER); // Use particularly thick lines while picking ease up selecting lines. - glLineWidth(qMax<double>(m_config->lineThickness(), 6.5)); + glLineWidth(qMax<double>(config::lineThickness(), 6.5)); } else { glEnable(GL_DITHER); // Restore line thickness - glLineWidth(m_config->lineThickness()); + glLineWidth(config::lineThickness()); } } @@ -936,13 +936,13 @@ // void GLRenderer::highlightCursorObject() { - if (not m_config->highlightObjectBelowCursor() and not objectAtCursor().isValid()) + if (not config::highlightObjectBelowCursor() and not objectAtCursor().isValid()) return; QModelIndex newIndex; QModelIndex oldIndex = m_objectAtCursor; - if (not m_isCameraMoving and m_config->highlightObjectBelowCursor()) + if (not m_isCameraMoving and config::highlightObjectBelowCursor()) { setPicking (true); drawGLScene();
--- a/src/grid.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/grid.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -25,24 +25,24 @@ qreal Grid::coordinateSnap() const { - switch (m_config->grid()) + switch (config::grid()) { default: - case Grid::Coarse: return m_config->gridCoarseCoordinateSnap(); - case Grid::Medium: return m_config->gridMediumCoordinateSnap(); - case Grid::Fine: return m_config->gridFineCoordinateSnap(); + case Grid::Coarse: return config::gridCoarseCoordinateSnap(); + case Grid::Medium: return config::gridMediumCoordinateSnap(); + case Grid::Fine: return config::gridFineCoordinateSnap(); } } qreal Grid::angleSnap() const { - switch (m_config->grid()) + switch (config::grid()) { default: - case Grid::Coarse: return m_config->gridCoarseAngleSnap(); - case Grid::Medium: return m_config->gridMediumAngleSnap(); - case Grid::Fine: return m_config->gridFineAngleSnap(); + case Grid::Coarse: return config::gridCoarseAngleSnap(); + case Grid::Medium: return config::gridMediumAngleSnap(); + case Grid::Fine: return config::gridFineAngleSnap(); } } @@ -55,12 +55,12 @@ int Grid::bezierCurveSegments() const { - switch (m_config->grid()) + switch (config::grid()) { default: - case Grid::Coarse: return m_config->gridCoarseBezierCurveSegments(); - case Grid::Medium: return m_config->gridMediumBezierCurveSegments(); - case Grid::Fine: return m_config->gridFineBezierCurveSegments(); + case Grid::Coarse: return config::gridCoarseBezierCurveSegments(); + case Grid::Medium: return config::gridMediumBezierCurveSegments(); + case Grid::Fine: return config::gridFineBezierCurveSegments(); } } @@ -104,7 +104,7 @@ */ int Grid::polarDivisions() const { - switch (m_config->grid()) + switch (config::grid()) { default: case Coarse: @@ -121,5 +121,5 @@ */ Grid::Type Grid::type() const { - return m_config->polarGrid() ? Polar : Cartesian; + return config::polarGrid() ? Polar : Cartesian; }
--- a/src/guiutilities.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/guiutilities.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -48,8 +48,8 @@ if (color == MainColor) { // Use the user preferences for the main color. - truecolor = config->mainColor(); - truecolor.setAlphaF(config->mainColorAlpha()); + truecolor = config::mainColor(); + truecolor.setAlphaF(config::mainColorAlpha()); } else { @@ -114,11 +114,11 @@ */ QColor GuiUtilities::mainColorRepresentation() { - QColor result = {m_config->mainColor()}; + QColor result = {config::mainColor()}; if (result.isValid()) { - result.setAlpha(m_config->mainColorAlpha() * 255.f); + result.setAlpha(config::mainColorAlpha() * 255.f); return result; } else @@ -136,7 +136,7 @@ { QVector<ColorToolbarItem> colors; - for (QString colorName : m_config->quickColorToolbar().split(":")) + for (QString colorName : config::quickColorToolbar().split(":")) { if (colorName == "|") {
--- a/src/headerhistorymodel.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/headerhistorymodel.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -149,7 +149,7 @@ { this->header->history.insert(row, {}); this->header->history[row].date = QDate::currentDate(); - this->header->history[row].author = ::config->defaultUser(); + this->header->history[row].author = config::defaultUser(); } this->endInsertRows();
--- a/src/hierarchyelement.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/hierarchyelement.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -42,7 +42,6 @@ } m_documents = m_window->documents(); - m_config = m_window->config(); } @@ -85,5 +84,5 @@ QString HierarchyElement::preferredLicenseText() const { QString caLicenseText = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt"; - return m_config->useCaLicense() ? caLicenseText : ""; + return config::useCaLicense() ? caLicenseText : ""; }
--- a/src/hierarchyelement.h Sat Mar 24 12:09:26 2018 +0200 +++ b/src/hierarchyelement.h Sat Mar 24 12:34:20 2018 +0200 @@ -61,5 +61,4 @@ protected: MainWindow* m_window; DocumentManager* m_documents; - Configuration* m_config; };
--- a/src/main.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/main.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -22,8 +22,6 @@ #include "mainwindow.h" #include "generics/reverse.h" -Configuration* config = nullptr; - int main (int argc, char* argv[]) { QApplication app (argc, argv); @@ -35,9 +33,6 @@ qRegisterMetaTypeStreamOperators<Libraries>("Libraries"); qRegisterMetaType<Vertex>("Vertex"); qRegisterMetaTypeStreamOperators<Vertex>("Vertex"); - - config = &::singleton<Configuration>(); - initializeCrashHandler(); LDColor::initColors(); MainWindow* mainWindow = new MainWindow;
--- a/src/main.h Sat Mar 24 12:09:26 2018 +0200 +++ b/src/main.h Sat Mar 24 12:34:20 2018 +0200 @@ -28,5 +28,3 @@ #include "configuration.h" #include "generics/range.h" #include "types/vertex.h" - -extern Configuration* config;
--- a/src/mainwindow.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/mainwindow.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -52,14 +52,12 @@ // MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) : QMainWindow (parent, flags), - m_config(*::config), m_guiUtilities (new GuiUtilities (this)), m_primitives(new PrimitiveManager(this)), m_grid(new Grid(this)), m_mathFunctions(new MathFunctions(this)), ui (*new Ui_MainWindow), m_externalPrograms (nullptr), - m_settings (makeSettings (this)), m_documents (new DocumentManager (this)), m_currentDocument (nullptr) { @@ -141,7 +139,7 @@ } } - for (QVariant const& toolbarname : m_config.hiddenToolbars()) + for (QVariant const& toolbarname : config::hiddenToolbars()) { QToolBar* toolbar = findChild<QToolBar*> (toolbarname.toString()); @@ -151,11 +149,11 @@ // If this is the first start, get the user to configuration. Especially point // them to the profile tab, it's the most important form to fill in. - if (m_config.firstStart()) + if (config::firstStart()) { ConfigDialog* dialog = new ConfigDialog (this, ConfigDialog::ProfileTab); dialog->show(); - m_config.setFirstStart (false); + config::setFirstStart (false); } QMetaObject::invokeMethod (this, "finishInitialization", Qt::QueuedConnection); @@ -173,7 +171,6 @@ delete m_grid; delete m_mathFunctions; delete &ui; - delete m_settings; for (Toolset* toolset : m_toolsets) delete toolset; @@ -222,7 +219,7 @@ QAction* first = nullptr; - for (const QVariant& it : m_config.recentFiles()) + for (const QVariant& it : config::recentFiles()) { QString file = it.toString(); QAction* recent = new QAction (getIcon ("open-recent"), file, this); @@ -271,7 +268,7 @@ void MainWindow::updateGridToolBar() { // Ensure that the current grid - and only the current grid - is selected. - int grid = m_config.grid(); + int grid = config::grid(); ui.actionGridCoarse->setChecked (grid == Grid::Coarse); ui.actionGridMedium->setChecked (grid == Grid::Medium); ui.actionGridFine->setChecked (grid == Grid::Fine); @@ -443,8 +440,8 @@ } // Save the configuration before leaving. - m_config.setHiddenToolbars (hiddenToolbars); - syncSettings(); + config::setHiddenToolbars (hiddenToolbars); + settingsObject().sync(); ev->accept(); } @@ -722,15 +719,15 @@ ui.actionRedo->setEnabled (pos < (long) his->size() - 1); } - ui.actionWireframe->setChecked (m_config.drawWireframe()); - ui.actionAxes->setChecked (m_config.drawAxes()); - ui.actionBfcView->setChecked (m_config.bfcRedGreenView()); - ui.actionRandomColors->setChecked (m_config.randomColors()); - ui.actionDrawAngles->setChecked (m_config.drawAngles()); - ui.actionDrawSurfaces->setChecked (m_config.drawSurfaces()); - ui.actionDrawEdgeLines->setChecked (m_config.drawEdgeLines()); - ui.actionDrawConditionalLines->setChecked (m_config.drawConditionalLines()); - ui.actionLighting->setChecked(m_config.lighting()); + ui.actionWireframe->setChecked (config::drawWireframe()); + ui.actionAxes->setChecked (config::drawAxes()); + ui.actionBfcView->setChecked (config::bfcRedGreenView()); + ui.actionRandomColors->setChecked (config::randomColors()); + ui.actionDrawAngles->setChecked (config::drawAngles()); + ui.actionDrawSurfaces->setChecked (config::drawSurfaces()); + ui.actionDrawEdgeLines->setChecked (config::drawEdgeLines()); + ui.actionDrawConditionalLines->setChecked (config::drawConditionalLines()); + ui.actionLighting->setChecked(config::lighting()); } // --------------------------------------------------------------------------------------------------------------------- @@ -779,7 +776,7 @@ { for (QAction* act : findChildren<QAction*>()) { - QKeySequence seq = m_settings->value ("shortcut_" + act->objectName(), act->shortcut()).value<QKeySequence>(); + QKeySequence seq = settingsObject().value("shortcut_" + act->objectName(), act->shortcut()).value<QKeySequence>(); act->setShortcut (seq); } } @@ -793,9 +790,9 @@ QString const key = "shortcut_" + act->objectName(); if (m_defaultShortcuts[act] != act->shortcut()) - m_settings->setValue (key, act->shortcut()); + settingsObject().setValue(key, act->shortcut()); else - m_settings->remove (key); + settingsObject().remove(key); }); } @@ -857,30 +854,6 @@ ui.ringToolSegmentsLabel->setText (format ("%1 / %2", numerator, denominator)); } -/* - * Returns a settings object that interfaces the ini file. - */ -QSettings* MainWindow::makeSettings(QObject* parent) -{ - QString path = qApp->applicationDirPath() + "/" UNIXNAME ".ini"; - return new QSettings {path, QSettings::IniFormat, parent}; -} - -// --------------------------------------------------------------------------------------------------------------------- -// -void MainWindow::syncSettings() -{ - m_settings->sync(); -} - -// --------------------------------------------------------------------------------------------------------------------- -// -QVariant MainWindow::getConfigValue (QString name) -{ - QVariant value = m_settings->value (name, m_config.defaultValueByName (name)); - return value; -} - // --------------------------------------------------------------------------------------------------------------------- // void MainWindow::createBlankDocument() @@ -1069,11 +1042,6 @@ return m_guiUtilities; } -Configuration* MainWindow::config() -{ - return &m_config; -} - Grid* MainWindow::grid() { return m_grid;
--- a/src/mainwindow.h Sat Mar 24 12:09:26 2018 +0200 +++ b/src/mainwindow.h Sat Mar 24 12:34:20 2018 +0200 @@ -31,7 +31,6 @@ class QToolButton; class Canvas; class Toolset; -class Configuration; class PrimitiveManager; class Grid; class MathFunctions; @@ -69,7 +68,6 @@ void changeDocument (LDDocument* f); void clearSelection(); void closeInitialDocument(); - Configuration* config(); void createBlankDocument(); LDDocument* currentDocument(); void currentDocumentClosed(); @@ -81,8 +79,6 @@ void doFullRefresh(); void endAction(); class ExtProgramToolset* externalPrograms(); - QVariant getConfigValue (QString name); - class QSettings* getSettings() { return m_settings; } LDColor getUniformSelectedColor(); Canvas* getRendererForDocument(LDDocument* document); Grid* grid(); @@ -106,7 +102,6 @@ void setQuickColors (const QVector<ColorToolbarItem> &colors); void spawnContextMenu (const QPoint& position); int suggestInsertPoint(); - void syncSettings(); Q_SLOT void updateActions(); void updateColorToolbar(); void updateDocumentList(); @@ -116,7 +111,6 @@ void updateRecentFilesMenu(); static QPixmap getIcon(QString iconName); - static class QSettings* makeSettings(QObject* parent = nullptr); template<typename... Args> void print(QString formatString, Args... args) @@ -144,7 +138,6 @@ private: struct ToolInfo; - Configuration& m_config; class GuiUtilities* m_guiUtilities; MessageManager* m_messageLog = nullptr; QMap<LDDocument*, Canvas*> m_renderers; @@ -161,7 +154,6 @@ QVector<Toolset*> m_toolsets; QMap<QAction*, ToolInfo> m_toolmap; class ExtProgramToolset* m_externalPrograms; - class QSettings* m_settings; DocumentManager* m_documents; LDDocument* m_currentDocument; QMap<QAction*, QKeySequence> m_defaultShortcuts;
--- a/src/mathfunctions.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/mathfunctions.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -84,7 +84,7 @@ Vertex MathFunctions::getRotationPoint(const QVector<LDObject*>& objs) const { - switch (RotationPoint (m_config->rotationPointType())) + switch (RotationPoint (config::rotationPointType())) { case ObjectOrigin: { @@ -111,7 +111,7 @@ return Vertex(); case CustomPoint: - return m_config->customRotationPoint(); + return config::customRotationPoint(); } return Vertex();
--- a/src/partdownloader.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/partdownloader.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -61,7 +61,7 @@ if (path.isEmpty()) reject(); else - m_config->setDownloadFilePath(path); + config::setDownloadFilePath(path); } } @@ -90,7 +90,7 @@ destination = destination.simplified(); // If the user doesn't want us to guess, stop right here. - if (not m_config->guessDownloadPaths()) + if (not config::guessDownloadPaths()) return; // Ensure .dat extension @@ -255,7 +255,7 @@ if (primaryFile()) emit primaryFileDownloaded(); - if (m_config->autoCloseDownloadDialog() and not failed) + if (config::autoCloseDownloadDialog() and not failed) { // Close automatically if desired. accept(); @@ -308,7 +308,7 @@ QString PartDownloader::downloadPath() { - QString path = m_config->downloadFilePath(); + QString path = config::downloadFilePath(); if (DIRSLASH[0] != '/') path.replace(DIRSLASH, "/");
--- a/src/primitives.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/primitives.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -482,10 +482,10 @@ QString license = ""; bool hires = (spec.divisions == HighResolution); - if (not m_config->defaultName().isEmpty()) + if (not config::defaultName().isEmpty()) { license = preferredLicenseText(); - author = format("%1 [%2]", m_config->defaultName(), m_config->defaultUser()); + author = format("%1 [%2]", config::defaultName(), config::defaultUser()); } document->setFrozen(false); @@ -499,7 +499,7 @@ else document->header.type = LDHeader::Primitive_8; - if (::config->useCaLicense()) + if (config::useCaLicense()) document->header.license = LDHeader::CaLicense; else document->header.license =LDHeader::UnspecifiedLicense; @@ -716,7 +716,7 @@ HierarchyElement(parent), m_manager(parent) { - for (const Library& library : ::config->libraries()) + for (const Library& library : config::libraries()) { QDir dir {library.path}; if (dir.exists("p") and QFileInfo {dir.filePath("p")}.isDir())
--- a/src/toolsets/algorithmtoolset.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -167,12 +167,12 @@ v.apply ([&](Axis, double& a) { - roundToDecimals (a, m_config->roundPositionPrecision()); + roundToDecimals (a, config::roundPositionPrecision()); }); applyToMatrix (t, [&](int, double& a) { - roundToDecimals (a, m_config->roundMatrixPrecision()); + roundToDecimals (a, config::roundMatrixPrecision()); }); mo->setPosition (v); @@ -186,7 +186,7 @@ Vertex v = obj->vertex (i); v.apply ([&](Axis, double& a) { - roundToDecimals (a, m_config->roundPositionPrecision()); + roundToDecimals (a, config::roundPositionPrecision()); }); obj->setVertex (i, v); num += 3; @@ -440,12 +440,12 @@ { bool ok; int numSegments = QInputDialog::getInt (m_window, APPNAME, "Amount of segments:", - m_config->splitLinesSegments(), 0, std::numeric_limits<int>::max(), 1, &ok); + config::splitLinesSegments(), 0, std::numeric_limits<int>::max(), 1, &ok); if (not ok) return; - m_config->setSplitLinesSegments (numSegments); + config::setSplitLinesSegments (numSegments); for (LDObject* obj : selectedObjects()) { @@ -561,9 +561,9 @@ subfile->header.description = subfileTitle; subfile->header.type = LDHeader::Subpart; subfile->header.name = LDDocument::shortenName(fullSubfileName); - subfile->header.author = format("%1 [%2]", m_config->defaultName(), m_config->defaultUser()); + subfile->header.author = format("%1 [%2]", config::defaultName(), config::defaultUser()); - if (::config->useCaLicense()) + if (config::useCaLicense()) subfile->header.license = LDHeader::CaLicense; subfile->setWinding(currentDocument()->winding());
--- a/src/toolsets/extprogramtoolset.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/toolsets/extprogramtoolset.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -76,22 +76,22 @@ bool ExtProgramToolset::getWineSetting (ExtProgramType program) { - return m_window->getConfigValue (externalProgramName (program) + "UsesWine").toBool(); + return config::value(externalProgramName (program) + "UsesWine").toBool(); } QString ExtProgramToolset::getPathSetting (ExtProgramType program) { - return m_window->getConfigValue (externalProgramName (program) + "Path").toString(); + return config::value(externalProgramName (program) + "Path").toString(); } void ExtProgramToolset::setPathSetting (ExtProgramType program, QString value) { - m_window->getSettings()->setValue (externalProgramName (program) + "Path", QVariant::fromValue (value)); + settingsObject().setValue(externalProgramName (program) + "Path", QVariant::fromValue(value)); } void ExtProgramToolset::setWineSetting (ExtProgramType program, bool value) { - m_window->getSettings()->setValue (externalProgramName (program) + "UsesWine", QVariant::fromValue (value)); + settingsObject().setValue(externalProgramName (program) + "UsesWine", QVariant::fromValue(value)); } QString ExtProgramToolset::externalProgramName (ExtProgramType program)
--- a/src/toolsets/movetoolset.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/toolsets/movetoolset.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -53,25 +53,25 @@ void MoveToolset::gridCoarse() { - m_config->setGrid (Grid::Coarse); + config::setGrid (Grid::Coarse); m_window->updateGridToolBar(); } void MoveToolset::gridMedium() { - m_config->setGrid (Grid::Medium); + config::setGrid (Grid::Medium); m_window->updateGridToolBar(); } void MoveToolset::gridFine() { - m_config->setGrid (Grid::Fine); + config::setGrid (Grid::Fine); m_window->updateGridToolBar(); } void MoveToolset::polarGrid() { - m_config->togglePolarGrid(); + config::togglePolarGrid(); m_window->updateGridToolBar(); } @@ -155,7 +155,7 @@ Ui_RotPointUI ui; ui.setupUi(dialog); - switch (RotationPoint(m_config->rotationPointType())) + switch (RotationPoint(config::rotationPointType())) { case ObjectOrigin: ui.objectPoint->setChecked (true); @@ -170,7 +170,7 @@ break; } - Vertex custompoint = m_config->customRotationPoint(); + Vertex custompoint = config::customRotationPoint(); ui.customX->setValue(custompoint.x); ui.customY->setValue(custompoint.y); ui.customZ->setValue(custompoint.z); @@ -189,7 +189,7 @@ custompoint.x = ui.customX->value(); custompoint.y = ui.customY->value(); custompoint.z = ui.customZ->value(); - m_config->setRotationPointType(pointType); - m_config->setCustomRotationPoint(custompoint); + config::setRotationPointType(pointType); + config::setCustomRotationPoint(custompoint); } }
--- a/src/toolsets/viewtoolset.cpp Sat Mar 24 12:09:26 2018 +0200 +++ b/src/toolsets/viewtoolset.cpp Sat Mar 24 12:34:20 2018 +0200 @@ -133,7 +133,7 @@ void ViewToolset::axes() { - m_config->toggleDrawAxes(); + config::toggleDrawAxes(); m_window->updateActions(); m_window->renderer()->update(); } @@ -158,13 +158,13 @@ void ViewToolset::wireframe() { - m_config->toggleDrawWireframe(); + config::toggleDrawWireframe(); m_window->renderer()->update(); } void ViewToolset::drawAngles() { - m_config->toggleDrawAngles(); + config::toggleDrawAngles(); m_window->renderer()->update(); } @@ -233,10 +233,10 @@ void ViewToolset::bfcView() { - m_config->toggleBfcRedGreenView(); + config::toggleBfcRedGreenView(); - if (m_config->bfcRedGreenView()) - m_config->setRandomColors (false); + if (config::bfcRedGreenView()) + config::setRandomColors (false); m_window->updateActions(); m_window->renderer()->update(); @@ -275,10 +275,10 @@ void ViewToolset::randomColors() { - m_config->toggleRandomColors(); + config::toggleRandomColors(); - if (m_config->randomColors()) - m_config->setBfcRedGreenView (false); + if (config::randomColors()) + config::setBfcRedGreenView (false); m_window->updateActions(); m_window->renderer()->update(); @@ -286,24 +286,24 @@ void ViewToolset::drawSurfaces() { - m_config->toggleDrawSurfaces(); + config::toggleDrawSurfaces(); m_window->updateActions(); } void ViewToolset::drawEdgeLines() { - m_config->toggleDrawEdgeLines(); + config::toggleDrawEdgeLines(); m_window->updateActions(); } void ViewToolset::drawConditionalLines() { - m_config->toggleDrawConditionalLines(); + config::toggleDrawConditionalLines(); m_window->updateActions(); } void ViewToolset::lighting() { - m_config->toggleLighting(); + config::toggleLighting(); m_window->updateActions(); }
--- a/tools/configcollector.py Sat Mar 24 12:09:26 2018 +0200 +++ b/tools/configcollector.py Sat Mar 24 12:34:20 2018 +0200 @@ -134,25 +134,20 @@ device.write('\n') formatargs = {} write = lambda value: device.write(value) - write('class Configuration\n') + write('namespace config\n') write('{\n') - write('public:\n') - write('\tConfiguration();\n') - write('\t~Configuration();\n') - write('\tbool existsEntry(const QString& name);\n') - write('\tQVariant defaultValueByName(const QString& name);\n') + write('\tbool exists(const QString& name);\n') + write('\tQVariant value(const QString& name);\n') + write('\tQVariant setValue(const QString& name);\n') + write('\tconst QMap<QString, QVariant>& defaults();\n') for declaration in self.declarations.values(): - write('\t{type} {readgate}() const;\n'.format(**declaration)) + write('\t{type} {readgate}();\n'.format(**declaration)) for declaration in self.declarations.values(): write('\tvoid {writegate}({typereference} value);\n'.format(**declaration)) for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()): write('\tvoid {togglefunction}();\n'.format(**declaration)) - write('\n') - write('private:\n') - write('\tQMap<QString, QVariant> m_defaults;\n') - write('\tclass QSettings* m_settings;\n') - write('};\n') + write('}\n') def writeSource(self, device, headername): device.write('#include <QSet>\n') @@ -161,51 +156,44 @@ device.write('#include "%s/mainwindow.h"\n' % (self.args.sourcedir)) device.write('#include "%s"\n' % headername) device.write( - '\n' - 'Configuration::Configuration() :\n' - '\tm_settings(MainWindow::makeSettings(nullptr))\n' - '{\n') + 'const QMap<QString, QVariant>& config::defaults()\n' + '{\n' + '\tstatic const QMap<QString, QVariant> defaults {' + ) for declaration in self.declarations.values(): - device.write('\tm_defaults["{name}"] = QVariant::fromValue<{type}>({default});\n'.format(**declaration)) - device.write('}\n' - '\n' - 'Configuration::~Configuration()\n' - '{\n' - '\tm_settings->deleteLater();\n' + device.write('\t{{"{name}", QVariant::fromValue<{type}>({default})}},\n'.format(**declaration)) + device.write('};\n' + 'return defaults;\n' '}\n' '\n') - device.write('QVariant Configuration::defaultValueByName(const QString& name)\n') + device.write('bool config::exists(const QString& name)\n') device.write('{\n') - device.write('\tQMap<QString, QVariant>::iterator it = m_defaults.find(name);\n') - device.write('\tif(it != m_defaults.end())\n') - device.write('\t\treturn *it;\n') - device.write('\telse\n') - device.write('\t\treturn {};\n') + device.write('\treturn defaults().contains(name);\n') device.write('}\n') device.write('\n') - device.write('bool Configuration::existsEntry(const QString& name)\n') - device.write('{\n') - device.write('\treturn m_defaults.find(name) != m_defaults.end();\n') - device.write('}\n') + device.write('QVariant config::value(const QString& name)\n' + '{\n' + '\treturn settingsObject().value(name, config::defaults().value(name));\n' + '}\n') device.write('\n') for declaration in self.declarations.values(): - device.write('{type} Configuration::{readgate}() const\n'.format(**declaration)) + device.write('{type} config::{readgate}()\n'.format(**declaration)) device.write('{\n') device.write('\tstatic const QVariant defaultvalue = QVariant::fromValue<{type}>({default});\n'.format(**declaration)) - device.write('\treturn m_settings->value("{name}", defaultvalue).value<{type}>();\n'.format(**declaration)) + device.write('\treturn ::settingsObject().value("{name}", defaultvalue).value<{type}>();\n'.format(**declaration)) device.write('}\n') device.write('\n') for declaration in self.declarations.values(): - device.write('void Configuration::{writegate}({typereference} value)\n'.format(**declaration)) + device.write('void config::{writegate}({typereference} value)\n'.format(**declaration)) device.write('{\n') device.write('\tif(value != {default})\n'.format(**declaration)) - device.write('\t\tm_settings->setValue("{name}", QVariant::fromValue<{type}>(value));\n'.format(**declaration)) + device.write('\t\t::settingsObject().setValue("{name}", QVariant::fromValue<{type}>(value));\n'.format(**declaration)) device.write('\telse\n') - device.write('\t\tm_settings->remove("{name}");\n'.format(**declaration)) + device.write('\t\t::settingsObject().remove("{name}");\n'.format(**declaration)) device.write('}\n') device.write('\n') for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()): - device.write('void Configuration::{togglefunction}()\n'.format(**declaration)) + device.write('void config::{togglefunction}()\n'.format(**declaration)) device.write('{\n') device.write('\t{writegate}(not {readgate}());\n'.format(**declaration)) device.write('}\n')