Selaa lähdekoodia

Merge branch '545-dicomtable-do-not-clear-selection-if-invalid-selection'

* 545-dicomtable-do-not-clear-selection-if-invalid-selection:
  DICOMTableView: Do not clear selection if user click outside of existing rows
Jean-Christophe Fillion-Robin 10 vuotta sitten
vanhempi
commit
3d9721142e

+ 24 - 0
Libs/DICOM/Widgets/ctkDICOMTableView.cpp

@@ -23,6 +23,7 @@
 #include "ui_ctkDICOMTableView.h"
 
 // Qt includes
+#include <QMouseEvent>
 #include <QSortFilterProxyModel>
 #include <QSqlQueryModel>
 
@@ -81,6 +82,7 @@ ctkDICOMTableViewPrivate::~ctkDICOMTableViewPrivate()
 {
 }
 
+//------------------------------------------------------------------------------
 void ctkDICOMTableViewPrivate::init()
 {
   Q_Q(ctkDICOMTableView);
@@ -93,6 +95,8 @@ void ctkDICOMTableViewPrivate::init()
     {
       q->setDicomDataBase(this->dicomDatabase);
     }
+
+  this->tblDicomDatabaseView->viewport()->installEventFilter(q);
 }
 
 //------------------------------------------------------------------------------
@@ -304,6 +308,26 @@ void ctkDICOMTableView::selectAll()
 }
 
 //------------------------------------------------------------------------------
+bool ctkDICOMTableView::eventFilter(QObject *obj, QEvent *event)
+{
+  Q_D(ctkDICOMTableView);
+  if (obj == d->tblDicomDatabaseView->viewport())
+    {
+      if (event->type() == QEvent::MouseButtonPress ||
+          event->type() == QEvent::MouseButtonDblClick)
+        {
+          QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
+          QPoint pos = mouseEvent->pos();
+          if (!d->tblDicomDatabaseView->indexAt(pos).isValid())
+            {
+              return true;
+            }
+        }
+    }
+  return QObject::eventFilter(obj, event);
+}
+
+//------------------------------------------------------------------------------
 void ctkDICOMTableView::setQuery(const QStringList &uids)
 {
   Q_D(ctkDICOMTableView);

+ 3 - 0
Libs/DICOM/Widgets/ctkDICOMTableView.h

@@ -150,6 +150,9 @@ protected Q_SLOTS:
 
   void selectAll();
 
+protected:
+  virtual bool eventFilter(QObject *obj, QEvent *event);
+
 Q_SIGNALS:
   /**
    * @brief Is emitted when the selection in the tableview has changed