ctkDICOMTableManager.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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_DynamicTableLayout;
  35. };
  36. //------------------------------------------------------------------------------
  37. ctkDICOMTableManagerPrivate::ctkDICOMTableManagerPrivate(ctkDICOMTableManager &obj)
  38. : q_ptr(&obj)
  39. , m_DynamicTableLayout(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. q->setDisplayDensity(ctkDICOMTableManager::Comfortable);
  58. // For propagating patient selection changes
  59. QObject::connect(this->patientsTable, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
  60. q, SIGNAL(patientsSelectionChanged(const QItemSelection&, const QItemSelection&)));
  61. QObject::connect(this->patientsTable, SIGNAL(selectionChanged(const QStringList&)),
  62. q, SIGNAL(patientsSelectionChanged(const QStringList&)));
  63. // For propagating study selection changes
  64. QObject::connect(this->studiesTable, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
  65. q, SIGNAL(studiesSelectionChanged(const QItemSelection&, const QItemSelection&)));
  66. QObject::connect(this->studiesTable, SIGNAL(selectionChanged(const QStringList&)),
  67. q, SIGNAL(studiesSelectionChanged(const QStringList&)));
  68. // For propagating series selection changes
  69. QObject::connect(this->seriesTable, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
  70. q, SIGNAL(seriesSelectionChanged(const QItemSelection&, const QItemSelection&)));
  71. QObject::connect(this->seriesTable, SIGNAL(selectionChanged(const QStringList&)),
  72. q, SIGNAL(seriesSelectionChanged(const QStringList&)));
  73. QObject::connect(this->seriesTable, SIGNAL(doubleClicked(const QModelIndex&)),
  74. q, SIGNAL(seriesDoubleClicked(const QModelIndex&)));
  75. }
  76. //------------------------------------------------------------------------------
  77. void ctkDICOMTableManagerPrivate::setDICOMDatabase(ctkDICOMDatabase* db)
  78. {
  79. this->patientsTable->setDicomDataBase(db);
  80. this->studiesTable->setDicomDataBase(db);
  81. this->seriesTable->setDicomDataBase(db);
  82. this->dicomDatabase = db;
  83. }
  84. //----------------------------------------------------------------------------
  85. // ctkDICOMTableManager methods
  86. //----------------------------------------------------------------------------
  87. ctkDICOMTableManager::ctkDICOMTableManager(QWidget *parent)
  88. :Superclass(parent)
  89. , d_ptr(new ctkDICOMTableManagerPrivate(*this))
  90. {
  91. Q_D(ctkDICOMTableManager);
  92. d->init();
  93. }
  94. //------------------------------------------------------------------------------
  95. ctkDICOMTableManager::ctkDICOMTableManager(ctkDICOMDatabase *db, QWidget *parent)
  96. : Superclass(parent)
  97. , d_ptr(new ctkDICOMTableManagerPrivate(*this))
  98. {
  99. Q_D(ctkDICOMTableManager);
  100. d->init();
  101. d->setDICOMDatabase(db);
  102. }
  103. //------------------------------------------------------------------------------
  104. ctkDICOMTableManager::~ctkDICOMTableManager()
  105. {
  106. }
  107. //------------------------------------------------------------------------------
  108. void ctkDICOMTableManager::setDICOMDatabase(ctkDICOMDatabase* db)
  109. {
  110. Q_D(ctkDICOMTableManager);
  111. d->setDICOMDatabase(db);
  112. }
  113. //------------------------------------------------------------------------------
  114. void ctkDICOMTableManager::setTableOrientation(const Qt::Orientation &o) const
  115. {
  116. Q_D(const ctkDICOMTableManager);
  117. d->tableSplitter->setOrientation(o);
  118. }
  119. //------------------------------------------------------------------------------
  120. Qt::Orientation ctkDICOMTableManager::tableOrientation()
  121. {
  122. Q_D(ctkDICOMTableManager);
  123. return d->tableSplitter->orientation();
  124. }
  125. //------------------------------------------------------------------------------
  126. QStringList ctkDICOMTableManager::currentPatientsSelection()
  127. {
  128. Q_D(ctkDICOMTableManager);
  129. return d->patientsTable->currentSelection();
  130. }
  131. //------------------------------------------------------------------------------
  132. QStringList ctkDICOMTableManager::currentStudiesSelection()
  133. {
  134. Q_D(ctkDICOMTableManager);
  135. return d->studiesTable->currentSelection();
  136. }
  137. //------------------------------------------------------------------------------
  138. QStringList ctkDICOMTableManager::currentSeriesSelection()
  139. {
  140. Q_D(ctkDICOMTableManager);
  141. return d->seriesTable->currentSelection();
  142. }
  143. //------------------------------------------------------------------------------
  144. void ctkDICOMTableManager::onPatientsQueryChanged(const QStringList &uids)
  145. {
  146. Q_D(ctkDICOMTableManager);
  147. const std::pair<QString, QStringList> patientCondition("Patients.UID", uids);
  148. d->seriesTable->addSqlWhereCondition(patientCondition);
  149. d->studiesTable->addSqlWhereCondition(patientCondition);
  150. }
  151. //------------------------------------------------------------------------------
  152. void ctkDICOMTableManager::onStudiesQueryChanged(const QStringList &uids)
  153. {
  154. Q_D(ctkDICOMTableManager);
  155. const std::pair<QString, QStringList> studiesCondition("Studies.StudyInstanceUID", uids);
  156. d->seriesTable->addSqlWhereCondition(studiesCondition);
  157. }
  158. //------------------------------------------------------------------------------
  159. void ctkDICOMTableManager::onPatientsSelectionChanged(const QStringList &uids)
  160. {
  161. std::pair<QString, QStringList> patientCondition;
  162. patientCondition.first = "Patients.UID";
  163. Q_D(ctkDICOMTableManager);
  164. if (!uids.empty())
  165. {
  166. patientCondition.second = uids;
  167. }
  168. else
  169. {
  170. patientCondition.second = d->patientsTable->uidsForAllRows();
  171. }
  172. d->studiesTable->addSqlWhereCondition(patientCondition);
  173. d->seriesTable->addSqlWhereCondition(patientCondition);
  174. }
  175. //------------------------------------------------------------------------------
  176. void ctkDICOMTableManager::onStudiesSelectionChanged(const QStringList &uids)
  177. {
  178. std::pair<QString, QStringList> studiesCondition;
  179. studiesCondition.first = "Studies.StudyInstanceUID";
  180. Q_D(ctkDICOMTableManager);
  181. if (!uids.empty())
  182. {
  183. studiesCondition.second = uids;
  184. }
  185. else
  186. {
  187. studiesCondition.second = d->studiesTable->uidsForAllRows();
  188. }
  189. d->seriesTable->addSqlWhereCondition(studiesCondition);
  190. }
  191. //------------------------------------------------------------------------------
  192. void ctkDICOMTableManager::setDynamicTableLayout(bool dynamic)
  193. {
  194. Q_D(ctkDICOMTableManager);
  195. d->m_DynamicTableLayout = dynamic;
  196. }
  197. bool ctkDICOMTableManager::dynamicTableLayout() const
  198. {
  199. Q_D(const ctkDICOMTableManager);
  200. return d->m_DynamicTableLayout;
  201. }
  202. //------------------------------------------------------------------------------
  203. void ctkDICOMTableManager::updateTableViews()
  204. {
  205. Q_D(ctkDICOMTableManager);
  206. d->patientsTable->setQuery();
  207. d->studiesTable->setQuery();
  208. d->seriesTable->setQuery();
  209. }
  210. //------------------------------------------------------------------------------
  211. void ctkDICOMTableManager::resizeEvent(QResizeEvent *e)
  212. {
  213. this->Superclass::resizeEvent(e);
  214. Q_D(ctkDICOMTableManager);
  215. if (!d->m_DynamicTableLayout)
  216. return;
  217. //Minimum size = 800 * 1.28 = 1024 => use horizontal layout (otherwise table size would be too small)
  218. this->setTableOrientation(e->size().width() > 1.28*this->minimumWidth() ? Qt::Horizontal : Qt::Vertical);
  219. }
  220. //------------------------------------------------------------------------------
  221. void ctkDICOMTableManager::setDisplayDensity(DisplayDensity density)
  222. {
  223. Q_D(ctkDICOMTableManager);
  224. // Compact density
  225. if (density == ctkDICOMTableManager::Compact)
  226. {
  227. d->patientsTable->setTableSectionSize(15);
  228. d->studiesTable->setTableSectionSize(15);
  229. d->seriesTable->setTableSectionSize(15);
  230. }
  231. // Cozy density
  232. if (density == ctkDICOMTableManager::Cozy)
  233. {
  234. d->patientsTable->setTableSectionSize(20);
  235. d->studiesTable->setTableSectionSize(20);
  236. d->seriesTable->setTableSectionSize(20);
  237. }
  238. // Comfortable density
  239. if (density == ctkDICOMTableManager::Comfortable)
  240. {
  241. d->patientsTable->setTableSectionSize(30);
  242. d->studiesTable->setTableSectionSize(30);
  243. d->seriesTable->setTableSectionSize(30);
  244. }
  245. }
  246. //------------------------------------------------------------------------------
  247. ctkDICOMTableManager::DisplayDensity ctkDICOMTableManager::displayDensity()
  248. {
  249. Q_D(ctkDICOMTableManager);
  250. int sectionSize;
  251. sectionSize = d->patientsTable->tableSectionSize();
  252. ctkDICOMTableManager::DisplayDensity density;
  253. if (sectionSize == 30)
  254. {
  255. density = ctkDICOMTableManager::Comfortable;
  256. }
  257. else if (sectionSize == 20)
  258. {
  259. density = ctkDICOMTableManager::Cozy;
  260. }
  261. else if (sectionSize == 15)
  262. {
  263. density = ctkDICOMTableManager::Compact;
  264. }
  265. return density;
  266. }