ctkDICOMTableView.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // ctkDICOMWidget includes
  15. #include "ctkDICOMTableView.h"
  16. #include "ui_ctkDICOMTableView.h"
  17. // Qt includes
  18. #include <QSqlQueryModel>
  19. #include <QSortFilterProxyModel>
  20. class ctkDICOMTableViewPrivate : public Ui_ctkDICOMTableView
  21. {
  22. Q_DECLARE_PUBLIC (ctkDICOMTableView)
  23. protected:
  24. ctkDICOMTableView* const q_ptr;
  25. public:
  26. ctkDICOMTableViewPrivate(ctkDICOMTableView& obj);
  27. ~ctkDICOMTableViewPrivate();
  28. void init();
  29. QSharedPointer<ctkDICOMDatabase> ctkDICOMDatabase;
  30. QSqlQueryModel DICOMSQLModel;
  31. QSortFilterProxyModel* DICOMSQLFilterModel;
  32. };
  33. ctkDICOMTableViewPrivate::ctkDICOMTableViewPrivate(ctkDICOMTableView &obj)
  34. : q_ptr(&obj)
  35. {
  36. this->DICOMSQLFilterModel = new QSortFilterProxyModel();
  37. }
  38. ctkDICOMTableViewPrivate::~ctkDICOMTableViewPrivate()
  39. {
  40. delete this->DICOMSQLFilterModel;
  41. }
  42. void ctkDICOMTableViewPrivate::init()
  43. {
  44. Q_Q(ctkDICOMTableView);
  45. this->setupUi(q);
  46. //TODO need model information
  47. // this->tblDicomDatabaseView->setModel(QSqlTableModel);
  48. this->tblDicomDatabaseView->setSelectionBehavior(QAbstractItemView::SelectRows);
  49. this->tblDicomDatabaseView->setSelectionMode(QAbstractItemView::SingleSelection);
  50. // this->tblDicomDatabaseView->setColumnHidden(1, true);
  51. QObject::connect(this->tblDicomDatabaseView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
  52. q, SLOT(onSelectionChanged(const QItemSelection &,const QItemSelection &)));
  53. }
  54. //----------------------------------------------------------------------------
  55. // ctkDICOMTableView methods
  56. //----------------------------------------------------------------------------
  57. ctkDICOMTableView::ctkDICOMTableView(QWidget *parent)
  58. :Superclass(parent)
  59. , d_ptr(new ctkDICOMTableViewPrivate(*this))
  60. {
  61. Q_D(ctkDICOMTableView);
  62. d->init();
  63. }
  64. ctkDICOMTableView::ctkDICOMTableView(QWidget *parent, QSharedPointer<ctkDICOMDatabase> ctkDicomDataBase)
  65. : Superclass(parent)
  66. , d_ptr(new ctkDICOMTableViewPrivate(*this))
  67. {
  68. Q_D(ctkDICOMTableView);
  69. // d->ctkDICOMDatabase = ctkDicomDataBase;
  70. this->setCTKDicomDataBase(ctkDicomDataBase);
  71. }
  72. ctkDICOMTableView::~ctkDICOMTableView()
  73. {
  74. }
  75. void ctkDICOMTableView::setCTKDicomDataBase(QSharedPointer<ctkDICOMDatabase> dicomDataBase)
  76. {
  77. Q_D(ctkDICOMTableView);
  78. d->ctkDICOMDatabase = dicomDataBase;
  79. if (d->ctkDICOMDatabase)
  80. {
  81. d->DICOMSQLModel.setQuery("select * from Patients", d->ctkDICOMDatabase->database());
  82. d->DICOMSQLFilterModel->setSourceModel(&d->DICOMSQLModel);
  83. d->DICOMSQLFilterModel->setFilterKeyColumn(-1);
  84. d->DICOMSQLFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
  85. QObject::connect(d->leSearchBox, SIGNAL(textChanged(QString)), d->DICOMSQLFilterModel, SLOT(setFilterWildcard(QString)));
  86. d->tblDicomDatabaseView->setModel(d->DICOMSQLFilterModel);
  87. QObject::connect(d->ctkDICOMDatabase.data(), SIGNAL(databaseChanged()), this, SLOT(onDatabaseChanged()));
  88. // d->tblDicomDatabaseView->setColumnHidden(0, true);
  89. }
  90. }
  91. void ctkDICOMTableView::onSelectionChanged(const QItemSelection &, const QItemSelection &)
  92. {
  93. //Do something
  94. }
  95. void ctkDICOMTableView::onDatabaseChanged()
  96. {
  97. Q_D(ctkDICOMTableView);
  98. d->DICOMSQLModel.setQuery("select * from Patients", d->ctkDICOMDatabase->database());
  99. d->tblDicomDatabaseView->setColumnHidden(0, true);
  100. }