From: Joel Holdsworth Date: Tue, 23 Dec 2014 11:06:20 +0000 (+0000) Subject: ViewWidget: Moved in unified accept_drag X-Git-Tag: pulseview-0.3.0~305 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=b434cbaf3208c2037fd5f86001b367b46ba926ba ViewWidget: Moved in unified accept_drag --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 49a846e2..3530d891 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -94,21 +94,6 @@ shared_ptr Header::get_mouse_over_item(const QPoint &pt) return shared_ptr(); } -bool Header::accept_drag() const -{ - // Check all the drag items share a common owner - RowItemOwner *item_owner = nullptr; - for (shared_ptr r : view_) - if (r->dragging()) { - if (!item_owner) - item_owner = r->owner(); - else if(item_owner != r->owner()) - return false; - } - - return item_owner; -} - void Header::drag_items(const QPoint &delta) { RowItemOwner *item_owner = nullptr; diff --git a/pv/view/header.hpp b/pv/view/header.hpp index f12d23ca..67566816 100644 --- a/pv/view/header.hpp +++ b/pv/view/header.hpp @@ -74,12 +74,6 @@ private: std::shared_ptr get_mouse_over_item( const QPoint &pt); - /** - * Returns true if the selection of row items allows dragging. - * @return Returns true if the drag is acceptable. - */ - bool accept_drag() const; - /** * Drag the dragging items by the delta offset. * @param delta the drag offset in pixels. diff --git a/pv/view/marginwidget.hpp b/pv/view/marginwidget.hpp index 308d9348..2178003f 100644 --- a/pv/view/marginwidget.hpp +++ b/pv/view/marginwidget.hpp @@ -67,12 +67,6 @@ protected: */ void show_popup(const std::shared_ptr &item); - /** - * Returns true if the selection of row items allows dragging. - * @return Returns true if the drag is acceptable. - */ - virtual bool accept_drag() const = 0; - /** * Drag the dragging items by the delta offset. * @param delta the drag offset in pixels. diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index a8cf6354..0149155d 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -83,11 +83,6 @@ shared_ptr Ruler::get_mouse_over_item(const QPoint &pt) return nullptr; } -bool Ruler::accept_drag() const -{ - return true; -} - void Ruler::drag_items(const QPoint &delta) { const vector< shared_ptr > items(view_.time_items()); diff --git a/pv/view/ruler.hpp b/pv/view/ruler.hpp index 6559f6f0..c93586e1 100644 --- a/pv/view/ruler.hpp +++ b/pv/view/ruler.hpp @@ -73,12 +73,6 @@ private: std::shared_ptr get_mouse_over_item( const QPoint &pt); - /** - * Returns true if the selection of time items allows dragging. - * @return Returns true if the drag is acceptable. - */ - bool accept_drag() const; - /** * Drag the dragging items by the delta offset. * @param delta the drag offset in pixels. diff --git a/pv/view/viewwidget.cpp b/pv/view/viewwidget.cpp index 357b6fea..9408a2de 100644 --- a/pv/view/viewwidget.cpp +++ b/pv/view/viewwidget.cpp @@ -18,9 +18,17 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + +#include "rowitem.hpp" +#include "timeitem.hpp" #include "view.hpp" #include "viewwidget.hpp" +using std::any_of; +using std::shared_ptr; +using std::vector; + namespace pv { namespace view { @@ -30,5 +38,37 @@ ViewWidget::ViewWidget(View &parent) : { } +bool ViewWidget::accept_drag() const +{ + const vector< shared_ptr > items(view_.time_items()); + + const bool any_row_items_selected = any_of(view_.begin(), view_.end(), + [](const shared_ptr &r) { return r->selected(); }); + + const bool any_time_items_selected = any_of(items.begin(), items.end(), + [](const shared_ptr &i) { return i->selected(); }); + + if (any_row_items_selected && !any_time_items_selected) + { + // Check all the drag items share a common owner + RowItemOwner *item_owner = nullptr; + for (shared_ptr r : view_) + if (r->dragging()) { + if (!item_owner) + item_owner = r->owner(); + else if(item_owner != r->owner()) + return false; + } + + return true; + } + else if (any_time_items_selected && !any_row_items_selected) + { + return true; + } + + return false; +} + } // namespace view } // namespace pv diff --git a/pv/view/viewwidget.hpp b/pv/view/viewwidget.hpp index 5c8889e3..1989fe13 100644 --- a/pv/view/viewwidget.hpp +++ b/pv/view/viewwidget.hpp @@ -35,6 +35,12 @@ class ViewWidget : public QWidget protected: ViewWidget(View &parent); + /** + * Returns true if the selection of row items allows dragging. + * @return Returns true if the drag is acceptable. + */ + bool accept_drag() const; + protected: pv::view::View &view_; };