From: Joel Holdsworth Date: Sat, 13 Dec 2014 12:56:21 +0000 (+0000) Subject: Flag: Added flag time markers X-Git-Tag: pulseview-0.3.0~346 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8914fe790fb677c56194a3ae4da06ba671fca78a;p=pulseview.git Flag: Added flag time markers --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 401f918d..af6ee357 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index c324410a..2683e9e6 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -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 diff --git a/pv/view/cursorheader.hpp b/pv/view/cursorheader.hpp index 5ae2a253..8db64086 100644 --- a/pv/view/cursorheader.hpp +++ b/pv/view/cursorheader.hpp @@ -60,6 +60,8 @@ private: void mouseReleaseEvent(QMouseEvent *); void leaveEvent(QEvent*); + void mouseDoubleClickEvent(QMouseEvent *e); + int calculateTextHeight(); std::shared_ptr mouse_down_item_; diff --git a/pv/view/flag.cpp b/pv/view/flag.cpp new file mode 100644 index 00000000..53b0feef --- /dev/null +++ b/pv/view/flag.cpp @@ -0,0 +1,83 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * 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 +#include +#include + +#include + +#include + +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 index 00000000..659d5cc1 --- /dev/null +++ b/pv/view/flag.hpp @@ -0,0 +1,72 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * 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 diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index 864a4e38..9cab1fc6 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -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); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index d58e074a..e4352257 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -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 > View::time_items() const { - vector< shared_ptr > items; + const vector> f(flags()); + vector> 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 View::cursors() const return cursors_; } +void View::add_flag(double time) +{ + flags_.push_back(shared_ptr(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) +{ + flags_.remove(flag); + time_item_appearance_changed(true, true); +} + +vector< std::shared_ptr > View::flags() const +{ + vector< std::shared_ptr > flags(flags_.begin(), flags_.end()); + stable_sort(flags.begin(), flags.end(), + [](const shared_ptr &a, const shared_ptr &b) { + return a->time() < b->time(); + }); + + return flags; +} + const QPoint& View::hover_point() const { return hover_point_; diff --git a/pv/view/view.hpp b/pv/view/view.hpp index 6a249c22..6b7841f9 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -35,6 +36,7 @@ #include #include "cursorpair.hpp" +#include "flag.hpp" #include "rowitemowner.hpp" namespace pv { @@ -161,6 +163,21 @@ public: */ std::shared_ptr 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); + + /** + * Gets the list of flags. + */ + std::vector< std::shared_ptr > flags() const; + const QPoint& hover_point() const; void update_viewport(); @@ -273,6 +290,9 @@ private: bool show_cursors_; std::shared_ptr cursors_; + std::list< std::shared_ptr > flags_; + char next_flag_text_; + QPoint hover_point_; unsigned int sticky_events_; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b1fc61ca..494f8dda 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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