ctkDICOMTableManager.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. // CTK includes
  15. #include "ctkDICOMTableManager.h"
  16. #include "ctkDICOMTableView.h"
  17. #include "ui_ctkDICOMTableManager.h"
  18. // Qt includes
  19. #include <QHBoxLayout>
  20. #include <QVBoxLayout>
  21. #include <QResizeEvent>
  22. #include <QSplitter>
  23. class ctkDICOMTableManagerPrivate : public Ui_ctkDICOMTableManager
  24. {
  25. Q_DECLARE_PUBLIC(ctkDICOMTableManager)
  26. protected:
  27. ctkDICOMTableManager* const q_ptr;
  28. public:
  29. ctkDICOMTableManagerPrivate(ctkDICOMTableManager& obj);
  30. ~ctkDICOMTableManagerPrivate();
  31. void init();
  32. void setDICOMDatabase(ctkDICOMDatabase *db);
  33. ctkDICOMDatabase* dicomDatabase;
  34. bool m_DynamicLayout;
  35. };
  36. //------------------------------------------------------------------------------
  37. ctkDICOMTableManagerPrivate::ctkDICOMTableManagerPrivate(ctkDICOMTableManager &obj)
  38. : q_ptr(&obj)
  39. , m_DynamicLayout(false)
  40. {
  41. }
  42. //------------------------------------------------------------------------------
  43. ctkDICOMTableManagerPrivate::~ctkDICOMTableManagerPrivate()
  44. {
  45. }
  46. //------------------------------------------------------------------------------
  47. void ctkDICOMTableManagerPrivate::init()
  48. {
  49. //setup UI
  50. Q_Q(ctkDICOMTableManager);
  51. this->setupUi(q);
  52. this->patientsTable->setQueryTableName("Patients");
  53. this->studiesTable->setQueryTableName("Studies");
  54. this->studiesTable->setQueryForeignKey("PatientsUID");
  55. this->seriesTable->setQueryTableName("Series");
  56. this->seriesTable->setQueryForeignKey("StudyInstanceUID");
  57. // For propagating patient selection changes
  58. QObject::connect(this->patientsTable, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
  59. q, SIGNAL(patientsSelectionChanged(const QItemSelection&, const QItemSelection&)));
  60. QObject::connect(this->patientsTable, SIGNAL(selectionChanged(const QStringList&)),
  61. q, SIGNAL(patientsSelectionChanged(const QStringList&)));
  62. // For propagating study selection changes
  63. QObject::connect(this->studiesTable, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
  64. q, SIGNAL(studiesSelectionChanged(const QItemSelection&, const QItemSelection&)));
  65. QObject::connect(this->studiesTable, SIGNAL(selectionChanged(const QStringList&)),
  66. q, SIGNAL(studiesSelectionChanged(const QStringList&)));
  67. // For propagating series selection changes
  68. QObject::connect(this->seriesTable, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
  69. q, SIGNAL(seriesSelectionChanged(const QItemSelection&, const QItemSelection&)));
  70. QObject::connect(this->seriesTable, SIGNAL(selectionChanged(const QStringList&)),
  71. q, SIGNAL(seriesSelectionChanged(const QStringList&)));
  72. QObject::connect(this->seriesTable, SIGNAL(doubleClicked(const QModelIndex&)),
  73. q, SIGNAL(seriesDoubleClicked(const QModelIndex&)));
  74. }
  75. //------------------------------------------------------------------------------
  76. void ctkDICOMTableManagerPrivate::setDICOMDatabase(ctkDICOMDatabase* db)
  77. {
  78. this->patientsTable->setDicomDataBase(db);
  79. this->studiesTable->setDicomDataBase(db);
  80. this->seriesTable->setDicomDataBase(db);
  81. this->dicomDatabase = db;
  82. }
  83. //----------------------------------------------------------------------------
  84. // ctkDICOMTableManager methods
  85. //----------------------------------------------------------------------------
  86. ctkDICOMTableManager::ctkDICOMTableManager(QWidget *parent)
  87. :Superclass(parent)
  88. , d_ptr(new ctkDICOMTableManagerPrivate(*this))
  89. {
  90. Q_D(ctkDICOMTableManager);
  91. d->init();
  92. }
  93. //------------------------------------------------------------------------------
  94. ctkDICOMTableManager::ctkDICOMTableManager(ctkDICOMDatabase *db, QWidget *parent)
  95. : Superclass(parent)
  96. , d_ptr(new ctkDICOMTableManagerPrivate(*this))
  97. {
  98. Q_D(ctkDICOMTableManager);
  99. d->init();
  100. d->setDICOMDatabase(db);
  101. }
  102. //------------------------------------------------------------------------------
  103. ctkDICOMTableManager::~ctkDICOMTableManager()
  104. {
  105. }
  106. //------------------------------------------------------------------------------
  107. void ctkDICOMTableManager::setDICOMDatabase(ctkDICOMDatabase* db)
  108. {
  109. Q_D(ctkDICOMTableManager);
  110. d->setDICOMDatabase(db);
  111. }
  112. //------------------------------------------------------------------------------
  113. void ctkDICOMTableManager::setTableOrientation(const Qt::Orientation &o) const
  114. {
  115. Q_D(const ctkDICOMTableManager);
  116. d->tableSplitter->setOrientation(o);
  117. }
  118. //------------------------------------------------------------------------------
  119. Qt::Orientation ctkDICOMTableManager::tableOrientation()
  120. {
  121. Q_D(ctkDICOMTableManager);
  122. return d->tableSplitter->orientation();
  123. }
  124. //------------------------------------------------------------------------------
  125. QStringList ctkDICOMTableManager::currentPatientsSelection()
  126. {
  127. Q_D(ctkDICOMTableManager);
  128. return d->patientsTable->currentSelection();
  129. }
  130. QStringList ctkDICOMTableManager::currentStudiesSelection()
  131. {
  132. Q_D(ctkDICOMTableManager);
  133. return d->studiesTable->currentSelection();
  134. }
  135. QStringList ctkDICOMTableManager::currentSeriesSelection()
  136. {
  137. Q_D(ctkDICOMTableManager);
  138. return d->seriesTable->currentSelection();
  139. }
  140. void ctkDICOMTableManager::onPatientsQueryChanged(const QStringList &uids)
  141. {
  142. Q_D(ctkDICOMTableManager);
  143. const std::pair<QString, QStringList> patientCondition("Patients.UID", uids);
  144. d->seriesTable->addSqlWhereCondition(patientCondition);
  145. d->studiesTable->addSqlWhereCondition(patientCondition);
  146. }
  147. void ctkDICOMTableManager::onStudiesQueryChanged(const QStringList &uids)
  148. {
  149. Q_D(ctkDICOMTableManager);
  150. const std::pair<QString, QStringList> studiesCondition("Studies.StudyInstanceUID", uids);
  151. d->seriesTable->addSqlWhereCondition(studiesCondition);
  152. }
  153. void ctkDICOMTableManager::onPatientsSelectionChanged(const QStringList &uids)
  154. {
  155. std::pair<QString, QStringList> patientCondition;
  156. patientCondition.first = "Patients.UID";
  157. Q_D(ctkDICOMTableManager);
  158. if (!uids.empty())
  159. {
  160. patientCondition.second = uids;
  161. }
  162. else
  163. {
  164. patientCondition.second = d->patientsTable->uidsForAllRows();
  165. }
  166. d->studiesTable->addSqlWhereCondition(patientCondition);
  167. d->seriesTable->addSqlWhereCondition(patientCondition);
  168. }
  169. void ctkDICOMTableManager::onStudiesSelectionChanged(const QStringList &uids)
  170. {
  171. std::pair<QString, QStringList> studiesCondition;
  172. studiesCondition.first = "Studies.StudyInstanceUID";
  173. Q_D(ctkDICOMTableManager);
  174. if (!uids.empty())
  175. {
  176. studiesCondition.second = uids;
  177. }
  178. else
  179. {
  180. studiesCondition.second = d->studiesTable->uidsForAllRows();
  181. }
  182. d->seriesTable->addSqlWhereCondition(studiesCondition);
  183. }
  184. void ctkDICOMTableManager::setDynamicTableLayout(bool dynamic)
  185. {
  186. Q_D(ctkDICOMTableManager);
  187. d->m_DynamicLayout = dynamic;
  188. }
  189. bool ctkDICOMTableManager::dynamicTableLayout()
  190. {
  191. Q_D(ctkDICOMTableManager);
  192. return d->m_DynamicLayout;
  193. }
  194. void ctkDICOMTableManager::resizeEvent(QResizeEvent *e)
  195. {
  196. this->Superclass::resizeEvent(e);
  197. Q_D(ctkDICOMTableManager);
  198. if (!d->m_DynamicLayout)
  199. return;
  200. //Minimum size = 800 * 1.28 = 1024 => use horizontal layout (otherwise table size would be too small)
  201. this->setTableOrientation(e->size().width() > 1.28*this->minimumWidth() ? Qt::Horizontal : Qt::Vertical);
  202. }