ctkDICOMObjectListWidget.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. // Qt includes
  18. #include <QApplication>
  19. #include <QClipboard>
  20. #include <QDesktopServices>
  21. #include <QString>
  22. #include <QStringList>
  23. #include <QUrl>
  24. //CTK includes
  25. #include <ctkDICOMObjectModel.h>
  26. #include <ctkLogger.h>
  27. static ctkLogger logger("org.commontk.DICOM.Widgets.ctkDICOMObjectListWidget");
  28. //----------------------------------------------------------------------------
  29. class ctkDICOMObjectListWidgetPrivate: public Ui_ctkDICOMObjectListWidget
  30. {
  31. public:
  32. ctkDICOMObjectListWidgetPrivate();
  33. ~ctkDICOMObjectListWidgetPrivate();
  34. void populateDICOMObjectTreeView(const QString& fileName);
  35. void setPathLabel(const QString& currentFile);
  36. QString currentFile;
  37. QStringList fileList;
  38. ctkDICOMObjectModel* dicomObjectModel;
  39. };
  40. //----------------------------------------------------------------------------
  41. // ctkDICOMObjectListWidgetPrivate methods
  42. //----------------------------------------------------------------------------
  43. ctkDICOMObjectListWidgetPrivate::ctkDICOMObjectListWidgetPrivate()
  44. {
  45. }
  46. //----------------------------------------------------------------------------
  47. ctkDICOMObjectListWidgetPrivate::~ctkDICOMObjectListWidgetPrivate()
  48. {
  49. }
  50. //----------------------------------------------------------------------------
  51. void ctkDICOMObjectListWidgetPrivate::populateDICOMObjectTreeView(const QString& fileName)
  52. {
  53. this->dicomObjectModel->setFile(fileName);
  54. this->dcmObjectTreeView->setModel(this->dicomObjectModel);
  55. this->dcmObjectTreeView->expandAll();
  56. }
  57. // --------------------------------------------------------------------------
  58. void ctkDICOMObjectListWidgetPrivate::setPathLabel(const QString& currentFile)
  59. {
  60. currentPathLabel->setText(currentFile);
  61. }
  62. //----------------------------------------------------------------------------
  63. // ctkDICOMObjectListWidget methods
  64. //----------------------------------------------------------------------------
  65. ctkDICOMObjectListWidget::ctkDICOMObjectListWidget(QWidget* _parent):Superclass(_parent),
  66. d_ptr(new ctkDICOMObjectListWidgetPrivate)
  67. {
  68. Q_D(ctkDICOMObjectListWidget);
  69. d->setupUi(this);
  70. d->dicomObjectModel = new ctkDICOMObjectModel(this);
  71. d->fileSliderWidget->setPageStep(1);
  72. d->currentPathLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
  73. connect(d->fileSliderWidget, SIGNAL(valueChanged(double)), this, SLOT(updateWidget()));
  74. connect(d->dcmObjectTreeView, SIGNAL(doubleClicked(const QModelIndex&))
  75. ,this, SLOT(openLookupUrl(const QModelIndex&)));
  76. connect(d->copyPathPushButton , SIGNAL(clicked(bool)),this, SLOT(copyPath()));
  77. }
  78. //----------------------------------------------------------------------------
  79. ctkDICOMObjectListWidget::~ctkDICOMObjectListWidget()
  80. {
  81. Q_D(ctkDICOMObjectListWidget);
  82. d->dicomObjectModel->deleteLater();
  83. }
  84. //----------------------------------------------------------------------------
  85. void ctkDICOMObjectListWidget::setCurrentFile(const QString& newFileName)
  86. {
  87. Q_D(ctkDICOMObjectListWidget);
  88. d->setPathLabel(newFileName);
  89. }
  90. // --------------------------------------------------------------------------
  91. void ctkDICOMObjectListWidget::setFileList(const QStringList& fileList)
  92. {
  93. Q_D(ctkDICOMObjectListWidget);
  94. d->fileList = fileList;
  95. if (d-> fileList.size()> 0)
  96. {
  97. d->currentFile = d->fileList[0];
  98. d->setPathLabel(d->currentFile );
  99. d->currentPathLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
  100. d->populateDICOMObjectTreeView(d->currentFile );
  101. d->fileSliderWidget->setMaximum(fileList.size()-1);
  102. }
  103. }
  104. // --------------------------------------------------------------------------
  105. QString ctkDICOMObjectListWidget::currentFile()
  106. {
  107. Q_D(ctkDICOMObjectListWidget);
  108. return d->currentFile;
  109. }
  110. // --------------------------------------------------------------------------
  111. QStringList ctkDICOMObjectListWidget::fileList()
  112. {
  113. Q_D(ctkDICOMObjectListWidget);
  114. return d->fileList;
  115. }
  116. // --------------------------------------------------------------------------
  117. void ctkDICOMObjectListWidget::openLookupUrl(const QModelIndex& index)
  118. {
  119. if (index.column() == 0)
  120. {
  121. QVariant data = index.data();
  122. QString lookupUrl = "http://dicomlookup.com/lookup.asp?sw=Tnumber&q="+data.toString();
  123. QUrl url(lookupUrl);
  124. QDesktopServices::openUrl(url);
  125. }
  126. }
  127. // --------------------------------------------------------------------------
  128. void ctkDICOMObjectListWidget::updateWidget()
  129. {
  130. Q_D(ctkDICOMObjectListWidget);
  131. d->currentFile = d->fileList[static_cast<int>(d->fileSliderWidget->value())];
  132. d->setPathLabel(d->currentFile);
  133. d->populateDICOMObjectTreeView(d->currentFile);
  134. }
  135. // --------------------------------------------------------------------------
  136. void ctkDICOMObjectListWidget::copyPath()
  137. {
  138. Q_D(ctkDICOMObjectListWidget);
  139. QClipboard *clipboard = QApplication::clipboard();
  140. clipboard->setText(d->currentFile);
  141. }