#include "globalsettings.hpp"
#include <QApplication>
-#include <QByteArray>
#include <QFontMetrics>
#include <QString>
-using std::function;
using std::map;
-using std::multimap;
+using std::vector;
namespace pv {
const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight";
const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable";
-multimap< QString, function<void(QVariant)> > GlobalSettings::callbacks_;
+vector<GlobalSettingsInterface*> GlobalSettings::callbacks_;
bool GlobalSettings::tracking_ = false;
map<QString, QVariant> GlobalSettings::tracked_changes_;
2 * QFontMetrics(QApplication::font()).height());
}
-void GlobalSettings::register_change_handler(const QString key,
- function<void(QVariant)> cb)
+void GlobalSettings::add_change_handler(GlobalSettingsInterface *cb)
{
- callbacks_.emplace(key, cb);
+ callbacks_.push_back(cb);
+}
+
+void GlobalSettings::remove_change_handler(GlobalSettingsInterface *cb)
+{
+ for (auto cb_it = callbacks_.begin(); cb_it != callbacks_.end(); cb_it++)
+ if (*cb_it == cb) {
+ callbacks_.erase(cb_it);
+ break;
+ }
}
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);
+ // Call all registered callbacks
+ for (GlobalSettingsInterface *cb : callbacks_)
+ cb->on_setting_changed(key, value);
}
void GlobalSettings::start_tracking()
#ifndef PULSEVIEW_GLOBALSETTINGS_HPP
#define PULSEVIEW_GLOBALSETTINGS_HPP
-#include <functional>
#include <map>
#include <glib.h>
using std::function;
using std::map;
-using std::multimap;
+using std::vector;
namespace pv {
+class GlobalSettingsInterface
+{
+public:
+ virtual void on_setting_changed(const QString &key, const QVariant &value) = 0;
+};
+
+
class GlobalSettings : public QSettings
{
Q_OBJECT
void set_defaults_where_needed();
- static void register_change_handler(const QString key,
- function<void(QVariant)> cb);
+ static void add_change_handler(GlobalSettingsInterface *cb);
+ static void remove_change_handler(GlobalSettingsInterface *cb);
void setValue(const QString& key, const QVariant& value);
static GVariant* restore_gvariant(QSettings &settings);
private:
- static multimap< QString, function<void(QVariant)> > callbacks_;
+ static vector<GlobalSettingsInterface*> callbacks_;
static bool tracking_;
static map<QString, QVariant> tracked_changes_;
qRegisterMetaType<util::Timestamp>("util::Timestamp");
qRegisterMetaType<uint64_t>("uint64_t");
- GlobalSettings::register_change_handler(GlobalSettings::Key_View_ColouredBG,
- bind(&MainWindow::on_settingViewColouredBg_changed, this, _1));
-
- GlobalSettings::register_change_handler(GlobalSettings::Key_View_ShowSamplingPoints,
- bind(&MainWindow::on_settingViewShowSamplingPoints_changed, this, _1));
-
- GlobalSettings::register_change_handler(GlobalSettings::Key_View_ShowAnalogMinorGrid,
- bind(&MainWindow::on_settingViewShowAnalogMinorGrid_changed, this, _1));
+ GlobalSettings::add_change_handler(this);
GlobalSettings settings;
settings.set_defaults_where_needed();
MainWindow::~MainWindow()
{
+ GlobalSettings::remove_change_handler(this);
+
while (!sessions_.empty())
remove_session(sessions_.front());
}
}
}
+void MainWindow::on_setting_changed(const QString &key, const QVariant &value)
+{
+ if (key == GlobalSettings::Key_View_ColouredBG)
+ on_settingViewColouredBg_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"));
#include <QTabWidget>
#include <QToolButton>
+#include "globalsettings.hpp"
#include "session.hpp"
#include "views/viewbase.hpp"
#endif
}
-class MainWindow : public QMainWindow
+class MainWindow : public QMainWindow, public GlobalSettingsInterface
{
Q_OBJECT
void save_sessions();
void restore_sessions();
+ void on_setting_changed(const QString &key, const QVariant &value);
+
private:
void setup_ui();
connect(analog_data, SIGNAL(min_max_changed(float, float)),
this, SLOT(on_min_max_changed(float, float)));
- GlobalSettings::register_change_handler(GlobalSettings::Key_View_ConversionThresholdDispMode,
- bind(&AnalogSignal::on_settingViewConversionThresholdDispMode_changed, this, _1));
+ GlobalSettings::add_change_handler(this);
GlobalSettings gs;
conversion_threshold_disp_mode_ =
update_scale();
}
+AnalogSignal::~AnalogSignal()
+{
+ GlobalSettings::remove_change_handler(this);
+}
+
shared_ptr<pv::data::SignalData> AnalogSignal::data() const
{
return base_->analog_data();
update_scale();
}
+void AnalogSignal::on_setting_changed(const QString &key, const QVariant &value)
+{
+ if (key == GlobalSettings::Key_View_ConversionThresholdDispMode)
+ on_settingViewConversionThresholdDispMode_changed(value);
+}
+
void AnalogSignal::paint_back(QPainter &p, ViewItemPaintParams &pp)
{
if (!base_->enabled())
#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_ANALOGSIGNAL_HPP
#define PULSEVIEW_PV_VIEWS_TRACEVIEW_ANALOGSIGNAL_HPP
-#include "signal.hpp"
-
#include <memory>
#include <QComboBox>
#include <QSpinBox>
+#include <pv/globalsettings.hpp>
+#include <pv/views/trace/signal.hpp>
+
using std::pair;
using std::shared_ptr;
namespace views {
namespace trace {
-class AnalogSignal : public Signal
+class AnalogSignal : public Signal, public GlobalSettingsInterface
{
Q_OBJECT
public:
AnalogSignal(pv::Session &session, shared_ptr<data::SignalBase> base);
- virtual ~AnalogSignal() = default;
+ ~AnalogSignal();
shared_ptr<pv::data::SignalData> data() const;
*/
void scale_handle_drag_release();
+ void on_setting_changed(const QString &key, const QVariant &value);
+
/**
* Paints the background layer of the signal with a QPainter
* @param p the QPainter to paint into.
GlobalSettings settings;
coloured_bg_ = settings.value(GlobalSettings::Key_View_ColouredBG).toBool();
- GlobalSettings::register_change_handler(GlobalSettings::Key_View_TriggerIsZeroTime,
- bind(&View::on_settingViewTriggerIsZeroTime_changed, this, _1));
+ GlobalSettings::add_change_handler(this);
connect(scrollarea_->horizontalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(h_scroll_value_changed(int)));
set_segment_display_mode(segment_display_mode_);
}
+View::~View()
+{
+ GlobalSettings::remove_change_handler(this);
+}
+
Session& View::session()
{
return session_;
i->animate_to_layout_v_offset();
}
+void View::on_setting_changed(const QString &key, const QVariant &value)
+{
+ if (key == GlobalSettings::Key_View_TriggerIsZeroTime)
+ on_settingViewTriggerIsZeroTime_changed(value);
+}
+
void View::trigger_event(int segment_id, util::Timestamp location)
{
// TODO This doesn't work if we're showing multiple segments at once
#include <QSizeF>
#include <QSplitter>
-#include <pv/data/signaldata.hpp>
+#include <pv/globalsettings.hpp>
#include <pv/util.hpp>
+#include <pv/data/signaldata.hpp>
#include <pv/views/viewbase.hpp>
#include "cursorpair.hpp"
bool viewportEvent(QEvent *event);
};
-class View : public ViewBase, public TraceTreeItemOwner
+class View : public ViewBase, public TraceTreeItemOwner, public GlobalSettingsInterface
{
Q_OBJECT
public:
explicit View(Session &session, bool is_main_view=false, QWidget *parent = nullptr);
+ ~View();
+
Session& session();
const Session& session() const;
void restack_all_trace_tree_items();
+ void on_setting_changed(const QString &key, const QVariant &value);
+
Q_SIGNALS:
void hover_point_changed(const QPoint &hp);