]> sigrok.org Git - pulseview.git/commitdiff
Flag: Added flag time markers
authorJoel Holdsworth <redacted>
Sat, 13 Dec 2014 12:56:21 +0000 (12:56 +0000)
committerJoel Holdsworth <redacted>
Sun, 28 Dec 2014 18:52:53 +0000 (18:52 +0000)
CMakeLists.txt
pv/view/cursorheader.cpp
pv/view/cursorheader.hpp
pv/view/flag.cpp [new file with mode: 0644]
pv/view/flag.hpp [new file with mode: 0644]
pv/view/timemarker.hpp
pv/view/view.cpp
pv/view/view.hpp
test/CMakeLists.txt

index 401f918d82fd61c23b48b283be651d11d9bc65d3..af6ee35782d4fccb06988048e4776857164ac764 100644 (file)
@@ -170,6 +170,7 @@ set(pulseview_SOURCES
        pv/view/cursor.cpp
        pv/view/cursorheader.cpp
        pv/view/cursorpair.cpp
+       pv/view/flag.cpp
        pv/view/header.cpp
        pv/view/marginwidget.cpp
        pv/view/logicsignal.cpp
@@ -214,6 +215,7 @@ set(pulseview_HEADERS
        pv/toolbars/samplingbar.hpp
        pv/view/cursor.hpp
        pv/view/cursorheader.hpp
+       pv/view/flag.hpp
        pv/view/header.hpp
        pv/view/logicsignal.hpp
        pv/view/marginwidget.hpp
index c324410a75cb873aaed571cea402f23981ad36ec..2683e9e6b20c8fc10c9d81f5bfd10dadb14f95fa 100644 (file)
@@ -157,5 +157,10 @@ void CursorHeader::leaveEvent(QEvent*)
        update();
 }
 
+void CursorHeader::mouseDoubleClickEvent(QMouseEvent *e)
+{
+       view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale());
+}
+
 } // namespace view
 } // namespace pv
index 5ae2a253fc6afcf0d556bd64d65eb5c8c37ea4c9..8db6408622d76430ac0cd39cece7699aae80f1cc 100644 (file)
@@ -60,6 +60,8 @@ private:
        void mouseReleaseEvent(QMouseEvent *);
        void leaveEvent(QEvent*);
 
+       void mouseDoubleClickEvent(QMouseEvent *e);
+
        int calculateTextHeight();
 
        std::shared_ptr<TimeItem> mouse_down_item_;
