diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-08-03 03:39:22 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-08-04 06:09:48 -0400 |
| commit | 37502f388422b2fdb60c2564d733ec015f579831 (patch) | |
| tree | f830e2412a74bfb4a49d211b0f525afe4147cd42 /src | |
| parent | cc3a16c6e9d58ed68a31be52f9fe2ef1d514ff5f (diff) | |
removed convertVariant(), turns out value() does it
separator colors to settings
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 30 | ||||
| -rw-r--r-- | src/settings.cpp | 57 | ||||
| -rw-r--r-- | src/settings.h | 4 |
3 files changed, 43 insertions, 48 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 32f728d8..f98da391 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3786,32 +3786,37 @@ void MainWindow::createSeparator_clicked() { m_OrganizerCore.modList()->changeModPriority(ModInfo::getIndex(name), newPriority); } - QSettings &settings = m_OrganizerCore.settings().directInterface(); - QColor previousColor = settings.value("previousSeparatorColor", QColor()).value<QColor>(); - if (previousColor.isValid()) { - ModInfo::getByIndex(ModInfo::getIndex(name))->setColor(previousColor); - } + if (auto c=m_OrganizerCore.settings().getPreviousSeparatorColor()) { + ModInfo::getByIndex(ModInfo::getIndex(name))->setColor(*c); + } } void MainWindow::setColor_clicked() { - QSettings &settings = m_OrganizerCore.settings().directInterface(); + auto& settings = m_OrganizerCore.settings(); ModInfo::Ptr modInfo = ModInfo::getByIndex(m_ContextRow); + QColorDialog dialog(this); dialog.setOption(QColorDialog::ShowAlphaChannel); + QColor currentColor = modInfo->getColor(); - QColor previousColor = settings.value("previousSeparatorColor", QColor()).value<QColor>(); - if (currentColor.isValid()) + if (currentColor.isValid()) { dialog.setCurrentColor(currentColor); - else - dialog.setCurrentColor(previousColor); + } + else if (auto c=settings.getPreviousSeparatorColor()) { + dialog.setCurrentColor(*c); + } + if (!dialog.exec()) return; + currentColor = dialog.currentColor(); if (!currentColor.isValid()) return; - settings.setValue("previousSeparatorColor", currentColor); + + settings.setPreviousSeparatorColor(currentColor); + QItemSelectionModel *selection = ui->modList->selectionModel(); if (selection->hasSelection() && selection->selectedRows().count() > 1) { for (QModelIndex idx : selection->selectedRows()) { @@ -3846,7 +3851,8 @@ void MainWindow::resetColor_clicked() else { modInfo->setColor(color); } - Settings::instance().directInterface().remove("previousSeparatorColor"); + + m_OrganizerCore.settings().removePreviousSeparatorColor(); } void MainWindow::createModFromOverwrite() diff --git a/src/settings.cpp b/src/settings.cpp index 73595ac9..f980e0be 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -27,45 +27,10 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. using namespace MOBase; template <class T> -T convertVariant(const QVariant& v); - -template <> -QByteArray convertVariant<QByteArray>(const QVariant& v) -{ - return v.toByteArray(); -} - -template <> -QString convertVariant<QString>(const QVariant& v) -{ - return v.toString(); -} - -template <> -int convertVariant<int>(const QVariant& v) -{ - return v.toInt(); -} - -template <> -bool convertVariant<bool>(const QVariant& v) -{ - return v.toBool(); -} - -template <> -QSize convertVariant<QSize>(const QVariant& v) -{ - return v.toSize(); -} - - - -template <class T> std::optional<T> getOptional(const QSettings& s, const QString& name) { if (s.contains(name)) { - return convertVariant<T>(s.value(name)); + return s.value(name).value<T>(); } return {}; @@ -453,6 +418,26 @@ bool Settings::getFirstStart() const return getOptional<bool>(m_Settings, "first_start").value_or(true); } +std::optional<QColor> Settings::getPreviousSeparatorColor() const +{ + const auto c = getOptional<QColor>(m_Settings, "previousSeparatorColor"); + if (c && c->isValid()) { + return c; + } + + return {}; +} + +void Settings::setPreviousSeparatorColor(const QColor& c) const +{ + m_Settings.setValue("previousSeparatorColor", c); +} + +void Settings::removePreviousSeparatorColor() +{ + m_Settings.remove("previousSeparatorColor"); +} + QString Settings::getProfileDirectory(bool resolve) const { return getConfigurablePath("profiles_directory", ToQString(AppConfig::profilesPath()), resolve); diff --git a/src/settings.h b/src/settings.h index f4e36b2a..fff684b8 100644 --- a/src/settings.h +++ b/src/settings.h @@ -190,6 +190,10 @@ public: std::optional<QVersionNumber> getVersion() const; bool getFirstStart() const; + std::optional<QColor> getPreviousSeparatorColor() const; + void setPreviousSeparatorColor(const QColor& c) const; + void removePreviousSeparatorColor(); + GeometrySettings& geometry(); const GeometrySettings& geometry() const; |
