浏览代码

Created initial table view

Andreas Fetzer 12 年之前
父节点
当前提交
cc8d2d066e

+ 4 - 0
Libs/DICOM/Widgets/CMakeLists.txt

@@ -35,6 +35,8 @@ set(KIT_SRCS
   ctkDICOMThumbnailGenerator.h
   ctkDICOMThumbnailListWidget.cpp
   ctkDICOMThumbnailListWidget.h
+  ctkDICOMTableView.cpp
+  ctkDICOMTableView.h
   )
 
 # Headers that should run through moc
@@ -50,6 +52,7 @@ set(KIT_MOC_SRCS
   ctkDICOMServerNodeWidget.h
   ctkDICOMThumbnailGenerator.h
   ctkDICOMThumbnailListWidget.h
+  ctkDICOMTableView.h
   )
 
 # UI files - includes new widgets
@@ -62,6 +65,7 @@ set(KIT_UI_FORMS
   Resources/UI/ctkDICOMQueryRetrieveWidget.ui
   Resources/UI/ctkDICOMQueryWidget.ui
   Resources/UI/ctkDICOMServerNodeWidget.ui
+  Resources/UI/ctkDICOMTableView.ui
 )
 
 # Resources

+ 72 - 0
Libs/DICOM/Widgets/Resources/UI/ctkDICOMTableView.ui

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkDICOMTableView</class>
+ <widget class="QWidget" name="ctkDICOMTableView">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>794</width>
+    <height>462</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLineEdit" name="leSearchBox">
+       <property name="styleSheet">
+        <string notr="true">color: rgb(188, 188, 188);
+font: 14pt &quot;Lucida Grande&quot;;</string>
+       </property>
+       <property name="text">
+        <string/>
+       </property>
+       <property name="placeholderText">
+        <string>Search...</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pBDeleteSearch">
+       <property name="text">
+        <string/>
+       </property>
+       <property name="icon">
+        <iconset resource="../../../../Widgets/Resources/ctkWidgets.qrc">
+         <normaloff>:/Icons/clear.svg</normaloff>:/Icons/clear.svg</iconset>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QTableView" name="tblDicomDatabaseView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources>
+  <include location="../../../../Widgets/Resources/ctkWidgets.qrc"/>
+ </resources>
+ <connections>
+  <connection>
+   <sender>pBDeleteSearch</sender>
+   <signal>clicked()</signal>
+   <receiver>leSearchBox</receiver>
+   <slot>clear()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>743</x>
+     <y>30</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>680</x>
+     <y>29</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>

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

