From 87c09c0ab5e1334e9877ee6fd7adeb1eb70d5929 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 6 May 2017 13:15:16 +0200 Subject: options: don't create QSettings all the time Update usages. --- gui/main-window.cpp | 8 ++++++++ gui/mapping-window.cpp | 11 ++++------- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'gui') diff --git a/gui/main-window.cpp b/gui/main-window.cpp index d64858c4..96be298e 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -277,6 +277,14 @@ void MainWindow::die_on_config_not_writable() bool MainWindow::maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list_) { + const bool writable = + group::with_settings_object([&](QSettings& s) { + return s.isWritable(); + }); + + if (writable) + return false; + const bool open = QFile(group::ini_combine(current)).open(QFile::ReadWrite); const QStringList ini_list = group::ini_list(); diff --git a/gui/mapping-window.cpp b/gui/mapping-window.cpp index 0ee8c562..0a5d3049 100644 --- a/gui/mapping-window.cpp +++ b/gui/mapping-window.cpp @@ -114,18 +114,15 @@ void MapWidget::closeEvent(QCloseEvent*) void MapWidget::save_dialog() { - mem settings_ = group::ini_file(); - QSettings& settings = *settings_; - - s.b_map->save_deferred(settings); + s.b_map->save(); for (int i = 0; i < 6; i++) { m.forall([&](Map& s) { - s.spline_main.save(settings); - s.spline_alt.save(settings); - s.opts.b_mapping_window->save_deferred(settings); + s.spline_main.save(); + s.spline_alt.save(); + s.opts.b_mapping_window->save(); }); } } -- cgit v1.2.3 From 03c5a15199b34b564314ac222d51ab687fc97a93 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 6 May 2017 13:23:44 +0200 Subject: get rid of the silly mem -> shared_ptr alias --- gui/main-window.cpp | 8 ++++---- gui/main-window.hpp | 8 ++++---- gui/main.cpp | 4 ++-- logic/selected-libraries.hpp | 11 +++++++---- logic/state.hpp | 2 +- logic/work.cpp | 2 +- logic/work.hpp | 2 +- spline/spline-widget.cpp | 2 +- spline/spline.cpp | 4 ++-- spline/spline.hpp | 6 +++--- 10 files changed, 26 insertions(+), 23 deletions(-) (limited to 'gui') diff --git a/gui/main-window.cpp b/gui/main-window.cpp index 96be298e..aa8e16f3 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -74,13 +74,13 @@ MainWindow::MainWindow() : { modules.filters().push_front(std::make_shared("", dylib::Filter)); - for (mem& x : modules.trackers()) + for (std::shared_ptr& x : modules.trackers()) ui.iconcomboTrackerSource->addItem(x->icon, x->name); - for (mem& x : modules.protocols()) + for (std::shared_ptr& x : modules.protocols()) ui.iconcomboProtocol->addItem(x->icon, x->name); - for (mem& x : modules.filters()) + for (std::shared_ptr& x : modules.filters()) ui.iconcomboFilter->addItem(x->icon, x->name); } @@ -601,7 +601,7 @@ inline bool MainWindow::mk_window(ptr& place, Args&&... params) } template -bool MainWindow::mk_dialog(mem lib, ptr& d) +bool MainWindow::mk_dialog(std::shared_ptr lib, ptr& d) { const bool just_created = mk_window_common(d, [&]() -> t* { if (lib && lib->Dialog) diff --git a/gui/main-window.hpp b/gui/main-window.hpp index 71e372f0..ef6143e7 100644 --- a/gui/main-window.hpp +++ b/gui/main-window.hpp @@ -68,15 +68,15 @@ class MainWindow : public QMainWindow, private State menu_action_tracker, menu_action_filter, menu_action_proto, menu_action_options, menu_action_mappings; - mem current_tracker() + std::shared_ptr current_tracker() { return modules.trackers().value(ui.iconcomboTrackerSource->currentIndex(), nullptr); } - mem current_protocol() + std::shared_ptr current_protocol() { return modules.protocols().value(ui.iconcomboProtocol->currentIndex(), nullptr); } - mem current_filter() + std::shared_ptr current_filter() { return modules.filters().value(ui.iconcomboFilter->currentIndex(), nullptr); } @@ -99,7 +99,7 @@ class MainWindow : public QMainWindow, private State // only use in impl file since no definition in header! template - bool mk_dialog(mem lib, ptr& d); + bool mk_dialog(std::shared_ptr lib, ptr& d); // idem template diff --git a/gui/main.cpp b/gui/main.cpp index 80040732..16e08b6e 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -129,13 +129,13 @@ main(int argc, char** argv) if (!QSettings(OPENTRACK_ORG).value("disable-translation", false).toBool()) { - (void) t.load(QLocale(), "", "", QCoreApplication::applicationDirPath() + "/" + OPENTRACK_I18N_PATH, ".qm"); + (void) t.load(QLocale(), "", "", QCoreApplication::applicationDirPath() + "/" OPENTRACK_I18N_PATH, ".qm"); (void) QCoreApplication::installTranslator(&t); } do { - mem w = std::make_shared(); + std::shared_ptr w = std::make_shared(); if (!w->isEnabled()) break; diff --git a/logic/selected-libraries.hpp b/logic/selected-libraries.hpp index 689cbec3..65e9733e 100644 --- a/logic/selected-libraries.hpp +++ b/logic/selected-libraries.hpp @@ -15,11 +15,14 @@ struct OTR_LOGIC_EXPORT SelectedLibraries { - using dylibptr = mem; - mem pTracker; - mem pFilter; - mem pProtocol; + using dylibptr = std::shared_ptr; + + std::shared_ptr pTracker; + std::shared_ptr pFilter; + std::shared_ptr pProtocol; + SelectedLibraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f); SelectedLibraries() : pTracker(nullptr), pFilter(nullptr), pProtocol(nullptr), correct(false) {} + bool correct; }; diff --git a/logic/state.hpp b/logic/state.hpp index f5892557..8bef71ad 100644 --- a/logic/state.hpp +++ b/logic/state.hpp @@ -26,5 +26,5 @@ struct State Modules modules; main_settings s; Mappings pose; - mem work; + std::shared_ptr work; }; diff --git a/logic/work.cpp b/logic/work.cpp index 7b9e550e..6829e62b 100644 --- a/logic/work.cpp +++ b/logic/work.cpp @@ -60,7 +60,7 @@ std::shared_ptr Work::make_logger(main_settings &s) } -Work::Work(Mappings& m, QFrame* frame, mem tracker_, mem filter_, mem proto_) : +Work::Work(Mappings& m, QFrame* frame, std::shared_ptr tracker_, std::shared_ptr filter_, std::shared_ptr proto_) : libs(frame, tracker_, filter_, proto_), logger(make_logger(s)), tracker(std::make_shared(m, libs, *logger)), diff --git a/logic/work.hpp b/logic/work.hpp index f1d5e401..dc32536c 100644 --- a/logic/work.hpp +++ b/logic/work.hpp @@ -35,7 +35,7 @@ struct OTR_LOGIC_EXPORT Work std::shared_ptr sc; std::vector keys; - Work(Mappings& m, QFrame* frame, mem tracker, mem filter, mem proto); + Work(Mappings& m, QFrame* frame, std::shared_ptr tracker, std::shared_ptr filter, std::shared_ptr proto); ~Work(); void reload_shortcuts(); bool is_ok() const; diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index fef03e82..c71626f0 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -59,7 +59,7 @@ void spline_widget::setConfig(spline* spl) if (spl) { - mem s = spl->get_settings(); + std::shared_ptr s = spl->get_settings(); connection = connect(s.get(), &spline::settings::recomputed, this, [this]() { reload_spline(); }, Qt::QueuedConnection); diff --git a/spline/spline.cpp b/spline/spline.cpp index 58703e02..c1f09db8 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -428,13 +428,13 @@ void spline::recompute() } // the return value is only safe to use with no spline::set_bundle calls -mem spline::get_settings() +std::shared_ptr spline::get_settings() { QMutexLocker foo(&_mutex); return s; } -mem spline::get_settings() const +std::shared_ptr spline::get_settings() const { QMutexLocker foo(&_mutex); return s; diff --git a/spline/spline.hpp b/spline/spline.hpp index 146837c8..acb1861a 100644 --- a/spline/spline.hpp +++ b/spline/spline.hpp @@ -52,7 +52,7 @@ class OTR_SPLINE_EXPORT spline final static QPointF ensure_in_bounds(const QList& points, double max_x, int i); static int element_count(const QList& points, double max_x); - mem s; + std::shared_ptr s; QMetaObject::Connection connection; std::vector data; @@ -99,8 +99,8 @@ public: bundle get_bundle(); void recompute(); - mem get_settings(); - mem get_settings() const; + std::shared_ptr get_settings(); + std::shared_ptr get_settings() const; using points_t = decltype(s->points()); int get_point_count() const; -- cgit v1.2.3