diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp index 933af435b1..bc6232d567 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp @@ -1,130 +1,139 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkHistogramVisualizationWidget.h" #include <qclipboard> QmitkHistogramVisualizationWidget::QmitkHistogramVisualizationWidget(QWidget* parent) : QWidget(parent) { m_Controls.setupUi(this); - CreateConnections(); - m_Controls.labelInfo->setVisible(false); - m_Controls.labelHistogramIsInvisibleWarning->setVisible(false); - m_Controls.checkBoxShowSubchart->setChecked(false); + #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + m_Controls.labelHistogramIsInvisibleWarning->setVisible(true); + m_Controls.labelHistogramIsInvisibleWarning->setText("<font color = 'red'>Histogram is not visible because Qt 5.10 is required for MitkChart. You can use the button <i>Copy to Clipboard</i> below to retrieve values.< / font>"); + m_Controls.groupBoxPlot->setVisible(false); + m_Controls.chartWidget->setVisible(false); + #else + m_Controls.labelHistogramIsInvisibleWarning->setVisible(false); + m_Controls.checkBoxShowSubchart->setChecked(false); + #endif + CreateConnections(); } void QmitkHistogramVisualizationWidget::SetHistogram(itk::Statistics::Histogram<double>::ConstPointer histogram, const std::string& dataLabel) { if (histogram == nullptr) return; m_Histogram = histogram; m_Controls.chartWidget->AddData2D(ConvertHistogramToMap(m_Histogram), dataLabel); m_Controls.chartWidget->SetChartType(dataLabel, QmitkChartWidget::ChartType::bar); m_Controls.chartWidget->SetXAxisLabel("Gray value"); m_Controls.chartWidget->SetYAxisLabel("Frequency"); - - m_Controls.chartWidget->Show(m_Controls.checkBoxShowSubchart->isChecked()); + #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + m_Controls.chartWidget->Show(m_Controls.checkBoxShowSubchart->isChecked()); + #endif SetGUIElementsEnabled(true); } void QmitkHistogramVisualizationWidget::Reset() { - m_Controls.chartWidget->Clear(); + #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + m_Controls.chartWidget->Clear(); + #endif SetGUIElementsEnabled(false); } void QmitkHistogramVisualizationWidget::CreateConnections() { connect(m_Controls.buttonCopyHistogramToClipboard, &QPushButton::clicked, this, &QmitkHistogramVisualizationWidget::OnClipboardButtonClicked); connect(m_Controls.checkBoxUseDefaultNBins, &QCheckBox::clicked, this, &QmitkHistogramVisualizationWidget::OnDefaultNBinsCheckBoxChanged); connect(m_Controls.spinBoxNBins, &QSpinBox::editingFinished, this, &QmitkHistogramVisualizationWidget::OnNBinsSpinBoxValueChanged); connect(m_Controls.checkBoxShowSubchart, &QCheckBox::clicked, this, &QmitkHistogramVisualizationWidget::OnShowSubchartCheckBoxChanged); } void QmitkHistogramVisualizationWidget::SetGUIElementsEnabled(bool enabled) { this->setEnabled(enabled); m_Controls.groupBoxHistogram->setEnabled(enabled); m_Controls.groupBoxPlot->setEnabled(enabled); m_Controls.checkBoxShowSubchart->setEnabled(enabled); m_Controls.checkBoxUseDefaultNBins->setEnabled(enabled); m_Controls.spinBoxNBins->setEnabled(!m_Controls.checkBoxUseDefaultNBins->isChecked()); m_Controls.buttonCopyHistogramToClipboard->setEnabled(enabled); } std::map<double, double> QmitkHistogramVisualizationWidget::ConvertHistogramToMap(itk::Statistics::Histogram<double>::ConstPointer histogram) const { std::map<double, double> histogramMap; if (histogram) { auto endIt = histogram->End(); auto it = histogram->Begin(); // generating Lists of measurement and frequencies for (; it != endIt; ++it) { double frequency = it.GetFrequency(); double measurement = it.GetMeasurementVector()[0]; histogramMap.emplace(measurement, frequency); } } return histogramMap; } void QmitkHistogramVisualizationWidget::OnClipboardButtonClicked() { if (m_Histogram) { QApplication::clipboard()->clear(); QString clipboard("Measurement \t Frequency\n"); auto iter = m_Histogram->Begin(); auto iterEnd = m_Histogram->End(); for (; iter != iterEnd; ++iter) { clipboard = clipboard.append("%L1 \t %L2\n") .arg(iter.GetMeasurementVector()[0], 0, 'f', 2) .arg(iter.GetFrequency()); } QApplication::clipboard()->setText(clipboard, QClipboard::Clipboard); } } void QmitkHistogramVisualizationWidget::OnDefaultNBinsCheckBoxChanged() { if (m_Controls.checkBoxUseDefaultNBins->isChecked()) { m_Controls.spinBoxNBins->setEnabled(false); m_Controls.spinBoxNBins->setValue(100); } else { m_Controls.spinBoxNBins->setEnabled(true); } } void QmitkHistogramVisualizationWidget::OnNBinsSpinBoxValueChanged() { emit RequestHistogramUpdate(m_Controls.spinBoxNBins->value()); } void QmitkHistogramVisualizationWidget::OnShowSubchartCheckBoxChanged() { m_Controls.chartWidget->Show(m_Controls.checkBoxShowSubchart->isChecked()); } \ No newline at end of file diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.ui b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.ui index ed1c05711b..192120d46f 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.ui +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.ui @@ -1,316 +1,319 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>QmitkHistogramVisualizationControls</class> <widget class="QWidget" name="QmitkHistogramVisualizationControls"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>540</width> <height>468</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QGroupBox" name="groupBoxHistogram"> <property name="enabled"> <bool>false</bool> </property> <property name="title"> <string>Histogram</string> </property> <property name="checkable"> <bool>false</bool> </property> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> <widget class="QLabel" name="labelHistogramIsInvisibleWarning"> <property name="enabled"> <bool>false</bool> </property> <property name="palette"> <palette> <active> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>255</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> <colorrole role="Text"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>255</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> <colorrole role="ButtonText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>255</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> </active> <inactive> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>255</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> <colorrole role="Text"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>255</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> <colorrole role="ButtonText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>255</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> </inactive> <disabled> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>120</red> <green>120</green> <blue>120</blue> </color> </brush> </colorrole> <colorrole role="Text"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>120</red> <green>120</green> <blue>120</blue> </color> </brush> </colorrole> <colorrole role="ButtonText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>120</red> <green>120</green> <blue>120</blue> </color> </brush> </colorrole> </disabled> </palette> </property> <property name="text"> <string/> </property> + <property name="wordWrap"> + <bool>true</bool> + </property> </widget> </item> <item> <widget class="QGroupBox" name="groupBoxPlot"> <property name="enabled"> <bool>false</bool> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="minimumSize"> <size> <width>0</width> <height>0</height> </size> </property> <property name="maximumSize"> <size> <width>16777215</width> <height>16777215</height> </size> </property> <property name="title"> <string>Plot</string> </property> <layout class="QVBoxLayout" name="verticalLayout_5"> <item> <widget class="QCheckBox" name="checkBoxShowSubchart"> <property name="text"> <string>Show Subchart</string> </property> <property name="checked"> <bool>true</bool> </property> </widget> </item> <item> <widget class="QCheckBox" name="checkBoxUseDefaultNBins"> <property name="text"> <string>Use default #bins</string> </property> <property name="checked"> <bool>true</bool> </property> </widget> </item> <item> <widget class="QFrame" name="FrameBinSize"> <property name="frameShape"> <enum>QFrame::NoFrame</enum> </property> <property name="frameShadow"> <enum>QFrame::Raised</enum> </property> <layout class="QGridLayout" name="gridLayout_2"> <property name="leftMargin"> <number>0</number> </property> <property name="topMargin"> <number>0</number> </property> <property name="rightMargin"> <number>0</number> </property> <property name="bottomMargin"> <number>0</number> </property> <property name="spacing"> <number>0</number> </property> <item row="1" column="0"> <widget class="QLabel" name="labelNBins"> <property name="minimumSize"> <size> <width>60</width> <height>0</height> </size> </property> <property name="maximumSize"> <size> <width>100</width> <height>16777215</height> </size> </property> <property name="text"> <string># bins:</string> </property> </widget> </item> <item row="1" column="1"> <widget class="QSpinBox" name="spinBoxNBins"> <property name="enabled"> <bool>false</bool> </property> <property name="toolTip"> <string>Press enter to recalculate statistics with new bin size.</string> </property> <property name="minimum"> <number>1</number> </property> <property name="maximum"> <number>10000</number> </property> <property name="value"> <number>100</number> </property> </widget> </item> </layout> </widget> </item> </layout> </widget> </item> <item> <widget class="QmitkChartWidget" name="chartWidget" native="true"/> </item> <item> <widget class="QLabel" name="labelInfo"> <property name="text"> <string/> </property> </widget> </item> <item> <widget class="QWidget" name="widgetClipboard" native="true"> <layout class="QHBoxLayout" name="horizontalLayout_3"> <property name="spacing"> <number>0</number> </property> <property name="leftMargin"> <number>0</number> </property> <property name="topMargin"> <number>0</number> </property> <property name="rightMargin"> <number>0</number> </property> <property name="bottomMargin"> <number>0</number> </property> <item> <widget class="QPushButton" name="buttonCopyHistogramToClipboard"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string>Copy to Clipboard</string> </property> </widget> </item> <item> <spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> </size> </property> </spacer> </item> </layout> </widget> </item> </layout> </widget> </item> </layout> </widget> <customwidgets> <customwidget> <class>QmitkChartWidget</class> <extends>QWidget</extends> <header location="global">QmitkChartWidget.h</header> </customwidget> </customwidgets> <resources/> <connections/> </ui>