]> sigrok.org Git - pulseview.git/commitdiff
Implement initial version of the settings management
authorSoeren Apel <redacted>
Mon, 6 Mar 2017 18:04:47 +0000 (19:04 +0100)
committerUwe Hermann <redacted>
Tue, 7 Mar 2017 21:59:35 +0000 (22:59 +0100)
CMakeLists.txt
pv/dialogs/settings.cpp [new file with mode: 0644]
pv/dialogs/settings.hpp [new file with mode: 0644]
pv/globalsettings.cpp [new file with mode: 0644]
pv/globalsettings.hpp [new file with mode: 0644]
pv/mainwindow.cpp
pv/mainwindow.hpp
test/CMakeLists.txt

index 3ae7e7d27711410d9f727661f10689f51def53f7..547c7c126bf69c7558732091dbc6c6df5e22960e 100644 (file)
@@ -210,6 +210,7 @@ set(pulseview_SOURCES
        main.cpp
        pv/application.cpp
        pv/devicemanager.cpp
+       pv/globalsettings.cpp
        pv/mainwindow.cpp
        pv/session.cpp
        pv/storesession.cpp
@@ -232,6 +233,7 @@ set(pulseview_SOURCES
        pv/dialogs/about.cpp
        pv/dialogs/connect.cpp
        pv/dialogs/inputoutputoptions.cpp
+       pv/dialogs/settings.cpp
        pv/dialogs/storeprogress.cpp
        pv/popups/deviceoptions.cpp
        pv/popups/channels.cpp
@@ -283,6 +285,7 @@ set(pulseview_SOURCES
 
 # This list includes only QObject derived class headers.
 set(pulseview_HEADERS
+       pv/globalsettings.hpp
        pv/mainwindow.hpp
        pv/session.hpp
        pv/storesession.hpp
@@ -295,6 +298,7 @@ set(pulseview_HEADERS
        pv/dialogs/about.hpp
        pv/dialogs/connect.hpp
        pv/dialogs/inputoutputoptions.hpp
+       pv/dialogs/settings.hpp
        pv/dialogs/storeprogress.hpp
        pv/popups/channels.hpp
        pv/popups/deviceoptions.hpp
diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp
new file mode 100644 (file)
index 0000000..8cb8d67
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "settings.hpp"
+#include "pv/globalsettings.hpp"
+
+#include <QCheckBox>
+#include <QDialogButtonBox>
+#include <QFormLayout>
+#include <QGroupBox>
+#include <QTabWidget>
+#include <QVBoxLayout>
+
+namespace pv {
+namespace dialogs {
+
+Settings::Settings(QWidget *parent) :
+       QDialog(parent, 0)
+{
+       QTabWidget *tab_stack = new QTabWidget(this);
+       tab_stack->addTab(get_view_settings_form(tab_stack), tr("&Views"));
+
+       QDialogButtonBox *button_box = new QDialogButtonBox(
+               QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+
+       QVBoxLayout* root_layout = new QVBoxLayout(this);
+       root_layout->addWidget(tab_stack);
+       root_layout->addWidget(button_box);
+
+       connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
+       connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
+}
+
+QWidget *Settings::get_view_settings_form(QWidget *parent) const
+{
+       GlobalSettings settings;
+
+       QWidget *form = new QWidget(parent);
+       QVBoxLayout *form_layout = new QVBoxLayout(form);
+
+       // Trace view settings
+       QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
+       form_layout->addWidget(trace_view_group);
+
+       QFormLayout *trace_view_layout = new QFormLayout();
+       trace_view_group->setLayout(trace_view_layout);
+
+       QCheckBox *coloured_bg_cb = new QCheckBox();
+       coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
+       connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
+       trace_view_layout->addRow(tr("Use &coloured trace background"), coloured_bg_cb);
+
+       QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
+       always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
+       connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
+       trace_view_layout->addRow(tr("Always zoom-to-&fit during capture"), always_zoom_to_fit_cb);
+
+       return form;
+}
+
+void Settings::accept()
+{
+       QDialog::accept();
+}
+
+void Settings::reject()
+{
+       QDialog::reject();
+}
+
+void Settings::on_view_alwaysZoomToFit_changed(int state)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
+}
+
+void Settings::on_view_colouredBG_changed(int state)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
+}
+
+} // namespace dialogs
+} // namespace pv
diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp
new file mode 100644 (file)
index 0000000..20c4f91
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PULSEVIEW_PV_SETTINGS_HPP
+#define PULSEVIEW_PV_SETTINGS_HPP
+
+#include <QDialog>
+
+namespace pv {
+namespace dialogs {
+
+class Settings : public QDialog
+{
+       Q_OBJECT
+
+public:
+       Settings(QWidget *parent = 0);
+
+       QWidget *get_view_settings_form(QWidget *parent) const;
+
+       void accept();
+       void reject();
+
+private Q_SLOTS:
+       void on_view_alwaysZoomToFit_changed(int state);
+       void on_view_colouredBG_changed(int state);
+};
+
+} // namespace dialogs
+} // namespace pv
+
+#endif // PULSEVIEW_PV_SETTINGS_HPP
diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp
new file mode 100644 (file)
index 0000000..5da89ce
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "globalsettings.hpp"
+
+namespace pv {
+
+const QString GlobalSettings::Key_View_AlwaysZoomToFit = "View_AlwaysZoomToFit";
+const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG";
+
+std::multimap< QString, std::function<void(QVariant)> > GlobalSettings::callbacks_;
+
+GlobalSettings::GlobalSettings() :
+       QSettings()
+{
+       beginGroup("Settings");
+}
+
+void GlobalSettings::register_change_handler(const QString key,
+       std::function<void(QVariant)> cb)
+{
+       callbacks_.emplace(key, cb);
+}
+
+void GlobalSettings::setValue(const QString &key, const QVariant &value)
+{
+       QSettings::setValue(key, value);
+
+       // Call all registered callbacks for this key
+       auto range = callbacks_.equal_range(key);
+
+       for (auto it = range.first; it != range.second; it++)
+               it->second(value);
+}
+
+
+} // namespace pv
diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp
new file mode 100644 (file)
index 0000000..b745796
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PULSEVIEW_GLOBALSETTINGS_HPP
+#define PULSEVIEW_GLOBALSETTINGS_HPP
+
+#include <functional>
+#include <map>
+
+#include <QSettings>
+#include <QString>
+#include <QVariant>
+
+namespace pv {
+
+class GlobalSettings : public QSettings
+{
+       Q_OBJECT
+
+public:
+       static const QString Key_View_AlwaysZoomToFit;
+       static const QString Key_View_ColouredBG;
+
+public:
+       GlobalSettings();
+
+       static void register_change_handler(const QString key,
+               std::function<void(QVariant)> cb);
+
+       void setValue(const QString& key, const QVariant& value);
+
+private:
+       static std::multimap< QString, std::function<void(QVariant)> > callbacks_;
+};
+
+} // namespace pv
+
+#endif // PULSEVIEW_GLOBALSETTINGS_HPP
index 33ebdd648e84e09fd6c6614eeb6a6511ce413047..8b650e1ca00067b0d406b6387a3eab657a2dfae4 100644 (file)
 #include "mainwindow.hpp"
 
 #include "devicemanager.hpp"
+#include "globalsettings.hpp"
 #include "util.hpp"
 #include "devices/hardwaredevice.hpp"
 #include "dialogs/about.hpp"
+#include "dialogs/settings.hpp"
 #include "toolbars/mainbar.hpp"
 #include "view/view.hpp"
 #include "views/trace/standardbar.hpp"
@@ -65,6 +67,9 @@ class ViewItem;
 
 using toolbars::MainBar;
 
+using std::bind;
+using std::placeholders::_1;
+
 const QString MainWindow::WindowTitle = tr("PulseView");
 
 MainWindow::MainWindow(DeviceManager &device_manager,
@@ -392,6 +397,8 @@ void MainWindow::setup_ui()
                this, SLOT(on_run_stop_clicked()));
        connect(&session_state_mapper_, SIGNAL(mapped(QObject*)),
                this, SLOT(on_capture_state_changed(QObject*)));
+       connect(settings_button_, SIGNAL(clicked(bool)),
+               this, SLOT(on_settings_clicked()));
 
        connect(&session_selector_, SIGNAL(tabCloseRequested(int)),
                this, SLOT(on_tab_close_requested(int)));
@@ -591,6 +598,12 @@ void MainWindow::on_run_stop_clicked()
        }
 }
 
+void MainWindow::on_settings_clicked()
+{
+       dialogs::Settings dlg;
+       dlg.exec();
+}
+
 void MainWindow::on_session_name_changed()
 {
        // Update the corresponding dock widget's name(s)
index ac098b21ae3580b9a8350d377f74e5773e0b6faa..f38ee44781632521cba1ee31402cc68af1a2bbfd 100644 (file)
@@ -112,6 +112,7 @@ private Q_SLOTS:
 
        void on_new_session_clicked();
        void on_run_stop_clicked();
+       void on_settings_clicked();
 
        void on_session_name_changed();
        void on_capture_state_changed(QObject *obj);
index 069f15f6c43137aea331c389b481004c8e258906..05b5cb4b0be21fad00c83135f93419e3b8d8597a 100644 (file)
@@ -20,6 +20,7 @@
 
 set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/devicemanager.cpp
+       ${PROJECT_SOURCE_DIR}/pv/globalsettings.cpp
        ${PROJECT_SOURCE_DIR}/pv/session.cpp
        ${PROJECT_SOURCE_DIR}/pv/storesession.cpp
        ${PROJECT_SOURCE_DIR}/pv/util.cpp
@@ -97,6 +98,7 @@ set(pulseview_TEST_SOURCES
 
 # This list includes only QObject derived class headers.
 set(pulseview_TEST_HEADERS
+       ${PROJECT_SOURCE_DIR}/pv/globalsettings.hpp
        ${PROJECT_SOURCE_DIR}/pv/session.hpp
        ${PROJECT_SOURCE_DIR}/pv/storesession.hpp
        ${PROJECT_SOURCE_DIR}/pv/binding/device.hpp