Skip to content

Commit 796654c

Browse files
Punzojcfr
authored andcommitted
COMP: Create a dedicated class for ctkDICOMMetadataDialog
This commit de-duplicate code originally copied in implementation of both `ctkDICOMVisualBrowserWidget` and `ctkDICOMBrowser` classes.
1 parent dcf10dc commit 796654c

File tree

5 files changed

+159
-118
lines changed

5 files changed

+159
-118
lines changed

Libs/DICOM/Widgets/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ set(KIT_SRCS
2626
ctkDICOMJobListWidget.h
2727
ctkDICOMListenerWidget.cpp
2828
ctkDICOMListenerWidget.h
29+
ctkDICOMMetadataDialog.cpp
30+
ctkDICOMMetadataDialog.h
2931
ctkDICOMQueryResultsTabWidget.cpp
3032
ctkDICOMQueryResultsTabWidget.h
3133
ctkDICOMQueryRetrieveWidget.cpp
@@ -63,6 +65,7 @@ set(KIT_MOC_SRCS
6365
ctkDICOMImage.h
6466
ctkDICOMImportWidget.h
6567
ctkDICOMJobListWidget.h
68+
ctkDICOMMetadataDialog.h
6669
ctkDICOMObjectListWidget.h
6770
ctkDICOMObjectModel.h
6871
ctkDICOMQueryRetrieveWidget.h

Libs/DICOM/Widgets/ctkDICOMBrowser.cpp

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
// ctkDICOMWidgets includes
5959
#include "ctkDICOMBrowser.h"
60+
#include "ctkDICOMMetadataDialog.h"
6061
#include "ctkDICOMObjectListWidget.h"
6162
#include "ctkDICOMQueryResultsTabWidget.h"
6263
#include "ctkDICOMQueryRetrieveWidget.h"
@@ -66,65 +67,6 @@
6667

6768
#include "ui_ctkDICOMBrowser.h"
6869

69-
class ctkDICOMMetadataDialog : public QDialog
70-
{
71-
public:
72-
ctkDICOMMetadataDialog(QWidget *parent = 0)
73-
: QDialog(parent)
74-
{
75-
this->setWindowFlags(Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::Window);
76-
this->setModal(true);
77-
this->setSizeGripEnabled(true);
78-
QVBoxLayout *layout = new QVBoxLayout(this);
79-
layout->setMargin(0);
80-
this->tagListWidget = new ctkDICOMObjectListWidget();
81-
layout->addWidget(this->tagListWidget);
82-
}
83-
84-
virtual ~ctkDICOMMetadataDialog()
85-
{
86-
}
87-
88-
void setFileList(const QStringList& fileList)
89-
{
90-
this->tagListWidget->setFileList(fileList);
91-
}
92-
93-
void closeEvent(QCloseEvent *evt)
94-
{
95-
// just hide the window when close button is clicked
96-
evt->ignore();
97-
this->hide();
98-
}
99-
100-
void showEvent(QShowEvent *event)
101-
{
102-
QDialog::showEvent(event);
103-
// QDialog would reset window position and size when shown.
104-
// Restore its previous size instead (user may look at metadata
105-
// of different series one after the other and would be inconvenient to
106-
// set the desired size manually each time).
107-
if (!savedGeometry.isEmpty())
108-
{
109-
this->restoreGeometry(savedGeometry);
110-
if (this->isMaximized())
111-
{
112-
this->setGeometry(QApplication::desktop()->availableGeometry(this));
113-
}
114-
}
115-
}
116-
117-
void hideEvent(QHideEvent *event)
118-
{
119-
this->savedGeometry = this->saveGeometry();
120-
QDialog::hideEvent(event);
121-
}
122-
123-
protected:
124-
ctkDICOMObjectListWidget* tagListWidget;
125-
QByteArray savedGeometry;
126-
};
127-
12870
//----------------------------------------------------------------------------
12971
class ctkDICOMBrowserPrivate: public Ui_ctkDICOMBrowser
13072
{
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*=========================================================================
2+
3+
Library: CTK
4+
5+
Copyright (c) Kitware Inc.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0.txt
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
=========================================================================*/
20+
21+
// Qt includes
22+
#include <QApplication>
23+
#include <QCloseEvent>
24+
#include <QDesktopWidget>
25+
#include <QHideEvent>
26+
#include <QShowEvent>
27+
#include <QStringList>
28+
#include <QVBoxLayout>
29+
30+
// ctkDICOMWidgets includes
31+
#include "ctkDICOMMetadataDialog.h"
32+
#include "ctkDICOMObjectListWidget.h"
33+
34+
//----------------------------------------------------------------------------
35+
ctkDICOMMetadataDialog::ctkDICOMMetadataDialog(QWidget* parent)
36+
: QDialog(parent)
37+
{
38+
this->setWindowFlags(Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::Window);
39+
this->setModal(true);
40+
this->setSizeGripEnabled(true);
41+
QVBoxLayout* layout = new QVBoxLayout(this);
42+
layout->setMargin(0);
43+
this->tagListWidget = new ctkDICOMObjectListWidget();
44+
layout->addWidget(this->tagListWidget);
45+
}
46+
47+
//----------------------------------------------------------------------------
48+
ctkDICOMMetadataDialog::~ctkDICOMMetadataDialog()
49+
{
50+
}
51+
52+
//----------------------------------------------------------------------------
53+
void ctkDICOMMetadataDialog::setFileList(const QStringList& fileList)
54+
{
55+
this->tagListWidget->setFileList(fileList);
56+
}
57+
58+
//----------------------------------------------------------------------------
59+
void ctkDICOMMetadataDialog::closeEvent(QCloseEvent* evt)
60+
{
61+
// just hide the window when close button is clicked
62+
evt->ignore();
63+
this->hide();
64+
}
65+
66+
//----------------------------------------------------------------------------
67+
void ctkDICOMMetadataDialog::showEvent(QShowEvent* event)
68+
{
69+
QDialog::showEvent(event);
70+
// QDialog would reset window position and size when shown.
71+
// Restore its previous size instead (user may look at metadata
72+
// of different series one after the other and would be inconvenient to
73+
// set the desired size manually each time).
74+
if (!this->savedGeometry.isEmpty())
75+
{
76+
this->restoreGeometry(this->savedGeometry);
77+
if (this->isMaximized())
78+
{
79+
this->setGeometry(QApplication::desktop()->availableGeometry(this));
80+
}
81+
}
82+
}
83+
84+
//----------------------------------------------------------------------------
85+
void ctkDICOMMetadataDialog::hideEvent(QHideEvent* event)
86+
{
87+
this->savedGeometry = this->saveGeometry();
88+
QDialog::hideEvent(event);
89+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*=========================================================================
2+
3+
Library: CTK
4+
5+
Copyright (c) Kitware Inc.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0.txt
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
=========================================================================*/
20+
21+
#ifndef __ctkDICOMMetadataDialog_h
22+
#define __ctkDICOMMetadataDialog_h
23+
24+
// Qt includes
25+
#include <QDialog>
26+
class QStringList;
27+
28+
// CTK includes
29+
#include "ctkDICOMWidgetsExport.h"
30+
31+
class ctkDICOMObjectListWidget;
32+
33+
/// \ingroup DICOM_Widgets
34+
class CTK_DICOM_WIDGETS_EXPORT ctkDICOMMetadataDialog : public QDialog
35+
{
36+
Q_OBJECT
37+
38+
public:
39+
/// Constructor
40+
explicit ctkDICOMMetadataDialog(QWidget* parent = nullptr);
41+
42+
/// Destructor
43+
virtual ~ctkDICOMMetadataDialog();
44+
45+
/// Set the list of DICOM files to display metadata for
46+
void setFileList(const QStringList& fileList);
47+
48+
/// Handle close event by hiding the dialog instead of closing it
49+
void closeEvent(QCloseEvent* evt) override;
50+
51+
/// Handle show event to restore previous geometry
52+
void showEvent(QShowEvent* event) override;
53+
54+
/// Handle hide event to save current geometry
55+
void hideEvent(QHideEvent* event) override;
56+
57+
protected:
58+
ctkDICOMObjectListWidget* tagListWidget;
59+
QByteArray savedGeometry;
60+
61+
private:
62+
Q_DISABLE_COPY(ctkDICOMMetadataDialog)
63+
};
64+
65+
#endif

Libs/DICOM/Widgets/ctkDICOMVisualBrowserWidget.cpp

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "ctkUtils.h"
5555

5656
// ctkDICOMWidgets includes
57+
#include "ctkDICOMMetadataDialog.h"
5758
#include "ctkDICOMObjectListWidget.h"
5859
#include "ctkDICOMVisualBrowserWidget.h"
5960
#include "ctkDICOMSeriesItemWidget.h"
@@ -67,65 +68,6 @@ QColor ctkDICOMVisualBrowserWidgetDefaultColor(Qt::white);
6768
QColor ctkDICOMVisualBrowserWidgetDarkModeDefaultColor(50, 50, 50);
6869
QColor ctkDICOMVisualBrowserWidgetWarningColor(Qt::darkYellow);
6970

70-
class ctkDICOMMetadataDialog : public QDialog
71-
{
72-
public:
73-
ctkDICOMMetadataDialog(QWidget* parent = 0)
74-
: QDialog(parent)
75-
{
76-
this->setWindowFlags(Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::Window);
77-
this->setModal(true);
78-
this->setSizeGripEnabled(true);
79-
QVBoxLayout* layout = new QVBoxLayout(this);
80-
layout->setMargin(0);
81-
this->tagListWidget = new ctkDICOMObjectListWidget();
82-
layout->addWidget(this->tagListWidget);
83-
}
84-
85-
virtual ~ctkDICOMMetadataDialog()
86-
{
87-
}
88-
89-
void setFileList(const QStringList& fileList)
90-
{
91-
this->tagListWidget->setFileList(fileList);
92-
}
93-
94-
void closeEvent(QCloseEvent* evt)
95-
{
96-
// just hide the window when close button is clicked
97-
evt->ignore();
98-
this->hide();
99-
}
100-
101-
void showEvent(QShowEvent* event)
102-
{
103-
QDialog::showEvent(event);
104-
// QDialog would reset window position and size when shown.
105-
// Restore its previous size instead (user may look at metadata
106-
// of different series one after the other and would be inconvenient to
107-
// set the desired size manually each time).
108-
if (!this->savedGeometry.isEmpty())
109-
{
110-
this->restoreGeometry(this->savedGeometry);
111-
if (this->isMaximized())
112-
{
113-
this->setGeometry(QApplication::desktop()->availableGeometry(this));
114-
}
115-
}
116-
}
117-
118-
void hideEvent(QHideEvent* event)
119-
{
120-
this->savedGeometry = this->saveGeometry();
121-
QDialog::hideEvent(event);
122-
}
123-
124-
protected:
125-
ctkDICOMObjectListWidget* tagListWidget;
126-
QByteArray savedGeometry;
127-
};
128-
12971
//----------------------------------------------------------------------------
13072
class ctkDICOMVisualBrowserWidgetPrivate : public Ui_ctkDICOMVisualBrowserWidget
13173
{

0 commit comments

Comments
 (0)