@@ -0,0 +1,130 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// ctkDICOMWidget includes
+#include "ctkDICOMTableView.h"
+#include "ui_ctkDICOMTableView.h"
+
+// Qt includes
+#include <QSqlQueryModel>
+#include <QSortFilterProxyModel>
+
+
+class ctkDICOMTableViewPrivate : public Ui_ctkDICOMTableView
+{
+  Q_DECLARE_PUBLIC (ctkDICOMTableView)
+
+protected:
+  ctkDICOMTableView* const q_ptr;
+
+public:
+  ctkDICOMTableViewPrivate(ctkDICOMTableView& obj);
+  ~ctkDICOMTableViewPrivate();
+  void init();
+
+  QSharedPointer<ctkDICOMDatabase> ctkDICOMDatabase;
+  QSqlQueryModel DICOMSQLModel;
+  QSortFilterProxyModel* DICOMSQLFilterModel;
+};
+
+ctkDICOMTableViewPrivate::ctkDICOMTableViewPrivate(ctkDICOMTableView &obj)
+  : q_ptr(&obj)
+{
+  this->DICOMSQLFilterModel = new QSortFilterProxyModel();
+}
+
+ctkDICOMTableViewPrivate::~ctkDICOMTableViewPrivate()
+{
+  delete this->DICOMSQLFilterModel;
+}
+
+void ctkDICOMTableViewPrivate::init()
+{
+  Q_Q(ctkDICOMTableView);
+  this->setupUi(q);
+
+  //TODO need model information
+//  this->tblDicomDatabaseView->setModel(QSqlTableModel);
+
+  this->tblDicomDatabaseView->setSelectionBehavior(QAbstractItemView::SelectRows);
+  this->tblDicomDatabaseView->setSelectionMode(QAbstractItemView::SingleSelection);
+//  this->tblDicomDatabaseView->setColumnHidden(1, true);
+
+  QObject::connect(this->tblDicomDatabaseView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+                   q, SLOT(onSelectionChanged(const QItemSelection &,const QItemSelection &)));
+}
+
+//----------------------------------------------------------------------------
+// ctkDICOMTableView methods
+
+//----------------------------------------------------------------------------
+ctkDICOMTableView::ctkDICOMTableView(QWidget *parent)
+  :Superclass(parent)
+  , d_ptr(new ctkDICOMTableViewPrivate(*this))
+{
+  Q_D(ctkDICOMTableView);
+  d->init();
+}
+
+ctkDICOMTableView::ctkDICOMTableView(QWidget *parent, QSharedPointer<ctkDICOMDatabase> ctkDicomDataBase)
+  : Superclass(parent)
+  , d_ptr(new ctkDICOMTableViewPrivate(*this))
+{
+  Q_D(ctkDICOMTableView);
+//  d->ctkDICOMDatabase = ctkDicomDataBase;
+  this->setCTKDicomDataBase(ctkDicomDataBase);
+}
+
+ctkDICOMTableView::~ctkDICOMTableView()
+{
+}
+
+void ctkDICOMTableView::setCTKDicomDataBase(QSharedPointer<ctkDICOMDatabase> dicomDataBase)
+{
+  Q_D(ctkDICOMTableView);
+  d->ctkDICOMDatabase = dicomDataBase;
+  if (d->ctkDICOMDatabase)
+  {
+    d->DICOMSQLModel.setQuery("select * from Patients", d->ctkDICOMDatabase->database());
+    d->DICOMSQLFilterModel->setSourceModel(&d->DICOMSQLModel);
+    d->DICOMSQLFilterModel->setFilterKeyColumn(-1);
+    d->DICOMSQLFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
+    QObject::connect(d->leSearchBox, SIGNAL(textChanged(QString)), d->DICOMSQLFilterModel, SLOT(setFilterWildcard(QString)));
+    d->tblDicomDatabaseView->setModel(d->DICOMSQLFilterModel);
+
+    QObject::connect(d->ctkDICOMDatabase.data(), SIGNAL(databaseChanged()), this, SLOT(onDatabaseChanged()));
+
+//    d->tblDicomDatabaseView->setColumnHidden(0, true);
+  }
+}
+
+void ctkDICOMTableView::onSelectionChanged(const QItemSelection &, const QItemSelection &)
+{
+  //Do something
+}
+
+void ctkDICOMTableView::onDatabaseChanged()
+{
+  Q_D(ctkDICOMTableView);
+  d->DICOMSQLModel.setQuery("select * from Patients", d->ctkDICOMDatabase->database());
+
+      d->tblDicomDatabaseView->setColumnHidden(0, true);
+}
+

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

@@ -0,0 +1,67 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef CTKDICOMTABLEVIEW_H
+#define CTKDICOMTABLEVIEW_H
+
+#include "ctkDICOMWidgetsExport.h"
+
+// ctkDICOMCore includes
+#include "ctkDICOMDatabase.h"
+
+// Qt includes
+#include <QWidget>
+#include <QItemSelection>
+
+class ctkDICOMTableViewPrivate;
+
+/// \ingroup DICOM_Widgets
+
+class CTK_DICOM_WIDGETS_EXPORT ctkDICOMTableView : public QWidget
+{
+  Q_OBJECT
+
+public:
+  typedef QWidget Superclass;
+
+  explicit ctkDICOMTableView(QWidget* parent = 0);
+  ctkDICOMTableView (QWidget* parent, QSharedPointer<ctkDICOMDatabase> ctkDicomDataBase);
+  virtual ~ctkDICOMTableView();
+
+  void setCTKDicomDataBase(QSharedPointer<ctkDICOMDatabase> dicomDataBase);
+
+  // Settings for QTableView
+  void hideColumn(int column);
+
+public Q_SLOTS:
+  void onSelectionChanged(const QItemSelection &, const QItemSelection &);
+
+protected Q_SLOTS:
+  void onDatabaseChanged();
+
+protected:
+  QScopedPointer<ctkDICOMTableViewPrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkDICOMTableView)
+  Q_DISABLE_COPY(ctkDICOMTableView)
+};
+
+#endif // CTKDICOMTABLEVIEW_H