ctkDICOMTableManager.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. // Qt includes
  18. #include <QHBoxLayout>
  19. #include <QVBoxLayout>
  20. #include <QRadioButton>
  21. #include <QButtonGroup>
  22. #include <QPushButton>
  23. #include <QSplitter>
  24. class ctkDICOMTableManagerPrivate
  25. {
  26. Q_DECLARE_PUBLIC(ctkDICOMTableManager)
  27. protected:
  28. ctkDICOMTableManager* const q_ptr;
  29. public:
  30. ctkDICOMTableManagerPrivate(ctkDICOMTableManager& obj);
  31. ~ctkDICOMTableManagerPrivate();
  32. QVBoxLayout* layout;
  33. QBoxLayout* layoutTables;
  34. QPushButton* changeLayoutButton;
  35. QSplitter* tableSplitter;
  36. ctkDICOMTableView* patientsTable;
  37. ctkDICOMTableView* studiesTable;
  38. ctkDICOMTableView* seriesTable;
  39. void init();
  40. void setCTKDICOMDatabase(QSharedPointer<ctkDICOMDatabase> db);
  41. };
  42. ctkDICOMTableManagerPrivate::ctkDICOMTableManagerPrivate(ctkDICOMTableManager &obj)
  43. : q_ptr(&obj)
  44. {
  45. }
  46. ctkDICOMTableManagerPrivate::~ctkDICOMTableManagerPrivate()
  47. {
  48. }
  49. void ctkDICOMTableManagerPrivate::init()
  50. {
  51. //setup UI
  52. Q_Q(ctkDICOMTableManager);
  53. this->layout = new QVBoxLayout();
  54. this->layoutTables = new QBoxLayout(QBoxLayout::LeftToRight);
  55. this->patientsTable = new ctkDICOMTableView(q, "Patients");
  56. this->studiesTable = new ctkDICOMTableView(q, "Studies");
  57. this->studiesTable->setQueryForeignKey("PatientsUID");
  58. this->seriesTable = new ctkDICOMTableView(q, "Series");
  59. this->seriesTable->setQueryForeignKey("StudyInstanceUID");
  60. //Connect changed tableview selection with query update of "child" table
  61. QObject::connect(this->patientsTable, SIGNAL(signalSelectionChanged(QStringList)),
  62. this->studiesTable, SLOT(onUpdateQuery(QStringList)));
  63. QObject::connect(this->studiesTable, SIGNAL(signalSelectionChanged(QStringList)),
  64. this->seriesTable, SLOT(onUpdateQuery(QStringList)));
  65. //Connect changed filter with query update of "child" table
  66. QObject::connect(this->patientsTable, SIGNAL(signalFilterChanged(const QStringList&)),
  67. this->studiesTable, SLOT(onUpdateQuery(const QStringList&)));
  68. QObject::connect(this->studiesTable, SIGNAL(signalFilterChanged(const QStringList&)),
  69. this->seriesTable, SLOT(onUpdateQuery(const QStringList&)));
  70. //This way a patient filter change can be propageted to series table without
  71. //any selection in the study table
  72. QObject::connect(this->studiesTable, SIGNAL(signalQueryChanged(QStringList)),
  73. this->seriesTable, SLOT(onUpdateQuery(const QStringList&)));
  74. QObject::connect(this->patientsTable, SIGNAL(signalSelectionChanged(const QItemSelection&, const QItemSelection&)),
  75. q, SIGNAL(signalPatientsSelectionChanged(const QItemSelection&, const QItemSelection&)));
  76. QObject::connect(this->patientsTable, SIGNAL(signalSelectionChanged(const QItemSelection&, const QItemSelection&)),
  77. q, SLOT(onPatientSelectionChanged()));
  78. QObject::connect(this->patientsTable, SIGNAL(signalSelectionChanged(const QStringList&)),
  79. q, SLOT(onPatientSelectionChanged(const QStringList&)));
  80. QObject::connect(this->studiesTable, SIGNAL(signalSelectionChanged(const QItemSelection&, const QItemSelection&)),
  81. q, SIGNAL(signalStudiesSelectionsChanged(const QItemSelection&, const QItemSelection&)));
  82. QObject::connect(this->studiesTable, SIGNAL(signalSelectionChanged(const QItemSelection&, const QItemSelection&)),
  83. q, SLOT(signalStudiesSelectionsChanged(const QItemSelection&, const QItemSelection&)));
  84. QObject::connect(this->studiesTable, SIGNAL(signalSelectionChanged(const QStringList&)),
  85. q, SLOT(signalStudiesSelectionsChanged(const QStringList&)));
  86. QObject::connect(this->seriesTable, SIGNAL(signalSelectionChanged(const QItemSelection&, const QItemSelection&)),
  87. q, SIGNAL(signalSeriesSelectionsChanged(const QItemSelection&, const QItemSelection&)));
  88. QObject::connect(this->seriesTable, SIGNAL(signalSelectionChanged(const QItemSelection&, const QItemSelection&)),
  89. q, SLOT(signalSeriesSelectionChanged(const QItemSelection&, const QItemSelection&)));
  90. QObject::connect(this->seriesTable, SIGNAL(signalSelectionChanged(const QStringList&)),
  91. q, SLOT(signalSeriesSelectionChanged(const QStringList&)));
  92. this->patientsTable->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
  93. this->studiesTable->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
  94. this->seriesTable->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
  95. tableSplitter = new QSplitter();
  96. tableSplitter->setChildrenCollapsible(false);
  97. tableSplitter->addWidget(this->patientsTable);
  98. tableSplitter->addWidget(this->studiesTable);
  99. tableSplitter->addWidget(this->seriesTable);
  100. tableSplitter->setStyleSheet("QSplitter::handle {background-color: rgb(224,224,224);}QSplitter::handle:horizontal {width: 2px;}QSplitter::handle:vertical {height: 2px;}");
  101. QHBoxLayout* buttonLayout = new QHBoxLayout();
  102. this->changeLayoutButton = new QPushButton();
  103. this->changeLayoutButton->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
  104. QPixmap icon(":/Icons/vertical.png");
  105. this->changeLayoutButton->setIcon(icon);
  106. QObject::connect(this->changeLayoutButton, SIGNAL(clicked()), q, SLOT(onChangeLayoutPushed()));
  107. buttonLayout->addWidget(this->changeLayoutButton);
  108. QSpacerItem* spacer = new QSpacerItem(20,20,QSizePolicy::Expanding,QSizePolicy::Fixed);
  109. buttonLayout->addItem(spacer);
  110. this->layout->addLayout(buttonLayout);
  111. this->layout->addWidget(this->tableSplitter);
  112. q->setLayout(layout);
  113. }
  114. void ctkDICOMTableManagerPrivate::setCTKDICOMDatabase(QSharedPointer<ctkDICOMDatabase> db)
  115. {
  116. this->patientsTable->setCTKDicomDataBase(db);
  117. this->studiesTable->setCTKDicomDataBase(db);
  118. this->seriesTable->setCTKDicomDataBase(db);
  119. }
  120. //----------------------------------------------------------------------------
  121. // ctkDICOMTableManager methods
  122. //----------------------------------------------------------------------------
  123. ctkDICOMTableManager::ctkDICOMTableManager(QWidget *parent)
  124. :Superclass(parent)
  125. , d_ptr(new ctkDICOMTableManagerPrivate(*this))
  126. {
  127. Q_D(ctkDICOMTableManager);
  128. d->init();
  129. }
  130. ctkDICOMTableManager::ctkDICOMTableManager(QSharedPointer<ctkDICOMDatabase> db, QWidget *parent)
  131. : Superclass(parent)
  132. , d_ptr(new ctkDICOMTableManagerPrivate(*this))
  133. {
  134. Q_D(ctkDICOMTableManager);
  135. d->init();
  136. d->setCTKDICOMDatabase(db);
  137. }
  138. ctkDICOMTableManager::~ctkDICOMTableManager()
  139. {
  140. }
  141. void ctkDICOMTableManager::onChangeLayoutPushed()
  142. {
  143. Q_D(ctkDICOMTableManager);
  144. if(d->tableSplitter->orientation() == Qt::Vertical)
  145. {
  146. QPixmap icon(":/Icons/vertical.png");
  147. d->changeLayoutButton->setIcon(icon);
  148. d->tableSplitter->setOrientation(Qt::Horizontal);
  149. }
  150. else
  151. {
  152. QPixmap icon(":/Icons/horizontal.png");
  153. d->changeLayoutButton->setIcon(icon);
  154. d->tableSplitter->setOrientation(Qt::Vertical);
  155. }
  156. }
  157. void ctkDICOMTableManager::setCTKDICOMDatabase(QSharedPointer<ctkDICOMDatabase> db)
  158. {
  159. Q_D(ctkDICOMTableManager);
  160. d->setCTKDICOMDatabase(db);
  161. }