ctkDICOMTableView.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkDICOMTableView_h
  15. #define __ctkDICOMTableView_h
  16. // Qt includes
  17. #include <QItemSelection>
  18. #include <QWidget>
  19. // ctkDICOMCore includes
  20. #include "ctkDICOMDatabase.h"
  21. #include "ctkDICOMWidgetsExport.h"
  22. class ctkDICOMTableViewPrivate;
  23. class QTableView;
  24. /**
  25. * @brief The ctkDICOMTableView displays the content of a specific table of the ctkDICOMDatabase
  26. *
  27. * The ctkDICOMTableView holds a QTableView which displays the content of the selected
  28. * ctkDICOMDatabase. It also holds a ctkSearchBox which allows filtering of the table content.
  29. *
  30. * @ingroup DICOM_Widgets
  31. */
  32. class CTK_DICOM_WIDGETS_EXPORT ctkDICOMTableView : public QWidget
  33. {
  34. Q_OBJECT
  35. Q_PROPERTY(bool filterActive READ filterActive)
  36. Q_PROPERTY( QTableView* tblDicomDatabaseView READ tableView )
  37. public:
  38. typedef QWidget Superclass;
  39. /**
  40. * Constructs ctkDICOMTableView without underlying database and table name
  41. * @param parent parentwidget
  42. */
  43. explicit ctkDICOMTableView(QWidget* parent = 0);
  44. /**
  45. * ctor with tablename as parameter
  46. * @param parent the parent widget
  47. * @param queryTableName the name of the table of the ctkDICOMDatabase which shall be displayed
  48. */
  49. explicit ctkDICOMTableView(QString queryTableName, QWidget* parent = 0);
  50. /**
  51. * ctor with tablename and database as parameter
  52. * @param ctkDicomDataBase the ctkDICOMDatabase which shall be used
  53. * @param parent the parent widget
  54. * @param queryTableName the name of the table of the ctkDICOMDatabase which shall be displayed
  55. */
  56. explicit ctkDICOMTableView (ctkDICOMDatabase* dicomDataBase, QString queryTableName, QWidget* parent = 0);
  57. virtual ~ctkDICOMTableView();
  58. /**
  59. * @brief Setting the ctkDICOMDatabase which shall be queried
  60. * @param dicomDataBase the underlying database
  61. */
  62. void setDicomDataBase(ctkDICOMDatabase* dicomDatabase);
  63. /**
  64. * Setting the table name which shall be used for the database query
  65. * @param tableName the name of the database table
  66. */
  67. void setQueryTableName(const QString &tableName);
  68. /**
  69. * Setting the foreign key for the database query. This is usefull if e.g. you
  70. * want to select the studies for a certain patient
  71. * @param foreignKey the foreign key which will be used for the query
  72. */
  73. void setQueryForeignKey(const QString &foreignKey);
  74. /**
  75. * Set the query for the underlying database. If the uid list is not empty just the
  76. * entries with the according uids are selected
  77. * @param uids a list of uids which should be selected
  78. */
  79. void setQuery (const QStringList &uids = QStringList());
  80. /**
  81. * @brief Add a where condition to the usual select statement
  82. * @param condition std::pair with column name and a value list
  83. */
  84. void addSqlWhereCondition(const std::pair<QString, QStringList>& condition);
  85. /**
  86. * @brief Returns the uids of the current selected rows
  87. * @return a list containing all the uids of the selected rows
  88. */
  89. QStringList currentSelection() const;
  90. /**
  91. * @brief Getting the UIDs for all rows
  92. * @return a QStringList with the uids for all rows
  93. */
  94. QStringList uidsForAllRows() const;
  95. bool filterActive();
  96. void setTableSectionSize(int);
  97. int tableSectionSize();
  98. /**
  99. * @brief Get the actual QTableView, for specific view settings
  100. * @return a pointer to QTableView* tblDicomDatabaseView
  101. */
  102. QTableView* tableView();
  103. public Q_SLOTS:
  104. /**
  105. * @brief slot is called if the selection of the tableview is changed
  106. * Within this slot the signal signalSelectionChanged is emitted
  107. */
  108. void onSelectionChanged();
  109. /**
  110. * @brief Updates the query which is used for displaying the table content
  111. * @param uids the uids of the table entries which shall be displayed
  112. */
  113. void onUpdateQuery(const QStringList &uids);
  114. /**
  115. * @brief Translates the local point to a global one
  116. * @param point the local point to translate to global
  117. * Emits customContextMenuRequested with the global point
  118. */
  119. void onCustomContextMenuRequested(const QPoint &point);
  120. protected Q_SLOTS:
  121. /**
  122. * @brief Called when the underlying database changes
  123. */
  124. void onDatabaseChanged();
  125. /**
  126. * @brief Called when the text of the ctkSearchBox has changed
  127. */
  128. void onFilterChanged();
  129. /**
  130. * @brief Called if a new instance was added to the database
  131. */
  132. void onInstanceAdded();
  133. void selectAll();
  134. protected:
  135. virtual bool eventFilter(QObject *obj, QEvent *event);
  136. Q_SIGNALS:
  137. /**
  138. * @brief Is emitted when the selection in the tableview has changed
  139. * @param uids the list of uids of the selected objects
  140. */
  141. void selectionChanged(const QStringList &uids);
  142. /**
  143. * @brief Is emitted when the data selection has changed
  144. */
  145. void selectionChanged(const QItemSelection&,const QItemSelection&);
  146. /**
  147. * @brief Is emitted when the query text has changed
  148. * @param uids the list of uids of the objects included in the query
  149. */
  150. void queryChanged(const QStringList &uids);
  151. void doubleClicked(const QModelIndex&);
  152. protected:
  153. QScopedPointer<ctkDICOMTableViewPrivate> d_ptr;
  154. Q_DECLARE_PRIVATE(ctkDICOMTableView)
  155. Q_DISABLE_COPY(ctkDICOMTableView)
  156. };
  157. #endif // __ctkDICOMTableView_h