소스 검색

DICOMTableView: Do not clear selection if user click outside of existing rows

Fixes #545

This is done by installing an event filter on the tableview viewport that
will block the mouse press and double click event if no row are pointed
by the cursor.

Reported-by: Sergey Aleshin <4memph@gmail.com>
Jean-Christophe Fillion-Robin 10 년 전
부모
커밋
de70697141
2개의 변경된 파일27개의 추가작업 그리고 0개의 파일을 삭제
  1. 24 0
      Libs/DICOM/Widgets/ctkDICOMTableView.cpp
  2. 3 0
      Libs/DICOM/Widgets/ctkDICOMTableView.h

+ 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()
     {
       this->setUpTableView();
     }
+
+  this->tblDicomDatabaseView->viewport()->installEventFilter(q);
 }
 
 //------------------------------------------------------------------------------
@@ -298,6 +302,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