diff --git a/pv/view/flag.cpp b/pv/view/flag.cpp
new file mode 100644 (file)
index 0000000..53b0fee
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "timemarker.hpp"
+#include "view.hpp"
+
+#include <QColor>
+#include <QFormLayout>
+#include <QLineEdit>
+
+#include <libsigrok/libsigrok.hpp>
+
+#include <pv/widgets/popup.hpp>
+
+using std::shared_ptr;
+
+namespace pv {
+namespace view {
+
+const QColor Flag::FillColour(0x73, 0xD2, 0x16);
+
+Flag::Flag(View &view, double time, const QString &text) :
+       TimeMarker(view, FillColour, time),
+       text_(text)
+{
+}
+
+Flag::Flag(const Flag &flag) :
+       TimeMarker(flag.view_, FillColour, flag.time_)
+{
+}
+
+bool Flag::enabled() const
+{
+       return true;
+}
+
+QString Flag::get_text() const
+{
+       return text_;
+}
+
+pv::widgets::Popup* Flag::create_popup(QWidget *parent)
+{
+       pv::widgets::Popup *const popup = TimeMarker::create_popup(parent);
+       QFormLayout *const form = (QFormLayout*)popup->layout();
+
+       QLineEdit *const text_edit = new QLineEdit(popup);
+       text_edit->setText(text_);
+
+       connect(text_edit, SIGNAL(textChanged(const QString&)),
+               this, SLOT(on_text_changed(const QString&)));
+
+       form->insertRow(0, tr("Text"), text_edit);
+
+       return popup;
+}
+
+void Flag::on_text_changed(const QString &text)
+{
+       text_ = text;
+       view_.time_item_appearance_changed(true, false);
+}
+
+} // namespace view
+} // namespace pv
diff --git a/pv/view/flag.hpp b/pv/view/flag.hpp
new file mode 100644 (file)
index 0000000..659d5cc
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_VIEW_FLAG_H
+#define PULSEVIEW_PV_VIEW_FLAG_H
+
+#include "timemarker.hpp"
+
+namespace pv {
+namespace view {
+
+class Flag : public TimeMarker
+{
+       Q_OBJECT
+
+public:
+       static const QColor FillColour;
+
+public:
+       /**
+        * Constructor.
+        * @param view A reference to the view that owns this cursor pair.
+        * @param time The time to set the flag to.
+        * @param text The text of the marker.
+        */
+       Flag(View &view, double time, const QString &text);
+
+       /**
+        * Copy constructor.
+        */
+       Flag(const Flag &flag);
+
+       /**
+        * Returns true if the item is visible and enabled.
+        */
+       bool enabled() const;
+
+       /**
+        * Gets the text to show in the marker.
+        */
+       QString get_text() const;
+
+       pv::widgets::Popup* create_popup(QWidget *parent);
+
+private Q_SLOTS:
+       void on_text_changed(const QString &text);
+
+private:
+       QString text_;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PULSEVIEW_PV_VIEW_FLAG_H
index 864a4e3865dc007c722cedbee04179f5c437e49e..9cab1fc6d0a96e666069e635c564a0d62ac80ab5 100644 (file)
@@ -98,7 +98,7 @@ public:
         **/
        void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
 
-       pv::widgets::Popup* create_popup(QWidget *parent);
+       virtual pv::widgets::Popup* create_popup(QWidget *parent);
 
 private Q_SLOTS:
        void on_value_changed(double value);
index d58e074a3ef72ec77bc3e75c3487dac627cbb15d..e43522577e9c985e3808d5cf5edce5b5c4365017 100644 (file)
@@ -60,7 +60,6 @@ using pv::data::SignalData;
 using pv::data::Segment;
 using pv::util::format_time;
 
-using std::back_inserter;
 using std::deque;
 using std::dynamic_pointer_cast;
 using std::list;
@@ -105,6 +104,7 @@ View::View(Session &session, QWidget *parent) :
        tick_prefix_(0),
        show_cursors_(false),
        cursors_(new CursorPair(*this)),
+       next_flag_text_('A'),
        hover_point_(-1, -1)
 {
        connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
@@ -192,7 +192,8 @@ const Viewport* View::viewport() const
 
 vector< shared_ptr<TimeItem> > View::time_items() const
 {
-       vector< shared_ptr<TimeItem> > items;
+       const vector<shared_ptr<Flag>> f(flags());
+       vector<shared_ptr<TimeItem>> items(f.begin(), f.end());
        items.push_back(cursors_);
        items.push_back(cursors_->first());
        items.push_back(cursors_->second());
@@ -364,6 +365,32 @@ std::shared_ptr<CursorPair> View::cursors() const
        return cursors_;
 }
 
+void View::add_flag(double time)
+{
+       flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
+               QString("%1").arg(next_flag_text_))));
+       next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
+               (next_flag_text_ + 1);
+       time_item_appearance_changed(true, true);
+}
+
+void View::remove_flag(std::shared_ptr<Flag> flag)
+{
+       flags_.remove(flag);
+       time_item_appearance_changed(true, true);
+}
+
+vector< std::shared_ptr<Flag> > View::flags() const
+{
+       vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end());
+       stable_sort(flags.begin(), flags.end(),
+               [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) {
+                       return a->time() < b->time();
+               });
+
+       return flags;
+}
+
 const QPoint& View::hover_point() const
 {
        return hover_point_;
index 6a249c22db4af0742861d5b07aa6315f36e4c017..6b7841f926ed105450a6181fe199e2b3eb2ed222 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <stdint.h>
 
+#include <list>
 #include <memory>
 #include <set>
 #include <unordered_map>
@@ -35,6 +36,7 @@
 #include <pv/data/signaldata.hpp>
 
 #include "cursorpair.hpp"
+#include "flag.hpp"
 #include "rowitemowner.hpp"
 
 namespace pv {
@@ -161,6 +163,21 @@ public:
         */
        std::shared_ptr<CursorPair> cursors() const;
 
+       /**
+        * Adds a new flag at a specified time.
+        */
+       void add_flag(double time);
+
+       /**
+        * Removes a flag from the list.
+        */
+       void remove_flag(std::shared_ptr<Flag> flag);
+
+       /**
+        * Gets the list of flags.
+        */
+       std::vector< std::shared_ptr<Flag> > flags() const;
+
        const QPoint& hover_point() const;
 
        void update_viewport();
@@ -273,6 +290,9 @@ private:
        bool show_cursors_;
        std::shared_ptr<CursorPair> cursors_;
 
+       std::list< std::shared_ptr<Flag> > flags_;
+       char next_flag_text_;
+
        QPoint hover_point_;
 
        unsigned int sticky_events_;
index b1fc61caa7799e895a14e30269243b3a3e3a8751..494f8dda5f5a9605934965ee3215eb24dd55f5a7 100644 (file)
@@ -42,6 +42,7 @@ set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/view/cursor.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/cursorheader.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/cursorpair.cpp
+       ${PROJECT_SOURCE_DIR}/pv/view/flag.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/header.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/marginwidget.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/logicsignal.cpp
@@ -84,6 +85,7 @@ set(pulseview_TEST_HEADERS
        ${PROJECT_SOURCE_DIR}/pv/prop/binding/deviceoptions.hpp
        ${PROJECT_SOURCE_DIR}/pv/view/cursor.hpp
        ${PROJECT_SOURCE_DIR}/pv/view/cursorheader.hpp
+       ${PROJECT_SOURCE_DIR}/pv/view/flag.hpp
        ${PROJECT_SOURCE_DIR}/pv/view/header.hpp
        ${PROJECT_SOURCE_DIR}/pv/view/logicsignal.hpp
        ${PROJECT_SOURCE_DIR}/pv/view/marginwidget.hpp