ctkDICOMObjectListWidget.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Brigham and Women's Hospital (BWH).
  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. // ctkDICOMWidgets includes
  15. #include "ctkDICOMObjectListWidget.h"
  16. #include "ui_ctkDICOMObjectListWidget.h"
  17. // STD includes
  18. #include <iostream>
  19. // Qt includes
  20. #include <QString>
  21. #include <QStringList>
  22. #include <QTimer>
  23. //CTK includes
  24. #include <ctkDICOMObjectModel.h>
  25. #include <ctkLogger.h>
  26. static ctkLogger logger("org.commontk.DICOM.Widgets.ctkDICOMObjectListWidget");
  27. //----------------------------------------------------------------------------
  28. class ctkDICOMObjectListWidgetPrivate: public Ui_ctkDICOMObjectListWidget
  29. {
  30. public:
  31. ctkDICOMObjectListWidgetPrivate();
  32. ~ctkDICOMObjectListWidgetPrivate();
  33. void populateDICOMObjectTreeView(const QString& fileName);
  34. QString currentFile;
  35. QStringList fileList;
  36. };
  37. //----------------------------------------------------------------------------
  38. // ctkDICOMObjectListWidgetPrivate methods
  39. //----------------------------------------------------------------------------
  40. ctkDICOMObjectListWidgetPrivate::ctkDICOMObjectListWidgetPrivate()
  41. {
  42. }
  43. //----------------------------------------------------------------------------
  44. ctkDICOMObjectListWidgetPrivate::~ctkDICOMObjectListWidgetPrivate(){
  45. }
  46. //----------------------------------------------------------------------------
  47. void ctkDICOMObjectListWidgetPrivate::populateDICOMObjectTreeView(const QString& fileName)
  48. {
  49. //TODO: Check memory management
  50. ctkDICOMObjectModel* dcmObjModel = new ctkDICOMObjectModel;
  51. dcmObjModel->setFile(fileName);
  52. std::cerr << "fileName is =" << fileName.toUtf8().constData() << "\n";
  53. this->dcmObjectTreeView->reset();
  54. this->dcmObjectTreeView->setModel( dcmObjModel);
  55. this->dcmObjectTreeView->expandAll();
  56. }
  57. //----------------------------------------------------------------------------
  58. // ctkDICOMObjectListWidget methods
  59. //----------------------------------------------------------------------------
  60. ctkDICOMObjectListWidget::ctkDICOMObjectListWidget(QWidget* _parent):Superclass(_parent),
  61. d_ptr(new ctkDICOMObjectListWidgetPrivate)
  62. {
  63. Q_D(ctkDICOMObjectListWidget);
  64. d->setupUi(this);
  65. d->currentPathLineEdit->setReadOnly(true);
  66. connect(d->fileSlider, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));
  67. }
  68. //----------------------------------------------------------------------------
  69. ctkDICOMObjectListWidget::~ctkDICOMObjectListWidget()
  70. {
  71. }
  72. //----------------------------------------------------------------------------
  73. void ctkDICOMObjectListWidget::setCurrentFile(const QString& newFileName)
  74. {
  75. Q_D(ctkDICOMObjectListWidget);
  76. d->currentPathLineEdit->setText(newFileName);
  77. }
  78. // --------------------------------------------------------------------------
  79. void ctkDICOMObjectListWidget::setFileList(const QStringList& fileList)
  80. {
  81. Q_D(ctkDICOMObjectListWidget);
  82. d->fileList = fileList;
  83. if (d-> fileList.size()> 0)
  84. {
  85. d->currentFile = d->fileList[0];
  86. d->currentPathLineEdit->setText(d->currentFile );
  87. d->populateDICOMObjectTreeView(d->currentFile );
  88. d->fileSlider->setMaximum(d->fileList.size()-1);
  89. }
  90. }
  91. // --------------------------------------------------------------------------
  92. QString ctkDICOMObjectListWidget::currentFile()
  93. {
  94. Q_D(const ctkDICOMObjectListWidget);
  95. return d->currentFile;
  96. }
  97. // --------------------------------------------------------------------------
  98. QStringList ctkDICOMObjectListWidget::fileList()
  99. {
  100. Q_D(const ctkDICOMObjectListWidget);
  101. return d->fileList;
  102. }
  103. // --------------------------------------------------------------------------
  104. void ctkDICOMObjectListWidget::updateWidget()
  105. {
  106. Q_D(ctkDICOMObjectListWidget);
  107. int fileNumber = d->fileSlider->value();
  108. d->currentFile = d->fileList[fileNumber];
  109. d->currentPathLineEdit->setText(d->currentFile);
  110. d->populateDICOMObjectTreeView(d->currentFile);
  111. }