More preparation and some settings handling cleanup
authorSoeren Apel <soeren@apelpie.net>
Mon, 25 Nov 2019 11:13:44 +0000 (12:13 +0100)
committerSoeren Apel <soeren@apelpie.net>
Mon, 25 Nov 2019 11:29:56 +0000 (12:29 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/viewbase.hpp

index f0a4c0714f12075a9d5ff2e6ca317d8392859595..c652e3e861ac0fd31d40888b8e2e8fc064886273 100644 (file)
@@ -51,6 +51,7 @@
 
 #ifdef ENABLE_DECODE
 #include "subwindows/decoder_selector/subwindow.hpp"
+#include "views/decoder_output/view.hpp"
 #endif
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
@@ -62,10 +63,6 @@ using std::string;
 
 namespace pv {
 
-namespace view {
-class ViewItem;
-}
-
 using toolbars::MainBar;
 
 const QString MainWindow::WindowTitle = tr("PulseView");
@@ -79,16 +76,12 @@ MainWindow::MainWindow(DeviceManager &device_manager, QWidget *parent) :
        icon_green_(":/icons/status-green.svg"),
        icon_grey_(":/icons/status-grey.svg")
 {
-       GlobalSettings::add_change_handler(this);
-
        setup_ui();
        restore_ui_settings();
 }
 
 MainWindow::~MainWindow()
 {
-       GlobalSettings::remove_change_handler(this);
-
        // Make sure we no longer hold any shared pointers to widgets after the
        // destructor finishes (goes for sessions and sub windows alike)
 
@@ -162,6 +155,10 @@ shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
                // This view will be the main view if there's no main bar yet
                v = make_shared<views::trace::View>(session,
                        (main_bar ? false : true), dock_main);
+#ifdef ENABLE_DECODE
+       if (type == views::ViewTypeDecoderOutput)
+               v = make_shared<views::decoder_output::View>(session, false, dock_main);
+#endif
 
        if (!v)
                return nullptr;
@@ -191,10 +188,6 @@ shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
                views::trace::View *tv =
                        qobject_cast<views::trace::View*>(v.get());
 
-               tv->enable_colored_bg(settings.value(GlobalSettings::Key_View_ColoredBG).toBool());
-               tv->enable_show_sampling_points(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
-               tv->enable_show_analog_minor_grid(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool());
-
                if (!main_bar) {
                        /* Initial view, create the main bar */
                        main_bar = make_shared<MainBar>(session, this, tv);
@@ -476,18 +469,6 @@ void MainWindow::restore_sessions()
        }
 }
 
-void MainWindow::on_setting_changed(const QString &key, const QVariant &value)
-{
-       if (key == GlobalSettings::Key_View_ColoredBG)
-               on_settingViewColoredBg_changed(value);
-
-       if (key == GlobalSettings::Key_View_ShowSamplingPoints)
-               on_settingViewShowSamplingPoints_changed(value);
-
-       if (key == GlobalSettings::Key_View_ShowAnalogMinorGrid)
-               on_settingViewShowAnalogMinorGrid_changed(value);
-}
-
 void MainWindow::setup_ui()
 {
        setObjectName(QString::fromUtf8("MainWindow"));
@@ -602,19 +583,6 @@ void MainWindow::restore_ui_settings()
        settings.endGroup();
 }
 
-void MainWindow::zoom_current_view(double steps)
-{
-       shared_ptr<Session> session = get_tab_session(session_selector_.currentIndex());
-
-       if (!session)
-               return;
-
-       shared_ptr<views::ViewBase> v = session.get()->main_view();
-       views::trace::View *tv =
-               qobject_cast<views::trace::View*>(v.get());
-       tv->zoom(steps);
-}
-
 shared_ptr<Session> MainWindow::get_tab_session(int index) const
 {
        // Find the session that belongs to the tab's main window
@@ -921,51 +889,6 @@ void MainWindow::on_view_show_analog_minor_grid_shortcut()
        settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, !state);
 }
 
-void MainWindow::on_settingViewColoredBg_changed(const QVariant new_value)
-{
-       bool state = new_value.toBool();
-
-       for (auto& entry : view_docks_) {
-               shared_ptr<views::ViewBase> viewbase = entry.second;
-
-               // Only trace views have this setting
-               views::trace::View* view =
-                               qobject_cast<views::trace::View*>(viewbase.get());
-               if (view)
-                       view->enable_colored_bg(state);
-       }
-}
-
-void MainWindow::on_settingViewShowSamplingPoints_changed(const QVariant new_value)
-{
-       bool state = new_value.toBool();
-
-       for (auto& entry : view_docks_) {
-               shared_ptr<views::ViewBase> viewbase = entry.second;
-
-               // Only trace views have this setting
-               views::trace::View* view =
-                               qobject_cast<views::trace::View*>(viewbase.get());
-               if (view)
-                       view->enable_show_sampling_points(state);
-       }
-}
-
-void MainWindow::on_settingViewShowAnalogMinorGrid_changed(const QVariant new_value)
-{
-       bool state = new_value.toBool();
-
-       for (auto& entry : view_docks_) {
-               shared_ptr<views::ViewBase> viewbase = entry.second;
-
-               // Only trace views have this setting
-               views::trace::View* view =
-                               qobject_cast<views::trace::View*>(viewbase.get());
-               if (view)
-                       view->enable_show_analog_minor_grid(state);
-       }
-}
-
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
index ea549c502a27c841001569bfe20b43d1d065f111..6f3676c214f24c7343ed62bde29fe1446d1d036f 100644 (file)
@@ -30,7 +30,6 @@
 #include <QTabWidget>
 #include <QToolButton>
 
-#include "globalsettings.hpp"
 #include "session.hpp"
 #include "subwindows/subwindowbase.hpp"
 #include "views/viewbase.hpp"
@@ -63,7 +62,7 @@ class DecoderMenu;
 #endif
 }
 
-class MainWindow : public QMainWindow, public GlobalSettingsInterface
+class MainWindow : public QMainWindow
 {
        Q_OBJECT
 
@@ -100,17 +99,12 @@ public:
        void save_sessions();
        void restore_sessions();
 
-       void on_setting_changed(const QString &key, const QVariant &value);
-
 private:
        void setup_ui();
 
        void save_ui_settings();
        void restore_ui_settings();
 
-       void zoom_current_view(double steps);
-       void scroll_to_start_or_end(bool start);
-
        shared_ptr<Session> get_tab_session(int index) const;
 
        void closeEvent(QCloseEvent *event);
@@ -147,10 +141,6 @@ private Q_SLOTS:
        void on_view_show_sampling_points_shortcut();
        void on_view_show_analog_minor_grid_shortcut();
 
-       void on_settingViewColoredBg_changed(const QVariant new_value);
-       void on_settingViewShowSamplingPoints_changed(const QVariant new_value);
-       void on_settingViewShowAnalogMinorGrid_changed(const QVariant new_value);
-
        void on_close_current_tab();
 
 private:
index ae98dc3a85a50c30c377929dede032a81bbcb894..668ebb70b0e85b25701bccaa6adf91c638672860 100644 (file)
@@ -798,26 +798,6 @@ pair<Timestamp, Timestamp> View::get_time_extents() const
        return make_pair(*left_time, *right_time);
 }
 
-void View::enable_show_sampling_points(bool state)
-{
-       (void)state;
-
-       viewport_->update();
-}
-
-void View::enable_show_analog_minor_grid(bool state)
-{
-       (void)state;
-
-       viewport_->update();
-}
-
-void View::enable_colored_bg(bool state)
-{
-       colored_bg_ = state;
-       viewport_->update();
-}
-
 bool View::colored_bg() const
 {
        return colored_bg_;
@@ -1037,13 +1017,22 @@ int View::header_width() const
 
 void View::on_setting_changed(const QString &key, const QVariant &value)
 {
+       GlobalSettings settings;
+
+       if (key == GlobalSettings::Key_View_ColoredBG) {
+               colored_bg_ = settings.value(GlobalSettings::Key_View_ColoredBG).toBool();
+               viewport_->update();
+       }
+
+       if ((key == GlobalSettings::Key_View_ShowSamplingPoints) ||
+          (key == GlobalSettings::Key_View_ShowAnalogMinorGrid))
+               viewport_->update();
+
        if (key == GlobalSettings::Key_View_TriggerIsZeroTime)
                on_settingViewTriggerIsZeroTime_changed(value);
 
-       if (key == GlobalSettings::Key_View_SnapDistance) {
-               GlobalSettings settings;
+       if (key == GlobalSettings::Key_View_SnapDistance)
                snap_distance_ = settings.value(GlobalSettings::Key_View_SnapDistance).toInt();
-       }
 }
 
 void View::trigger_event(int segment_id, util::Timestamp location)
index 6c8ff3d1075d3e42d54ab8c478881fe86e2622a5..82a2f728116608555cee5b6ebb6a5001c30abd9b 100644 (file)
@@ -260,27 +260,11 @@ public:
 
        pair<pv::util::Timestamp, pv::util::Timestamp> get_time_extents() const;
 
-       /**
-        * Enables or disables colored trace backgrounds. If they're not
-        * colored then they will use alternating colors.
-        */
-       void enable_colored_bg(bool state);
-
        /**
         * Returns true if the trace background should be drawn with a colored background.
         */
        bool colored_bg() const;
 
-       /**
-        * Enable or disable showing sampling points.
-        */
-       void enable_show_sampling_points(bool state);
-
-       /**
-        * Enable or disable showing the analog minor grid.
-        */
-       void enable_show_analog_minor_grid(bool state);
-
        /**
         * Returns true if cursors are displayed. false otherwise.
         */
index f44dbf98edb1c3b5a3a0023dd58f67740b911d46..09c5716ae1cb82443cd13a243a2f714c73c76198 100644 (file)
@@ -52,6 +52,7 @@ namespace views {
 
 enum ViewType {
        ViewTypeTrace,
+       ViewTypeDecoderOutput,
        ViewTypeTabularDecode
 };