]> sigrok.org Git - pulseview.git/blobdiff - pv/views/trace/logicsignal.hpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / views / trace / logicsignal.hpp
index 2f5c66baa219fb69dcb8e9e42e08de1c01ad1849..eee6b9c4ce081f4b74d6ccf30ffe206e6aa6965b 100644 (file)
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_LOGICSIGNAL_HPP
-#define PULSEVIEW_PV_VIEWS_TRACEVIEW_LOGICSIGNAL_HPP
+#ifndef PULSEVIEW_PV_VIEWS_TRACE_LOGICSIGNAL_HPP
+#define PULSEVIEW_PV_VIEWS_TRACE_LOGICSIGNAL_HPP
 
 #include <QCache>
+#include <QColor>
+#include <QDebug>
+#include <QSpinBox>
 
 #include "signal.hpp"
 
@@ -57,50 +60,34 @@ class LogicSignal : public Signal
 public:
        static const float Oversampling;
 
-       static const QColor EdgeColour;
-       static const QColor HighColour;
-       static const QColor LowColour;
-       static const QColor SamplingPointColour;
+       static const QColor EdgeColor;
+       static const QColor HighColor;
+       static const QColor LowColor;
+       static const QColor SamplingPointColor;
 
-       static const QColor SignalColours[10];
-
-       static QColor TriggerMarkerBackgroundColour;
+       static QColor TriggerMarkerBackgroundColor;
        static const int TriggerMarkerPadding;
        static const char* TriggerMarkerIcons[8];
 
-       LogicSignal(pv::Session &session,
-               shared_ptr<devices::Device> device,
-               shared_ptr<data::SignalBase> base);
+       LogicSignal(pv::Session &session, shared_ptr<data::SignalBase> base);
 
        virtual ~LogicSignal() = default;
 
-       shared_ptr<pv::data::SignalData> data() const;
-
-       shared_ptr<pv::data::Logic> logic_data() const;
+       virtual std::map<QString, QVariant> save_settings() const;
+       virtual void restore_settings(std::map<QString, QVariant> settings);
 
        /**
         * Computes the vertical extents of the contents of this row item.
         * @return A pair containing the minimum and maximum y-values.
         */
-       pair<int, int> v_extents() const;
-
-       /**
-        * Returns the offset to show the drag handle.
-        */
-       int scale_handle_offset() const;
-
-       /**
-        * Handles the scale handle being dragged to an offset.
-        * @param offset the offset the scale handle was dragged to.
-        */
-       void scale_handle_dragged(int offset);
+       virtual pair<int, int> v_extents() const;
 
        /**
         * Paints the mid-layer of the signal with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with..
         */
-       void paint_mid(QPainter &p, ViewItemPaintParams &pp);
+       virtual void paint_mid(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the signal with a QPainter
@@ -109,12 +96,23 @@ public:
         */
        virtual void paint_fore(QPainter &p, ViewItemPaintParams &pp);
 
-private:
+       /**
+        * Determines the closest level change (i.e. edge) to a given sample, which
+        * is useful for e.g. the "snap to edge" functionality.
+        *
+        * @param sample_pos Sample to use
+        * @return The changes left and right of the given position
+        */
+       virtual vector<data::LogicSegment::EdgePair> get_nearest_level_changes(uint64_t sample_pos);
+
+protected:
        void paint_caps(QPainter &p, QLineF *const lines,
                vector< pair<int64_t, bool> > &edges,
                bool level, double samples_per_pixel, double pixels_offset,
                float x_offset, float y_offset);
 
+       shared_ptr<pv::data::LogicSegment> get_logic_segment_to_paint() const;
+
        void init_trigger_actions(QWidget *parent);
 
        const vector<int32_t> get_trigger_types() const;
@@ -127,15 +125,24 @@ private:
        static const QIcon* get_icon(const char *path);
        static const QPixmap* get_pixmap(const char *path);
 
-private Q_SLOTS:
+       virtual void update_logic_level_offsets();
+
+protected Q_SLOTS:
+       void on_setting_changed(const QString &key, const QVariant &value);
+
        void on_trigger();
 
-private:
-       int signal_height_;
+       void on_signal_height_changed(int height);
+
+protected:
+       QColor high_fill_color_;
+       bool show_sampling_points_, fill_high_areas_;
+       float high_level_offset_, low_level_offset_;  // y offsets relative to trace
 
-       shared_ptr<pv::devices::Device> device_;
+       QSpinBox *signal_height_sb_;
 
        const sigrok::TriggerMatchType *trigger_match_;
+       const vector<int32_t> trigger_types_;
        QToolBar *trigger_bar_;
        QAction *trigger_none_;
        QAction *trigger_rising_;
@@ -146,10 +153,15 @@ private:
 
        static QCache<QString, const QIcon> icon_cache_;
        static QCache<QString, const QPixmap> pixmap_cache_;
+
+       // ---------------------------------------------------------------------------
+       // Note: Make sure to update save_settings() and restore_settings() when
+       //       adding a trace-configurable variable here
+       int signal_height_;
 };
 
 } // namespace trace
 } // namespace views
 } // namespace pv
 
-#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_LOGICSIGNAL_HPP
+#endif // PULSEVIEW_PV_VIEWS_TRACE_LOGICSIGNAL_HPP