summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gui/ui.cpp25
-rw-r--r--gui/ui.h5
-rw-r--r--opentrack-compat/options.cpp32
-rw-r--r--spline-widget/functionconfig.cpp29
-rw-r--r--spline-widget/functionconfig.h4
5 files changed, 56 insertions, 39 deletions
diff --git a/gui/ui.cpp b/gui/ui.cpp
index fabcb5e4..40ac6c8d 100644
--- a/gui/ui.cpp
+++ b/gui/ui.cpp
@@ -74,9 +74,6 @@ MainWindow::MainWindow() :
connect(&pose_update_timer, SIGNAL(timeout()), this, SLOT(showHeadPose()));
connect(&kbd_quit, SIGNAL(activated()), this, SLOT(exit()));
- save_timer.setSingleShot(true);
- connect(&save_timer, SIGNAL(timeout()), this, SLOT(_save()));
-
profile_menu.addAction("Create new empty config", this, SLOT(make_empty_config()));
profile_menu.addAction("Create new copied config", this, SLOT(make_copied_config()));
profile_menu.addAction("Open configuration directory", this, SLOT(open_config_directory()));
@@ -156,11 +153,10 @@ bool MainWindow::get_new_config_name_from_dialog(QString& ret)
MainWindow::~MainWindow()
{
- maybe_save();
-
if (tray)
tray->hide();
stopTracker();
+ save();
}
void MainWindow::set_working_directory()
@@ -168,30 +164,15 @@ void MainWindow::set_working_directory()
QDir::setCurrent(QCoreApplication::applicationDirPath());
}
-void MainWindow::save_mappings() {
+void MainWindow::save_mappings()
+{
pose.save_mappings();
}
void MainWindow::save()
{
- save_timer.stop();
- save_timer.start(5000);
-}
-
-void MainWindow::maybe_save()
-{
- if (save_timer.isActive())
- {
- save_timer.stop();
- _save();
- }
-}
-
-void MainWindow::_save() {
s.b->save();
save_mappings();
- mem<QSettings> settings = group::ini_file();
- settings->sync();
#if defined(__unix) || defined(__linux)
QString currentFile = group::ini_pathname();
diff --git a/gui/ui.h b/gui/ui.h
index fbfd1237..42c4630c 100644
--- a/gui/ui.h
+++ b/gui/ui.h
@@ -38,7 +38,7 @@ using namespace options;
class MainWindow : public QMainWindow, private State
{
Q_OBJECT
-
+
Shortcuts global_shortcuts;
Ui::OpentrackUI ui;
@@ -55,7 +55,6 @@ class MainWindow : public QMainWindow, private State
process_detector_worker det;
QMenu profile_menu;
bool is_refreshing_profiles;
- QTimer save_timer;
mem<dylib> current_tracker()
{
@@ -79,10 +78,8 @@ class MainWindow : public QMainWindow, private State
void set_title(const QString& game_title = QStringLiteral(""));
static bool get_new_config_name_from_dialog(QString &ret);
void set_profile(const QString& profile);
- void maybe_save();
void register_shortcuts();
private slots:
- void _save();
void save();
void exit();
void profileSelected(QString name);
diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp
index 55a4b795..785698de 100644
--- a/opentrack-compat/options.cpp
+++ b/opentrack-compat/options.cpp
@@ -88,7 +88,7 @@ const mem<QSettings> group::ini_file()
return std::make_shared<QSettings>();
}
-impl_bundle::impl_bundle(const QString &group_name)
+impl_bundle::impl_bundle(const QString& group_name)
:
mtx(QMutex::Recursive),
group_name(group_name),
@@ -101,20 +101,25 @@ void impl_bundle::reload()
{
{
QMutexLocker l(&mtx);
- saved = group(group_name);
- transient = saved;
- modified = false;
+ if (modified)
+ {
+ saved = group(group_name);
+ transient = saved;
+ modified = false;
+ }
}
emit reloading();
}
-void impl_bundle::store_kv(const QString &name, const QVariant &datum)
+void impl_bundle::store_kv(const QString& name, const QVariant& datum)
{
QMutexLocker l(&mtx);
auto old = transient.get<QVariant>(name);
if (!transient.contains(name) || datum != old)
{
+ if (!modified)
+ qDebug() << "bundle" << group_name << "modified" << "key" << name << "to" << datum << "from" << old;
modified = true;
transient.put(name, datum);
}
@@ -128,13 +133,20 @@ bool impl_bundle::contains(const QString &name) const
void impl_bundle::save()
{
+ bool modified_ = false;
{
QMutexLocker l(&mtx);
- modified = false;
- saved = transient;
- transient.save();
+ if (modified)
+ {
+ qDebug() << "bundle" << group_name << "saved";
+ modified_ = true;
+ modified = false;
+ saved = transient;
+ transient.save();
+ }
}
- emit saving();
+ if (modified_)
+ emit saving();
}
bool impl_bundle::modifiedp() const
@@ -220,7 +232,6 @@ custom_type_initializer custom_type_initializer::singleton = custom_type_initial
QDataStream& operator <<(QDataStream& out, const options::slider_value& v)
{
out << v.cur() << v.min() << v.max();
- qDebug() << "out cur" << v.cur();
return out;
}
@@ -231,6 +242,5 @@ QDataStream& operator >>(QDataStream& in, options::slider_value& v)
in >> min;
in >> max;
v = options::slider_value(cur, min, max);
- qDebug() << "in cur" << v.cur();
return in;
}
diff --git a/spline-widget/functionconfig.cpp b/spline-widget/functionconfig.cpp
index 1acea958..8cfce7ae 100644
--- a/spline-widget/functionconfig.cpp
+++ b/spline-widget/functionconfig.cpp
@@ -15,6 +15,7 @@
#include <QtAlgorithms>
#include <QSettings>
#include <QPixmap>
+#include <QString>
#include <algorithm>
#include <cmath>
@@ -271,10 +272,36 @@ void Map::loadSettings(QSettings& settings, const QString& title)
saved = cur;
}
+bool Map::State::operator==(const State& other) const
+{
+ if (input.size() != other.input.size())
+ return false;
+
+ const int sz = input.size();
+
+ using std::fabs;
+
+ for (int i = 0; i < sz; i++)
+ {
+ const qreal eps = 1e-3;
+
+ if (fabs(input[i].x() - other.input[i].x()) > eps ||
+ fabs(input[i].y() - other.input[i].y()) > eps)
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
void Map::saveSettings(QSettings& settings, const QString& title)
{
QMutexLocker foo(&_mutex);
- settings.beginGroup(QString("Curves-%1").arg(title));
+
+ if (cur == saved)
+ return;
+
+ settings.beginGroup(QStringLiteral("Curves-%1").arg(title));
if (cur.input.size() == 0)
cur.input.push_back(QPointF(max_x, max_y));
diff --git a/spline-widget/functionconfig.h b/spline-widget/functionconfig.h
index 6c039831..5c9eeb2b 100644
--- a/spline-widget/functionconfig.h
+++ b/spline-widget/functionconfig.h
@@ -28,9 +28,11 @@ class SPLINE_WIDGET_EXPORT Map {
private:
static constexpr int value_count = 10000;
- struct State {
+ struct State
+ {
QList<QPointF> input;
std::vector<float> data;
+ bool operator==(const State& s) const;
};
int precision() const;