]> sigrok.org Git - pulseview.git/commitdiff
ViewWidget: Moved in unified accept_drag
authorJoel Holdsworth <redacted>
Tue, 23 Dec 2014 11:06:20 +0000 (11:06 +0000)
committerJoel Holdsworth <redacted>
Mon, 29 Dec 2014 12:24:23 +0000 (12:24 +0000)
pv/view/header.cpp
pv/view/header.hpp
pv/view/marginwidget.hpp
pv/view/ruler.cpp
pv/view/ruler.hpp
pv/view/viewwidget.cpp
pv/view/viewwidget.hpp

index 49a846e286a594a76db1a74063595c1accdab13a..3530d891b5f7edf6bde111c70f7202ab2849e718 100644 (file)
@@ -94,21 +94,6 @@ shared_ptr<ViewItem> Header::get_mouse_over_item(const QPoint &pt)
        return shared_ptr<RowItem>();
 }
 
        return shared_ptr<RowItem>();
 }
 
-bool Header::accept_drag() const
-{
-       // Check all the drag items share a common owner
-       RowItemOwner *item_owner = nullptr;
-       for (shared_ptr<RowItem> 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;
 void Header::drag_items(const QPoint &delta)
 {
        RowItemOwner *item_owner = nullptr;
index f12d23ca5852f40a1707301e38b2d4de22910fec..6756681624a4f6aaf2abf423c529098b44ba7423 100644 (file)
@@ -74,12 +74,6 @@ private:
        std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
                const QPoint &pt);
 
        std::shared_ptr<pv::view::ViewItem> 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.
        /**
         * Drag the dragging items by the delta offset.
         * @param delta the drag offset in pixels.
index 308d9348d12a0341aa6a203cd1b214a8c74839cf..2178003f00969584c309d7832c6a09b2dab756c0 100644 (file)
@@ -67,12 +67,6 @@ protected:
         */
        void show_popup(const std::shared_ptr<ViewItem> &item);
 
         */
        void show_popup(const std::shared_ptr<ViewItem> &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.
        /**
         * Drag the dragging items by the delta offset.
         * @param delta the drag offset in pixels.
index a8cf63540a0cb239645b1cb3e4e5131743caac1e..0149155d24c300e0bbd8b68127548ac1d4416ac9 100644 (file)
@@ -83,11 +83,6 @@ shared_ptr<ViewItem> Ruler::get_mouse_over_item(const QPoint &pt)
        return nullptr;
 }
 
        return nullptr;
 }
 
-bool Ruler::accept_drag() const
-{
-       return true;
-}
-
 void Ruler::drag_items(const QPoint &delta)
 {
        const vector< shared_ptr<TimeItem> > items(view_.time_items());
 void Ruler::drag_items(const QPoint &delta)
 {
        const vector< shared_ptr<TimeItem> > items(view_.time_items());
index 6559f6f09cd770d2c0060a2eb1273ea4112a6d39..c93586e169a799d9606ee3ca9666a0cf37ea6c9c 100644 (file)
@@ -73,12 +73,6 @@ private:
        std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
                const QPoint &pt);
 
        std::shared_ptr<pv::view::ViewItem> 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.
        /**
         * Drag the dragging items by the delta offset.
         * @param delta the drag offset in pixels.
index 357b6fea5648d3f3dba4908b9d04c22624a6d266..9408a2de6b6793968317207aff32452e593054be 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <algorithm>
+
+#include "rowitem.hpp"
+#include "timeitem.hpp"
 #include "view.hpp"
 #include "viewwidget.hpp"
 
 #include "view.hpp"
 #include "viewwidget.hpp"
 
+using std::any_of;
+using std::shared_ptr;
+using std::vector;
+
 namespace pv {
 namespace view {
 
 namespace pv {
 namespace view {
 
@@ -30,5 +38,37 @@ ViewWidget::ViewWidget(View &parent) :
 {
 }
 
 {
 }
 
+bool ViewWidget::accept_drag() const
+{
+       const vector< shared_ptr<TimeItem> > items(view_.time_items());
+
+       const bool any_row_items_selected = any_of(view_.begin(), view_.end(),
+               [](const shared_ptr<RowItem> &r) { return r->selected(); });
+
+       const bool any_time_items_selected = any_of(items.begin(), items.end(),
+               [](const shared_ptr<TimeItem> &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<RowItem> 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
 } // namespace view
 } // namespace pv
index 5c8889e3be4cde76d2b91bc6724dd848d7bcb19a..1989fe13e7d9b44925d82d3c852dd29df1995978 100644 (file)
@@ -35,6 +35,12 @@ class ViewWidget : public QWidget
 protected:
        ViewWidget(View &parent);
 
 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_;
 };
 protected:
        pv::view::View &view_;
 };