ctkDICOMTableManager.cpp 11 KB

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