diff --git a/Examples/Tutorial/Step4/Step4.cpp b/Examples/Tutorial/Step4/Step4.cpp index 3861e4d84f..2d6fe9c4c8 100644 --- a/Examples/Tutorial/Step4/Step4.cpp +++ b/Examples/Tutorial/Step4/Step4.cpp @@ -1,164 +1,164 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkRegisterClasses.h" #include "QmitkRenderWindow.h" #include "QmitkSliceWidget.h" #include "mitkNodePredicateDataType.h" #include "mitkProperties.h" #include "mitkRenderingManager.h" #include "mitkStandaloneDataStorage.h" #include #include #include #include #include //##Documentation //## @brief Use several views to explore data //## //## As in Step2 and Step3, load one or more data sets (many image, //## surface and other formats), but create 3 views on the data. //## The QmitkRenderWindow is used for displaying a 3D view as in Step3, //## but without volume-rendering. //## Furthermore, we create two 2D views for slicing through the data. //## We use the class QmitkSliceWidget, which is based on the class //## QmitkRenderWindow, but additionally provides sliders //## to slice through the data. We create two instances of //## QmitkSliceWidget, one for axial and one for sagittal slicing. //## The two slices are also shown at their correct position in 3D as //## well as intersection-line, each in the other 2D view. int main(int argc, char *argv[]) { QApplication qtapplication(argc, argv); if (argc < 2) { fprintf( stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str()); return 1; } // Register Qmitk-dependent global instances QmitkRegisterClasses(); //************************************************************************* // Part I: Basic initialization //************************************************************************* // Create a DataStorage mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); //************************************************************************* // Part II: Create some data by reading files //************************************************************************* int i; for (i = 1; i < argc; ++i) { // For testing if (strcmp(argv[i], "-testing") == 0) continue; //********************************************************************* // Part III: Put the data into the datastorage //********************************************************************* // Load datanode (eg. many image formats, surface formats, etc.) mitk::IOUtil::Load(argv[i], *ds); } //************************************************************************* // Part IV: Create windows and pass the tree to it //************************************************************************* // Create toplevel widget with horizontal layout QWidget toplevelWidget; QHBoxLayout layout; layout.setSpacing(2); - layout.setMargin(0); + layout.setContentsMargins({}); toplevelWidget.setLayout(&layout); //************************************************************************* // Part IVa: 3D view //************************************************************************* // Create a renderwindow QmitkRenderWindow renderWindow(&toplevelWidget); layout.addWidget(&renderWindow); // Tell the renderwindow which (part of) the datastorage to render renderWindow.GetRenderer()->SetDataStorage(ds); // Use it as a 3D view renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); // Reposition the camera to include all visible actors renderWindow.GetRenderer()->GetVtkRenderer()->ResetCamera(); // ******************************************************* // ****************** START OF NEW PART ****************** // ******************************************************* //************************************************************************* // Part IVb: 2D view for slicing axially //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget view2(&toplevelWidget); layout.addWidget(&view2); view2.SetLevelWindowEnabled(true); // Tell the QmitkSliceWidget which (part of) the tree to render. // By default, it slices the data axially view2.SetDataStorage(ds); // Get the image from the data storage. A predicate (mitk::NodePredicateBase) // is used to get only nodes of the type mitk::Image. mitk::DataStorage::SetOfObjects::ConstPointer rs = ds->GetSubset(mitk::TNodePredicateDataType::New()); view2.SetData(rs->Begin(), mitk::AnatomicalPlane::Axial); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the datastorage! ds->Add(view2.GetRenderer()->GetCurrentWorldPlaneGeometryNode()); //************************************************************************* // Part IVc: 2D view for slicing sagittally //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget view3(&toplevelWidget); layout.addWidget(&view3); view3.SetDataStorage(ds); // Tell the QmitkSliceWidget which (part of) the datastorage to render // and to slice sagittally view3.SetData(rs->Begin(), mitk::AnatomicalPlane::Sagittal); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the datastorage! ds->Add(view3.GetRenderer()->GetCurrentWorldPlaneGeometryNode()); // ******************************************************* // ******************* END OF NEW PART ******************* // ******************************************************* //************************************************************************* // Part V: Qt-specific initialization //************************************************************************* toplevelWidget.show(); return qtapplication.exec(); } /** \example Step4.cpp */ diff --git a/Examples/Tutorial/Step5/Step5.cpp b/Examples/Tutorial/Step5/Step5.cpp index addd3361a1..e4b149aef6 100644 --- a/Examples/Tutorial/Step5/Step5.cpp +++ b/Examples/Tutorial/Step5/Step5.cpp @@ -1,203 +1,203 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkRegisterClasses.h" #include "QmitkRenderWindow.h" #include "QmitkSliceWidget.h" #include "mitkNodePredicateDataType.h" #include "mitkProperties.h" #include "mitkRenderingManager.h" #include "mitkStandaloneDataStorage.h" #include "mitkPointSet.h" // NEW INCLUDE #include "mitkPointSetDataInteractor.h" #include #include #include #include //##Documentation //## @brief Interactively add points //## //## As in Step4, load one or more data sets (many image, //## surface and other formats) and create 3 views on the data. //## Additionally, we want to interactively add points. A node containing //## a PointSet as data is added to the data tree and a PointSetDataInteractor //## is associated with the node, which handles the interaction. The //## @em interaction @em pattern is defined in a state-machine, stored in an //## external XML file. Thus, we need to load a state-machine //## The interaction patterns defines the @em events, //## on which the interactor reacts (e.g., which mouse buttons are used to //## set a point), the @em transition to the next state (e.g., the initial //## may be "empty point set") and associated @a actions (e.g., add a point //## at the position where the mouse-click occured). int main(int argc, char *argv[]) { QApplication qtapplication(argc, argv); if (argc < 2) { fprintf( stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str()); return 1; } // Register Qmitk-dependent global instances QmitkRegisterClasses(); //************************************************************************* // Part I: Basic initialization //************************************************************************* // Create a DataStorage mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); //************************************************************************* // Part II: Create some data by reading files //************************************************************************* int i; for (i = 1; i < argc; ++i) { // For testing if (strcmp(argv[i], "-testing") == 0) continue; // Load datanode (eg. many image formats, surface formats, etc.) mitk::StandaloneDataStorage::SetOfObjects::Pointer dataNodes = mitk::IOUtil::Load(argv[i], *ds); //********************************************************************* // Part III: Put the data into the datastorage //********************************************************************* // Add the node to the DataStorage if (dataNodes->empty()) { fprintf(stderr, "Could not open file %s \n\n", argv[i]); exit(2); } } //************************************************************************* // Part V: Create windows and pass the tree to it //************************************************************************* // Create toplevel widget with horizontal layout QWidget toplevelWidget; QHBoxLayout layout; layout.setSpacing(2); - layout.setMargin(0); + layout.setContentsMargins({}); toplevelWidget.setLayout(&layout); //************************************************************************* // Part Va: 3D view //************************************************************************* // Create a renderwindow QmitkRenderWindow renderWindow(&toplevelWidget); layout.addWidget(&renderWindow); // Tell the renderwindow which (part of) the tree to render renderWindow.GetRenderer()->SetDataStorage(ds); // Use it as a 3D view renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); // Reposition the camera to include all visible actors renderWindow.GetRenderer()->GetVtkRenderer()->ResetCamera(); //************************************************************************* // Part Vb: 2D view for slicing axially //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget view2(&toplevelWidget); layout.addWidget(&view2); // Tell the QmitkSliceWidget which (part of) the tree to render. // By default, it slices the data axially view2.SetDataStorage(ds); mitk::DataStorage::SetOfObjects::ConstPointer rs = ds->GetSubset(mitk::TNodePredicateDataType::New()); view2.SetData(rs->Begin(), mitk::AnatomicalPlane::Axial); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the tree! ds->Add(view2.GetRenderer()->GetCurrentWorldPlaneGeometryNode()); //************************************************************************* // Part Vc: 2D view for slicing sagittally //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget view3(&toplevelWidget); layout.addWidget(&view3); // Tell the QmitkSliceWidget which (part of) the tree to render // and to slice sagittally view3.SetDataStorage(ds); view3.SetData(rs->Begin(), mitk::AnatomicalPlane::Sagittal); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the tree! ds->Add(view3.GetRenderer()->GetCurrentWorldPlaneGeometryNode()); // ******************************************************* // ****************** START OF NEW PART ****************** // ******************************************************* //************************************************************************* // Part VI: For allowing to interactively add points ... //************************************************************************* // ATTENTION: It is very important that the renderer already know their DataStorage, // because registerig DataInteractors with the render windows is done automatically // and only works if the BaseRenderer and the DataStorage know each other. // Create PointSet and a node for it mitk::PointSet::Pointer pointSet = mitk::PointSet::New(); mitk::DataNode::Pointer pointSetNode = mitk::DataNode::New(); // Store the point set in the DataNode pointSetNode->SetData(pointSet); // Add the node to the tree ds->Add(pointSetNode); // Create PointSetDataInteractor mitk::PointSetDataInteractor::Pointer interactor = mitk::PointSetDataInteractor::New(); // Set the StateMachine pattern that describes the flow of the interactions interactor->LoadStateMachine("PointSet.xml"); // Set the configuration file, which describes the user interactions that trigger actions // in this file SHIFT + LeftClick triggers add Point, but by modifying this file, // it could as well be changes to any other user interaction. interactor->SetEventConfig("PointSetConfig.xml"); // Assign the pointSetNode to the interactor, // alternatively one could also add the DataInteractor to the pointSetNode using the SetDataInteractor() method. interactor->SetDataNode(pointSetNode); // ******************************************************* // ******************* END OF NEW PART ******************* // ******************************************************* //************************************************************************* // Part VII: Qt-specific initialization //************************************************************************* toplevelWidget.show(); return qtapplication.exec(); } /** \example Step5.cpp */ diff --git a/Examples/Tutorial/Step6/Step6.cpp b/Examples/Tutorial/Step6/Step6.cpp index a6bce70bb3..5e7b065aeb 100644 --- a/Examples/Tutorial/Step6/Step6.cpp +++ b/Examples/Tutorial/Step6/Step6.cpp @@ -1,233 +1,233 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "Step6.h" #include "QmitkRenderWindow.h" #include "QmitkSliceWidget.h" #include "mitkProperties.h" #include "mitkRenderingManager.h" #include "mitkPointSet.h" #include "mitkPointSetDataInteractor.h" #include "mitkImageAccessByItk.h" #include "mitkRenderingManager.h" #include #include #include #include #include #include #include //##Documentation //## @brief Start region-grower at interactively added points Step6::Step6(int argc, char *argv[], QWidget *parent) : QWidget(parent) { // load data as in the previous steps; a reference to the first loaded // image is kept in the member m_FirstImage and used as input for the // region growing Load(argc, argv); } void Step6::Initialize() { // setup the widgets as in the previous steps, but with an additional // QVBox for a button to start the segmentation this->SetupWidgets(); // Create controlsParent widget with horizontal layout QWidget *controlsParent = new QWidget(this); this->layout()->addWidget(controlsParent); QHBoxLayout *hlayout = new QHBoxLayout(controlsParent); hlayout->setSpacing(2); QLabel *labelThresholdMin = new QLabel("Lower Threshold:", controlsParent); hlayout->addWidget(labelThresholdMin); m_LineEditThresholdMin = new QLineEdit("-1000", controlsParent); hlayout->addWidget(m_LineEditThresholdMin); QLabel *labelThresholdMax = new QLabel("Upper Threshold:", controlsParent); hlayout->addWidget(labelThresholdMax); m_LineEditThresholdMax = new QLineEdit("-400", controlsParent); hlayout->addWidget(m_LineEditThresholdMax); // create button to start the segmentation and connect its clicked() // signal to method StartRegionGrowing QPushButton *startButton = new QPushButton("start region growing", controlsParent); hlayout->addWidget(startButton); connect(startButton, SIGNAL(clicked()), this, SLOT(StartRegionGrowing())); if (m_FirstImage.IsNull()) startButton->setEnabled(false); // as in Step5, create PointSet (now as a member m_Seeds) and // associate a interactor to it m_Seeds = mitk::PointSet::New(); mitk::DataNode::Pointer pointSetNode = mitk::DataNode::New(); pointSetNode->SetData(m_Seeds); pointSetNode->SetProperty("layer", mitk::IntProperty::New(2)); m_DataStorage->Add(pointSetNode); // Create PointSetDataInteractor mitk::PointSetDataInteractor::Pointer interactor = mitk::PointSetDataInteractor::New(); interactor->LoadStateMachine("PointSet.xml"); interactor->SetEventConfig("PointSetConfig.xml"); interactor->SetDataNode(pointSetNode); } int Step6::GetThresholdMin() { return m_LineEditThresholdMin->text().toInt(); } int Step6::GetThresholdMax() { return m_LineEditThresholdMax->text().toInt(); } void Step6::StartRegionGrowing() { AccessByItk_1(m_FirstImage, RegionGrowing, this); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void Step6::Load(int argc, char *argv[]) { //************************************************************************* // Part I: Basic initialization //************************************************************************* m_DataStorage = mitk::StandaloneDataStorage::New(); //************************************************************************* // Part II: Create some data by reading files //************************************************************************* int i; for (i = 1; i < argc; ++i) { // For testing if (strcmp(argv[i], "-testing") == 0) continue; // Load datanode (eg. many image formats, surface formats, etc.) mitk::StandaloneDataStorage::SetOfObjects::Pointer dataNodes = mitk::IOUtil::Load(argv[i], *m_DataStorage); if (dataNodes->empty()) { fprintf(stderr, "Could not open file %s \n\n", argv[i]); exit(2); } mitk::Image::Pointer image = dynamic_cast(dataNodes->at(0)->GetData()); if ((m_FirstImage.IsNull()) && (image.IsNotNull())) m_FirstImage = image; } } void Step6::SetupWidgets() { //************************************************************************* // Part I: Create windows and pass the datastorage to it //************************************************************************* // Create toplevel widget with vertical layout QVBoxLayout *vlayout = new QVBoxLayout(this); - vlayout->setMargin(0); + vlayout->setContentsMargins({}); vlayout->setSpacing(2); // Create viewParent widget with horizontal layout QWidget *viewParent = new QWidget(this); vlayout->addWidget(viewParent); QHBoxLayout *hlayout = new QHBoxLayout(viewParent); - hlayout->setMargin(0); + hlayout->setContentsMargins({}); hlayout->setSpacing(2); //************************************************************************* // Part Ia: 3D view //************************************************************************* // Create a renderwindow QmitkRenderWindow *renderWindow = new QmitkRenderWindow(viewParent); hlayout->addWidget(renderWindow); // Tell the renderwindow which (part of) the tree to render renderWindow->GetRenderer()->SetDataStorage(m_DataStorage); // Use it as a 3D view renderWindow->GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); // Reposition the camera to include all visible actors renderWindow->GetRenderer()->GetVtkRenderer()->ResetCamera(); //************************************************************************* // Part Ib: 2D view for slicing axially //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget *view2 = new QmitkSliceWidget(viewParent); hlayout->addWidget(view2); // Tell the QmitkSliceWidget which (part of) the tree to render. // By default, it slices the data axially view2->SetDataStorage(m_DataStorage); mitk::DataStorage::SetOfObjects::ConstPointer rs = m_DataStorage->GetAll(); view2->SetData(rs->Begin(), mitk::AnatomicalPlane::Axial); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the tree! m_DataStorage->Add(view2->GetRenderer()->GetCurrentWorldPlaneGeometryNode()); //************************************************************************* // Part Ic: 2D view for slicing sagittally //************************************************************************* // Create QmitkSliceWidget, which is based on the class // QmitkRenderWindow, but additionally provides sliders QmitkSliceWidget *view3 = new QmitkSliceWidget(viewParent); hlayout->addWidget(view3); // Tell the QmitkSliceWidget which (part of) the tree to render // and to slice sagittally view3->SetDataStorage(m_DataStorage); view3->SetData(rs->Begin(), mitk::AnatomicalPlane::Sagittal); // We want to see the position of the slice in 2D and the // slice itself in 3D: add it to the tree! m_DataStorage->Add(view3->GetRenderer()->GetCurrentWorldPlaneGeometryNode()); //************************************************************************* // Part II: handle updates: To avoid unnecessary updates, we have to //************************************************************************* // define when to update. The RenderingManager serves this purpose, and // each RenderWindow has to be registered to it. /*mitk::RenderingManager *renderingManager = mitk::RenderingManager::GetInstance(); renderingManager->AddRenderWindow( renderWindow ); renderingManager->AddRenderWindow( view2->GetRenderWindow() ); renderingManager->AddRenderWindow( view3->GetRenderWindow() );*/ } /** \example Step6.cpp */ diff --git a/Examples/Tutorial/Step8/Step8.cpp b/Examples/Tutorial/Step8/Step8.cpp index 2363ed0a48..e300928095 100644 --- a/Examples/Tutorial/Step8/Step8.cpp +++ b/Examples/Tutorial/Step8/Step8.cpp @@ -1,76 +1,76 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "Step8.h" #include "QmitkLevelWindowWidget.h" #include "QmitkRenderWindow.h" #include "QmitkStdMultiWidget.h" #include "mitkRenderingManager.h" #include #include //##Documentation //## @brief As Step6, but with QmitkStdMultiWidget as widget Step8::Step8(int argc, char *argv[], QWidget *parent) : Step6(argc, argv, parent) { } void Step8::SetupWidgets() { //************************************************************************* // Part I: Create windows and pass the tree to it //************************************************************************* // Create toplevel widget with vertical layout QVBoxLayout *vlayout = new QVBoxLayout(this); - vlayout->setMargin(0); + vlayout->setContentsMargins({}); vlayout->setSpacing(2); // Create viewParent widget with horizontal layout QWidget *viewParent = new QWidget(this); vlayout->addWidget(viewParent); QHBoxLayout *hlayout = new QHBoxLayout(viewParent); - hlayout->setMargin(0); + hlayout->setContentsMargins({}); //************************************************************************* // Part Ia: create and initialize QmitkStdMultiWidget //************************************************************************* QmitkStdMultiWidget *multiWidget = new QmitkStdMultiWidget(viewParent); hlayout->addWidget(multiWidget); // Tell the multiWidget which DataStorage to render multiWidget->SetDataStorage(m_DataStorage); // Initialize the multiWidget with the render windows multiWidget->InitializeMultiWidget(); // Add the displayed views to the DataStorage to see their positions in 2D and 3D multiWidget->AddPlanesToDataStorage(); //************************************************************************* // Part Ib: create and initialize LevelWindowWidget //************************************************************************* QmitkLevelWindowWidget *levelWindowWidget = new QmitkLevelWindowWidget(viewParent); hlayout->addWidget(levelWindowWidget); // Tell the levelWindowWidget which DataStorage to access levelWindowWidget->SetDataStorage(m_DataStorage); } /** \example Step8.cpp */ diff --git a/Modules/Chart/src/QmitkChartWidget.cpp b/Modules/Chart/src/QmitkChartWidget.cpp index dff85d5543..543dd4dfce 100644 --- a/Modules/Chart/src/QmitkChartWidget.cpp +++ b/Modules/Chart/src/QmitkChartWidget.cpp @@ -1,940 +1,940 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include #include #include #include #include #include #include "mitkExceptionMacro.h" #include #include class CustomPage : public QWebEnginePage { public: CustomPage(QObject *parent = nullptr) : QWebEnginePage(parent) {} virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel /*level*/, const QString &message, int lineNumber, const QString & /*sourceID*/) override { MITK_INFO << "JS > " << lineNumber << ": " << message.toStdString(); } }; class QmitkChartWidget::Impl final { public: explicit Impl(QWidget *parent); ~Impl(); Impl(const Impl &) = delete; Impl &operator=(const Impl &) = delete; void AddData1D(const std::vector &data1D, const std::string &label, QmitkChartWidget::ChartType chartType); void AddData2D(const std::vector< std::pair > &data2D, const std::string &label, QmitkChartWidget::ChartType chartType); void AddChartExampleData(const std::vector< std::pair >& data2D, const std::string& label, const std::string& type, const std::string& color, const std::string& style, const std::string& pieLabelsData = 0); void UpdateData1D(const std::vector &data1D, const std::string &label); void UpdateData2D(const std::vector< std::pair > &data2D, const std::string &label); void UpdateChartExampleData(const std::vector< std::pair >& data2D, const std::string& label, const std::string& type, const std::string& color, const std::string& lineStyle, const std::string& pieLabelsData = 0); void RemoveData(const std::string &label); void UpdateLabel(const std::string &existingLabel, const std::string &newLabel); QmitkChartxyData* GetDataElementByLabel(const std::string& label) const; void ClearData(); void SetColor(const std::string &label, const std::string &colorName); void SetLineStyle(const std::string &label, LineStyle style); void SetMarkerSymbol(const std::string &label, MarkerSymbol symbol); void SetYAxisScale(AxisScale scale); void SetXAxisLabel(const std::string &label); void SetYAxisLabel(const std::string &label); void SetPieLabels(const std::vector &pieLabels, const std::string &label); void SetTitle(const std::string &title); void SetXErrorBars(const std::string &label, const std::vector &errorPlus, const std::vector &errorMinus = std::vector()); void SetYErrorBars(const std::string &label, const std::vector &errorPlus, const std::vector &errorMinus = std::vector()); std::string GetThemeName() const; void SetThemeName(ColorTheme style); void SetLegendPosition(LegendPosition position); void Show(bool showSubChart); void SetShowLegend(bool show); void SetShowErrorBars(bool show); void SetStackedData(bool stacked); void SetShowDataPoints(bool showDataPoints = false); void SetShowSubchart(bool showSubChart); void SetChartType(const std::string &label, QmitkChartWidget::ChartType chartType); void SetMinMaxValueXView(double minValueX, double maxValueX); void SetMinMaxValueYView(double minValueY, double maxValueY); QList ConvertErrorVectorToQList(const std::vector &error); QList ConvertVectorToQList(const std::vector &vec); std::string ConvertChartTypeToString(QmitkChartWidget::ChartType chartType) const; void ClearJavaScriptChart(); void InitializeJavaScriptChart(); void CallJavaScriptFuntion(const QString &command); QSize sizeHint() const; void GetImageUrl(); private: using ChartxyDataVector = std::vector>; std::string GetUniqueLabelName(const QList &labelList, const std::string &label) const; QList GetDataLabels(const ChartxyDataVector &c3xyData) const; QWebChannel *m_WebChannel; QWebEngineView *m_WebEngineView; QmitkChartData m_C3Data; ChartxyDataVector m_C3xyData; std::map m_ChartTypeToName; std::map m_ChartColorToName; std::map m_ColorThemeToName; std::map m_LegendPositionToName; std::map m_LineStyleToName; std::map m_MarkerSymbolToName; std::map m_AxisScaleToName; }; QmitkChartWidget::Impl::Impl(QWidget *parent) : m_WebChannel(new QWebChannel(parent)), m_WebEngineView(new QWebEngineView(parent)) { // disable context menu for QWebEngineView m_WebEngineView->setContextMenuPolicy(Qt::NoContextMenu); m_WebEngineView->setPage(new CustomPage()); // Set the webengineview to an initial empty page. The actual chart will be loaded once the data is calculated. m_WebEngineView->load(QUrl(QStringLiteral("qrc:///Chart/empty.html"))); m_WebEngineView->page()->setWebChannel(m_WebChannel); m_WebEngineView->settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, false); //This is added as a workarround for T28252 (https://phabricator.mitk.org/T28252) //can be removed if task is properly fixed. m_WebEngineView->settings()->setAttribute(QWebEngineSettings::ShowScrollBars, false); connect(m_WebEngineView, SIGNAL(loadFinished(bool)), parent, SLOT(OnLoadFinished(bool))); auto layout = new QGridLayout(parent); - layout->setMargin(0); + layout->setContentsMargins({}); layout->addWidget(m_WebEngineView); m_ChartTypeToName.emplace(ChartType::bar, "bar"); m_ChartTypeToName.emplace(ChartType::line, "line"); m_ChartTypeToName.emplace(ChartType::spline, "spline"); m_ChartTypeToName.emplace(ChartType::pie, "pie"); m_ChartTypeToName.emplace(ChartType::area, "area"); m_ChartTypeToName.emplace(ChartType::area_spline, "area-spline"); m_ChartTypeToName.emplace(ChartType::scatter, "scatter"); m_ChartColorToName.emplace(ChartColor::red, "red"); m_ChartColorToName.emplace(ChartColor::orange, "orange"); m_ChartColorToName.emplace(ChartColor::yellow, "yellow"); m_ChartColorToName.emplace(ChartColor::green, "green"); m_ChartColorToName.emplace(ChartColor::blue, "blue"); m_ChartColorToName.emplace(ChartColor::purple, "purple"); m_ChartColorToName.emplace(ChartColor::brown, "brown"); m_ChartColorToName.emplace(ChartColor::magenta, "magenta"); m_ChartColorToName.emplace(ChartColor::tan, "tan"); m_ChartColorToName.emplace(ChartColor::cyan, "cyan"); m_ChartColorToName.emplace(ChartColor::olive, "olive"); m_ChartColorToName.emplace(ChartColor::maroon, "maroon"); m_ChartColorToName.emplace(ChartColor::navy, "navy"); m_ChartColorToName.emplace(ChartColor::aquamarine, "aquamarine"); m_ChartColorToName.emplace(ChartColor::turqouise, "turqouise"); m_ChartColorToName.emplace(ChartColor::silver, "silver"); m_ChartColorToName.emplace(ChartColor::lime, "lime"); m_ChartColorToName.emplace(ChartColor::teal, "teal"); m_ChartColorToName.emplace(ChartColor::indigo, "indigo"); m_ChartColorToName.emplace(ChartColor::violet, "violet"); m_ChartColorToName.emplace(ChartColor::pink, "pink"); m_ChartColorToName.emplace(ChartColor::black, "black"); m_ChartColorToName.emplace(ChartColor::white, "white"); m_ChartColorToName.emplace(ChartColor::grey, "grey"); m_LegendPositionToName.emplace(LegendPosition::bottomMiddle, "bottomMiddle"); m_LegendPositionToName.emplace(LegendPosition::bottomRight, "bottomRight"); m_LegendPositionToName.emplace(LegendPosition::topRight, "topRight"); m_LegendPositionToName.emplace(LegendPosition::topLeft, "topLeft"); m_LegendPositionToName.emplace(LegendPosition::middleRight, "middleRight"); m_LineStyleToName.emplace(LineStyle::solid, "solid"); m_LineStyleToName.emplace(LineStyle::dashed, "dashed"); m_MarkerSymbolToName.emplace(MarkerSymbol::circle, "circle"); m_MarkerSymbolToName.emplace(MarkerSymbol::cross, "cross"); m_MarkerSymbolToName.emplace(MarkerSymbol::diamond, "diamond"); m_MarkerSymbolToName.emplace(MarkerSymbol::pentagon, "pentagon"); m_MarkerSymbolToName.emplace(MarkerSymbol::square, "square"); m_MarkerSymbolToName.emplace(MarkerSymbol::star, "star"); m_MarkerSymbolToName.emplace(MarkerSymbol::x, "x"); m_MarkerSymbolToName.emplace(MarkerSymbol::diamond_tall, "diamond-tall"); m_MarkerSymbolToName.emplace(MarkerSymbol::star_diamond, "star-diamond"); m_MarkerSymbolToName.emplace(MarkerSymbol::star_triangle_up, "star-triangle-up"); m_MarkerSymbolToName.emplace(MarkerSymbol::star_triangle_down, "star-triangle-down"); m_MarkerSymbolToName.emplace(MarkerSymbol::asterisk, "asterisk"); m_MarkerSymbolToName.emplace(MarkerSymbol::cross_thin, "cross-thin"); m_MarkerSymbolToName.emplace(MarkerSymbol::x_thin, "x-thin"); m_AxisScaleToName.emplace(AxisScale::linear, ""); m_AxisScaleToName.emplace(AxisScale::log, "log"); m_ColorThemeToName.emplace(ColorTheme::lightstyle, "light"); m_ColorThemeToName.emplace(ColorTheme::darkstyle, "dark"); } QmitkChartWidget::Impl::~Impl() {} std::string QmitkChartWidget::Impl::GetThemeName() const { return m_C3Data.GetThemeName().toString().toStdString(); } std::string CheckForCorrectHex(const std::string &colorName) { std::regex rgx("([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"); std::smatch match; if (!colorName.empty() && colorName.at(0) != '#' && std::regex_search(colorName.begin(), colorName.end(), match, rgx)) { return "#" + colorName; } else { return colorName; } } void QmitkChartWidget::Impl::GetImageUrl() { m_C3Data.EmitSignalImageUrl(); } void QmitkChartWidget::Impl::AddData1D(const std::vector &data1D, const std::string &label, QmitkChartWidget::ChartType type) { std::vector< std::pair > transformedData2D; unsigned int count = 0; // transform the 1D data to 2D data for (const auto &ele : data1D) { transformedData2D.emplace_back(count, ele); count++; } AddData2D(transformedData2D, label, type); } void QmitkChartWidget::Impl::AddData2D(const std::vector< std::pair > &data2D, const std::string &label, QmitkChartWidget::ChartType type) { const std::string chartTypeName(m_ChartTypeToName.at(type)); auto definedLabels = GetDataLabels(m_C3xyData); auto uniqueLabel = GetUniqueLabelName(definedLabels, label); unsigned int sizeOfC3xyData = static_cast(m_C3xyData.size()); m_C3xyData.push_back(std::make_unique(data2D, QVariant(QString::fromStdString(uniqueLabel)), QVariant(QString::fromStdString(chartTypeName)), QVariant(sizeOfC3xyData))); } void QmitkChartWidget::Impl::AddChartExampleData(const std::vector< std::pair >& data2D, const std::string& label, const std::string& type, const std::string& color, const std::string& lineStyle, const std::string& pieLabelsData) { auto definedLabels = GetDataLabels(m_C3xyData); auto uniqueLabel = GetUniqueLabelName(definedLabels, label); if (type == "scatter") { SetShowDataPoints(true); MITK_INFO << "Enabling data points for all because of scatter plot"; } unsigned int sizeOfC3xyData = static_cast(m_C3xyData.size()); std::unique_ptr chartData = std::make_unique( data2D, QVariant(QString::fromStdString(uniqueLabel)), QVariant(QString::fromStdString(type)), QVariant(sizeOfC3xyData)); chartData->SetColor(QVariant(QString::fromStdString(color))); chartData->SetLineStyle(QVariant(QString::fromStdString(lineStyle))); if (pieLabelsData != "") { std::string pieLabelsDataWorkingString = pieLabelsData; QList pieLabelsDataList; while (pieLabelsDataWorkingString.size() != 0) { QVariant oneElement = QString::fromStdString(pieLabelsDataWorkingString.substr(0, pieLabelsDataWorkingString.find(";"))); pieLabelsDataList.push_back(oneElement); if (pieLabelsDataWorkingString.find(";") != std::string::npos) { pieLabelsDataWorkingString.erase(0, pieLabelsDataWorkingString.find(";") + 1); } else { pieLabelsDataWorkingString.erase(pieLabelsDataWorkingString.begin(), pieLabelsDataWorkingString.end()); } } chartData->SetPieLabels(pieLabelsDataList); } m_C3xyData.push_back(std::move(chartData)); } void QmitkChartWidget::Impl::UpdateData1D(const std::vector &data1D, const std::string &label) { std::vector< std::pair > transformedData2D; unsigned int count = 0; // transform the 1D data to 2D data for (const auto &ele : data1D) { transformedData2D.emplace_back( count, ele ); count++; } UpdateData2D(transformedData2D, label); } void QmitkChartWidget::Impl::UpdateData2D(const std::vector< std::pair > &data2D, const std::string &label) { auto element = GetDataElementByLabel(label); if (element) element->SetData(data2D); } void QmitkChartWidget::Impl::UpdateChartExampleData(const std::vector< std::pair >& data2D, const std::string& label, const std::string& type, const std::string& color, const std::string& lineStyle, const std::string& pieLabelsData) { UpdateData2D(data2D, label); auto element = GetDataElementByLabel(label); if (element) { element->SetChartType(QString::fromStdString(type)); element->SetColor(QString::fromStdString(color)); element->SetLineStyle(QString::fromStdString(lineStyle)); if (pieLabelsData != "") { std::string pieLabelsDataWorkingString = pieLabelsData; QList pieLabelsDataList; while (pieLabelsDataWorkingString.size() != 0) { QVariant oneElement = QString::fromStdString(pieLabelsDataWorkingString.substr(0, pieLabelsDataWorkingString.find(";"))); pieLabelsDataList.push_back(oneElement); if (pieLabelsDataWorkingString.find(";") != std::string::npos) { pieLabelsDataWorkingString.erase(0, pieLabelsDataWorkingString.find(";") + 1); } else { pieLabelsDataWorkingString.erase(pieLabelsDataWorkingString.begin(), pieLabelsDataWorkingString.end()); } } element->SetPieLabels(pieLabelsDataList); } } } void QmitkChartWidget::Impl::RemoveData(const std::string &label) { for (ChartxyDataVector::iterator iter = m_C3xyData.begin(); iter != m_C3xyData.end(); ++iter) { if ((*iter)->GetLabel().toString().toStdString() == label) { m_C3xyData.erase(iter); return; } } throw std::invalid_argument("Cannot Remove Data because the label does not exist."); } void QmitkChartWidget::Impl::ClearData() { for (auto &xyData : m_C3xyData) { m_WebChannel->deregisterObject(xyData.get()); } m_C3xyData.clear(); } void QmitkChartWidget::Impl::UpdateLabel(const std::string &existingLabel, const std::string &newLabel) { auto element = GetDataElementByLabel(existingLabel); if (element) { auto definedLabels = GetDataLabels(m_C3xyData); auto uniqueLabel = GetUniqueLabelName(definedLabels, newLabel); element->SetLabel(QString::fromStdString(uniqueLabel)); } } void QmitkChartWidget::Impl::SetColor(const std::string &label, const std::string &colorName) { auto element = GetDataElementByLabel(label); if (element) { auto colorChecked = CheckForCorrectHex(colorName); element->SetColor(QVariant(QString::fromStdString(colorChecked))); } } void QmitkChartWidget::Impl::SetLineStyle(const std::string &label, LineStyle style) { auto element = GetDataElementByLabel(label); const std::string lineStyleName(m_LineStyleToName.at(style)); element->SetLineStyle(QVariant(QString::fromStdString(lineStyleName))); } void QmitkChartWidget::Impl::SetMarkerSymbol(const std::string &label, MarkerSymbol symbol) { auto element = GetDataElementByLabel(label); const std::string markerSymbolName(m_MarkerSymbolToName.at(symbol)); element->SetMarkerSymbol(QVariant(QString::fromStdString(markerSymbolName))); } void QmitkChartWidget::Impl::SetYAxisScale(AxisScale scale) { const std::string axisScaleName(m_AxisScaleToName.at(scale)); m_C3Data.SetYAxisScale(QString::fromStdString(axisScaleName)); } QmitkChartxyData *QmitkChartWidget::Impl::GetDataElementByLabel(const std::string &label) const { for (const auto &qmitkChartxyData : m_C3xyData) { if (qmitkChartxyData->GetLabel().toString() == label.c_str()) { return qmitkChartxyData.get(); } } return nullptr; } QList QmitkChartWidget::Impl::GetDataLabels(const ChartxyDataVector &c3xyData) const { QList dataLabels; for (auto element = c3xyData.begin(); element != c3xyData.end(); ++element) { dataLabels.push_back((*element)->GetLabel()); } return dataLabels; } void QmitkChartWidget::Impl::SetXAxisLabel(const std::string &label) { m_C3Data.SetXAxisLabel(QString::fromStdString(label)); } void QmitkChartWidget::Impl::SetYAxisLabel(const std::string &label) { m_C3Data.SetYAxisLabel(QString::fromStdString(label)); } void QmitkChartWidget::Impl::SetPieLabels(const std::vector &pieLabels, const std::string &label) { auto element = GetDataElementByLabel(label); if (element) { if (element->GetChartType() == QVariant("pie")) { auto dataY = element->GetYData(); element->SetPieLabels(ConvertVectorToQList(pieLabels)); if (static_cast(dataY.size()) != pieLabels.size()) { MITK_INFO << "data has " << dataY.size() << " entries whereas pie labels have " << pieLabels.size() << " entries. Unnamed pie labels automatically get a numerical label."; } } else { MITK_INFO << "label" << label << "has chart type " << element->GetChartType().toString().toStdString() << ", but pie is required"; } } } void QmitkChartWidget::Impl::SetTitle(const std::string &title) { m_C3Data.SetTitle(QString::fromStdString(title)); } void QmitkChartWidget::Impl::SetThemeName(QmitkChartWidget::ColorTheme style) { const std::string themeName(m_ColorThemeToName.at(style)); m_C3Data.SetThemeName(QString::fromStdString(themeName)); } void QmitkChartWidget::Impl::SetLegendPosition(QmitkChartWidget::LegendPosition legendPosition) { const std::string legendPositionName(m_LegendPositionToName.at(legendPosition)); m_C3Data.SetLegendPosition(QString::fromStdString(legendPositionName)); } void QmitkChartWidget::Impl::Show(bool showSubChart) { if (m_C3xyData.empty()) { MITK_WARN << "no data available for display in chart"; } else { m_C3Data.SetAppearance(showSubChart, m_C3xyData.front()->GetChartType() == QVariant("pie")); } InitializeJavaScriptChart(); } void QmitkChartWidget::Impl::SetShowLegend(bool show) { m_C3Data.SetShowLegend(show); } void QmitkChartWidget::Impl::SetStackedData(bool stacked) { m_C3Data.SetStackedData(stacked); } void QmitkChartWidget::Impl::SetShowErrorBars(bool show) { m_C3Data.SetShowErrorBars(show); } void QmitkChartWidget::Impl::SetShowDataPoints(bool showDataPoints) { if (showDataPoints == true) { m_C3Data.SetDataPointSize(6.5); } else { m_C3Data.SetDataPointSize(0); } } void QmitkChartWidget::Impl::SetShowSubchart(bool showSubChart) { m_C3Data.SetShowSubchart(showSubChart); } void QmitkChartWidget::Impl::SetChartType(const std::string &label, QmitkChartWidget::ChartType chartType) { auto element = GetDataElementByLabel(label); if (element) { if (chartType == ChartType::scatter) { SetShowDataPoints(true); MITK_INFO << "Enabling data points for all because of scatter plot"; } const std::string chartTypeName(m_ChartTypeToName.at(chartType)); element->SetChartType(QVariant(QString::fromStdString(chartTypeName))); } } void QmitkChartWidget::Impl::SetMinMaxValueXView(double minValueX, double maxValueX) { m_C3Data.SetMinValueXView(minValueX); m_C3Data.SetMaxValueXView(maxValueX); } void QmitkChartWidget::Impl::SetMinMaxValueYView(double minValueY, double maxValueY) { m_C3Data.SetMinValueYView(minValueY); m_C3Data.SetMaxValueYView(maxValueY); } QList QmitkChartWidget::Impl::ConvertErrorVectorToQList(const std::vector &error) { QList errorConverted; for (const auto &aValue : error) { errorConverted.append(aValue); } return errorConverted; } QList QmitkChartWidget::Impl::ConvertVectorToQList(const std::vector &vec) { QList vecConverted; for (const auto &aValue : vec) { vecConverted.append(QString::fromStdString(aValue)); } return vecConverted; } void QmitkChartWidget::Impl::SetXErrorBars(const std::string &label, const std::vector &errorPlus, const std::vector &errorMinus) { auto element = GetDataElementByLabel(label); if (element) { auto errorConvertedPlus = ConvertErrorVectorToQList(errorPlus); auto errorConvertedMinus = ConvertErrorVectorToQList(errorMinus); element->SetXErrorDataPlus(errorConvertedPlus); element->SetXErrorDataMinus(errorConvertedMinus); } } void QmitkChartWidget::Impl::SetYErrorBars(const std::string &label, const std::vector &errorPlus, const std::vector &errorMinus) { auto element = GetDataElementByLabel(label); if (element) { auto errorConvertedPlus = ConvertErrorVectorToQList(errorPlus); auto errorConvertedMinus = ConvertErrorVectorToQList(errorMinus); element->SetYErrorDataPlus(errorConvertedPlus); element->SetYErrorDataMinus(errorConvertedMinus); } } std::string QmitkChartWidget::Impl::ConvertChartTypeToString(QmitkChartWidget::ChartType chartType) const { return m_ChartTypeToName.at(chartType); } QSize QmitkChartWidget::Impl::sizeHint() const { return QSize(400, 300); } void QmitkChartWidget::Impl::CallJavaScriptFuntion(const QString &command) { m_WebEngineView->page()->runJavaScript(command); } void QmitkChartWidget::Impl::ClearJavaScriptChart() { m_WebEngineView->load(QUrl(QStringLiteral("qrc:///Chart/empty.html"))); } void QmitkChartWidget::Impl::InitializeJavaScriptChart() { auto alreadyRegisteredObjects = m_WebChannel->registeredObjects(); auto alreadyRegisteredObjectsValues = alreadyRegisteredObjects.values(); // only register objects that have not been registered yet if (alreadyRegisteredObjectsValues.indexOf(&m_C3Data) == -1) { m_WebChannel->registerObject(QStringLiteral("chartData"), &m_C3Data); } unsigned count = 0; for (auto &xyData : m_C3xyData) { // only register objects that have not been registered yet if (alreadyRegisteredObjectsValues.indexOf(xyData.get()) == -1) { QString variableName = "xyData" + QString::number(count); m_WebChannel->registerObject(variableName, xyData.get()); } count++; } m_WebEngineView->load(QUrl(QStringLiteral("qrc:///Chart/QmitkChartWidget.html"))); } std::string QmitkChartWidget::Impl::GetUniqueLabelName(const QList &labelList, const std::string &label) const { QString currentLabel = QString::fromStdString(label); int counter = 0; while (labelList.contains(currentLabel)) { currentLabel = QString::fromStdString(label + std::to_string(counter)); counter++; } return currentLabel.toStdString(); } QmitkChartWidget::QmitkChartWidget(QWidget *parent) : QWidget(parent), m_Impl(new Impl(this)) { connect(this, &QmitkChartWidget::PageSuccessfullyLoaded, this, &QmitkChartWidget::OnPageSuccessfullyLoaded); } QmitkChartWidget::~QmitkChartWidget() {} void QmitkChartWidget::SetColor(const std::string &label, const std::string &colorName) { m_Impl->SetColor(label, colorName); } void QmitkChartWidget::SetLineStyle(const std::string &label, LineStyle style) { m_Impl->SetLineStyle(label, style); } void QmitkChartWidget::SetMarkerSymbol(const std::string &label, MarkerSymbol symbol) { m_Impl->SetMarkerSymbol(label, symbol); } void QmitkChartWidget::SetYAxisScale(AxisScale scale) { m_Impl->SetYAxisScale(scale); } void QmitkChartWidget::AddData1D(const std::vector &data1D, const std::string &label, ChartType type) { m_Impl->AddData1D(data1D, label, type); } void QmitkChartWidget::AddData2D(const std::vector< std::pair >& data2D, const std::string& label, ChartType type) { m_Impl->AddData2D(data2D, label, type); } void QmitkChartWidget::AddChartExampleData(const std::vector< std::pair >& data2D, const std::string& label, const std::string& type, const std::string& color, const std::string& lineStyle, const std::string& pieLabelsData) { m_Impl->AddChartExampleData(data2D, label, type, color, lineStyle, pieLabelsData); } void QmitkChartWidget::UpdateData1D(const std::vector &data1D, const std::string &label) { m_Impl->UpdateData1D(data1D, label); } void QmitkChartWidget::UpdateData2D(const std::vector< std::pair > &data2D, const std::string &label) { m_Impl->UpdateData2D(data2D, label); } void QmitkChartWidget::UpdateChartExampleData(const std::vector< std::pair >& data2D, const std::string& label, const std::string& type, const std::string& color, const std::string& lineStyle, const std::string& pieLabelsData) { m_Impl->UpdateChartExampleData(data2D, label, type, color, lineStyle, pieLabelsData); } void QmitkChartWidget::RemoveData(const std::string &label) { m_Impl->RemoveData(label); } void QmitkChartWidget::UpdateLabel(const std::string &existingLabel, const std::string &newLabel) { m_Impl->UpdateLabel(existingLabel, newLabel); } QmitkChartxyData* QmitkChartWidget::GetDataElementByLabel(const std::string& label) const { return m_Impl->GetDataElementByLabel(label); } void QmitkChartWidget::SetXAxisLabel(const std::string &label) { m_Impl->SetXAxisLabel(label); } void QmitkChartWidget::SetYAxisLabel(const std::string &label) { m_Impl->SetYAxisLabel(label); } void QmitkChartWidget::SetPieLabels(const std::vector &pieLabels, const std::string &label) { m_Impl->SetPieLabels(pieLabels, label); } void QmitkChartWidget::SetTitle(const std::string &title) { m_Impl->SetTitle(title); } void QmitkChartWidget::SetShowDataPoints(bool showDataPoints) { m_Impl->SetShowDataPoints(showDataPoints); } void QmitkChartWidget::SetChartType(const std::string &label, ChartType type) { m_Impl->SetChartType(label, type); } void QmitkChartWidget::SetXErrorBars(const std::string &label, const std::vector &errorPlus, const std::vector &errorMinus) { m_Impl->SetXErrorBars(label, errorPlus, errorMinus); } void QmitkChartWidget::SetYErrorBars(const std::string &label, const std::vector &errorPlus, const std::vector &errorMinus) { m_Impl->SetYErrorBars(label, errorPlus, errorMinus); } void QmitkChartWidget::SetLegendPosition(LegendPosition position) { m_Impl->SetLegendPosition(position); } void QmitkChartWidget::SetShowLegend(bool show) { m_Impl->SetShowLegend(show); } void QmitkChartWidget::SetStackedData(bool stacked) { m_Impl->SetStackedData(stacked); } void QmitkChartWidget::Show(bool showSubChart) { m_Impl->Show(showSubChart); } void QmitkChartWidget::Clear() { m_Impl->ClearData(); m_Impl->ClearJavaScriptChart(); } void QmitkChartWidget::OnLoadFinished(bool isLoadSuccessful) { if (isLoadSuccessful) { emit PageSuccessfullyLoaded(); } } void QmitkChartWidget::OnPageSuccessfullyLoaded() { auto themeName = m_Impl->GetThemeName(); QString command; if (themeName == "dark") { command = QString("changeTheme('dark')"); } else { command = QString("changeTheme('light')"); } m_Impl->CallJavaScriptFuntion(command); } void QmitkChartWidget::SetTheme(ColorTheme themeEnabled) { m_Impl->SetThemeName(themeEnabled); } void QmitkChartWidget::SetShowSubchart(bool showSubChart) { m_Impl->SetShowSubchart(showSubChart); } void QmitkChartWidget::SetShowErrorBars(bool showErrorBars) { m_Impl->SetShowErrorBars(showErrorBars); } void QmitkChartWidget::SetMinMaxValueXView(double minValueX, double maxValueX) { m_Impl->SetMinMaxValueXView(minValueX, maxValueX); } void QmitkChartWidget::SetMinMaxValueYView(double minValueY, double maxValueY) { m_Impl->SetMinMaxValueYView(minValueY, maxValueY); } void QmitkChartWidget::Reload() { const QString command = QString("Reload()"); m_Impl->CallJavaScriptFuntion(command); } QSize QmitkChartWidget::sizeHint() const { return m_Impl->sizeHint(); } void QmitkChartWidget::SavePlotAsImage() { m_Impl->GetImageUrl(); } diff --git a/Modules/QtWidgets/src/QmitkLineEditLevelWindowWidget.cpp b/Modules/QtWidgets/src/QmitkLineEditLevelWindowWidget.cpp index e11dcbfb6a..29223cadf2 100644 --- a/Modules/QtWidgets/src/QmitkLineEditLevelWindowWidget.cpp +++ b/Modules/QtWidgets/src/QmitkLineEditLevelWindowWidget.cpp @@ -1,168 +1,168 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkLineEditLevelWindowWidget.h" // mitk core #include // mitk qt widgets #include // qt #include #include #include // itk #include // c++ #include #include QmitkLineEditLevelWindowWidget::QmitkLineEditLevelWindowWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { m_Manager = mitk::LevelWindowManager::New(); itk::ReceptorMemberCommand::Pointer command = itk::ReceptorMemberCommand::New(); command->SetCallbackFunction(this, &QmitkLineEditLevelWindowWidget::OnPropertyModified); m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command); m_IsObserverTagSet = true; m_Contextmenu = new QmitkLevelWindowWidgetContextMenu(this); auto layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins({}); layout->setSpacing(0); m_LevelInput = new QLineEdit(this); m_LevelInput->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); m_LevelInput->setToolTip("Edit this field to change the center of the levelwindow."); m_WindowInput = new QLineEdit(this); m_WindowInput->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); m_WindowInput->setToolTip( "Edit this field to change the span of the levelwindow. This number describes the whole span around the center."); layout->addWidget(m_LevelInput); layout->addWidget(m_WindowInput); // signals and slots connections connect(m_LevelInput, SIGNAL(editingFinished()), this, SLOT(SetLevelValue())); connect(m_WindowInput, SIGNAL(editingFinished()), this, SLOT(SetWindowValue())); // Validator for both LineEdit-widgets, to limit the valid input-range to int. QValidator *validatorWindowInput = new QDoubleValidator(0, std::numeric_limits::max(), 2, this); m_WindowInput->setValidator(validatorWindowInput); this->hide(); } QmitkLineEditLevelWindowWidget::~QmitkLineEditLevelWindowWidget() { if (m_IsObserverTagSet) { m_Manager->RemoveObserver(m_ObserverTag); m_IsObserverTagSet = false; } } void QmitkLineEditLevelWindowWidget::OnPropertyModified(const itk::EventObject &) { try { m_LevelWindow = m_Manager->GetLevelWindow(); QString level; QString window; if (m_LevelWindow.IsFloatingValues()) { std::stringstream ssLevel; std::stringstream ssWindow; ssLevel << std::setprecision(3) << m_LevelWindow.GetLevel(); ssWindow << std::setprecision(3) << m_LevelWindow.GetWindow(); level = ssLevel.str().c_str(); window = ssWindow.str().c_str(); } else { level.setNum((int)(m_LevelWindow.GetLevel())); window.setNum((int)(m_LevelWindow.GetWindow())); } m_LevelInput->setText(level); m_WindowInput->setText(window); m_LevelInput->setEnabled(!m_LevelWindow.IsFixed()); m_WindowInput->setEnabled(!m_LevelWindow.IsFixed()); this->show(); } catch (...) { try { this->hide(); } catch (...) { } } } void QmitkLineEditLevelWindowWidget::SetLevelWindowManager(mitk::LevelWindowManager *levelWindowManager) { if (m_IsObserverTagSet) { m_Manager->RemoveObserver(m_ObserverTag); m_IsObserverTagSet = false; } m_Manager = levelWindowManager; if (m_Manager.IsNotNull()) { itk::ReceptorMemberCommand::Pointer command = itk::ReceptorMemberCommand::New(); command->SetCallbackFunction(this, &QmitkLineEditLevelWindowWidget::OnPropertyModified); m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command); m_IsObserverTagSet = true; } } void QmitkLineEditLevelWindowWidget::SetDataStorage(mitk::DataStorage *ds) { m_Manager->SetDataStorage(ds); } void QmitkLineEditLevelWindowWidget::SetLevelValue() { double level = m_LevelInput->text().toDouble(); m_LevelWindow.SetLevelWindow(level, m_LevelWindow.GetWindow()); m_Manager->SetLevelWindow(m_LevelWindow); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkLineEditLevelWindowWidget::SetWindowValue() { double window = m_WindowInput->text().toDouble(); m_LevelWindow.SetLevelWindow(m_LevelWindow.GetLevel(), window); m_Manager->SetLevelWindow(m_LevelWindow); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkLineEditLevelWindowWidget::contextMenuEvent(QContextMenuEvent *) { m_Contextmenu->SetLevelWindowManager(m_Manager.GetPointer()); m_Contextmenu->GetContextMenu(); } mitk::LevelWindowManager *QmitkLineEditLevelWindowWidget::GetManager() { return m_Manager.GetPointer(); } diff --git a/Modules/QtWidgets/src/QmitkMultiWidgetLayoutManager.cpp b/Modules/QtWidgets/src/QmitkMultiWidgetLayoutManager.cpp index 96b441e343..51bf4daa58 100644 --- a/Modules/QtWidgets/src/QmitkMultiWidgetLayoutManager.cpp +++ b/Modules/QtWidgets/src/QmitkMultiWidgetLayoutManager.cpp @@ -1,541 +1,541 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkMultiWidgetLayoutManager.h" #include #include #include #include // qt #include #include QmitkMultiWidgetLayoutManager::QmitkMultiWidgetLayoutManager(QmitkAbstractMultiWidget* multiwidget) : QObject(multiwidget) , m_MultiWidget(multiwidget) , m_CurrentRenderWindowWidget(nullptr) { // nothing here } void QmitkMultiWidgetLayoutManager::SetLayoutDesign(LayoutDesign layoutDesign) { if (nullptr == m_MultiWidget) { return; } // retrieve the render window name from the sending render window auto renderWindow = dynamic_cast(QObject::sender()); m_CurrentRenderWindowWidget = m_MultiWidget->GetRenderWindowWidget(renderWindow).get(); switch (layoutDesign) { case LayoutDesign::DEFAULT: { SetDefaultLayout(); break; } case LayoutDesign::ALL_2D_TOP_3D_BOTTOM: { SetAll2DTop3DBottomLayout(); break; } case LayoutDesign::ALL_2D_LEFT_3D_RIGHT: { SetAll2DLeft3DRightLayout(); break; } case LayoutDesign::ONE_BIG: { SetOneBigLayout(); break; } case LayoutDesign::ONLY_2D_HORIZONTAL: { SetOnly2DHorizontalLayout(); break; } case LayoutDesign::ONLY_2D_VERTICAL: { SetOnly2DVerticalLayout(); break; } case LayoutDesign::ONE_TOP_3D_BOTTOM: { SetOneTop3DBottomLayout(); break; } case LayoutDesign::ONE_LEFT_3D_RIGHT: { SetOneLeft3DRightLayout(); break; } case LayoutDesign::ALL_HORIZONTAL: { SetAllHorizontalLayout(); break; } case LayoutDesign::ALL_VERTICAL: { SetAllVerticalLayout(); break; } case LayoutDesign::REMOVE_ONE: { RemoveOneLayout(); break; } case LayoutDesign::NONE: { break; } }; } void QmitkMultiWidgetLayoutManager::SetCurrentRenderWindowWidget(QmitkRenderWindowWidget* renderWindowWidget) { m_CurrentRenderWindowWidget = renderWindowWidget; } void QmitkMultiWidgetLayoutManager::SetDefaultLayout() { MITK_DEBUG << "Set default layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(Qt::Vertical, m_MultiWidget); hBoxLayout->addWidget(mainSplit); QList splitterSizeRow; for (int row = 0; row < m_MultiWidget->GetRowCount(); ++row) { splitterSizeRow.push_back(1000); QList splitterSizeColumn; auto splitter = new QSplitter(mainSplit); for (int column = 0; column < m_MultiWidget->GetColumnCount(); ++column) { splitterSizeColumn.push_back(1000); auto renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(row, column); splitter->addWidget(renderWindowWidget.get()); renderWindowWidget->show(); } splitter->setSizes(splitterSizeColumn); } mainSplit->setSizes(splitterSizeRow); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::DEFAULT); } } void QmitkMultiWidgetLayoutManager::SetAll2DTop3DBottomLayout() { MITK_DEBUG << "Set all 2D top and 3D bottom layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(Qt::Vertical, m_MultiWidget); hBoxLayout->addWidget(mainSplit); auto subSplit2D = new QSplitter(mainSplit); QList splitterSize; auto all2DRenderWindowWidgets = m_MultiWidget->Get2DRenderWindowWidgets(); for (const auto& renderWindowWidget : all2DRenderWindowWidgets) { subSplit2D->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } subSplit2D->setSizes(splitterSize); auto subSplit3D = new QSplitter(mainSplit); splitterSize.clear(); auto all3DRenderWindowWidgets = m_MultiWidget->Get3DRenderWindowWidgets(); for (const auto& renderWindowWidget : all3DRenderWindowWidgets) { subSplit3D->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } subSplit3D->setSizes(splitterSize); // set size for main splitter splitterSize.clear(); splitterSize.push_back(600); splitterSize.push_back(1000); mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ALL_2D_TOP_3D_BOTTOM); } } void QmitkMultiWidgetLayoutManager::SetAll2DLeft3DRightLayout() { MITK_DEBUG << "Set all 2D left and 3D right layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(m_MultiWidget); hBoxLayout->addWidget(mainSplit); auto subSplit2D = new QSplitter(Qt::Vertical, mainSplit); QList splitterSize; auto all2DRenderWindowWidgets = m_MultiWidget->Get2DRenderWindowWidgets(); for (const auto& renderWindowWidget : all2DRenderWindowWidgets) { subSplit2D->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } subSplit2D->setSizes(splitterSize); auto subSplit3D = new QSplitter(mainSplit); splitterSize.clear(); auto all3DRenderWindowWidgets = m_MultiWidget->Get3DRenderWindowWidgets(); for (const auto& renderWindowWidget : all3DRenderWindowWidgets) { subSplit3D->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } subSplit3D->setSizes(splitterSize); // set size for main splitter splitterSize.clear(); splitterSize.push_back(600); splitterSize.push_back(1000); mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ALL_2D_LEFT_3D_RIGHT); } } void QmitkMultiWidgetLayoutManager::SetOneBigLayout() { MITK_DEBUG << "Set single 2D layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(m_MultiWidget); hBoxLayout->addWidget(mainSplit); mainSplit->addWidget(m_CurrentRenderWindowWidget); m_CurrentRenderWindowWidget->show(); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ONE_BIG); } } void QmitkMultiWidgetLayoutManager::SetOnly2DHorizontalLayout() { MITK_DEBUG << "Set only 2D layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(m_MultiWidget); hBoxLayout->addWidget(mainSplit); QList splitterSize; auto all2DRenderWindowWidgets = m_MultiWidget->Get2DRenderWindowWidgets(); for (const auto& renderWindowWidget : all2DRenderWindowWidgets) { mainSplit->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ONLY_2D_HORIZONTAL); } } void QmitkMultiWidgetLayoutManager::SetOnly2DVerticalLayout() { MITK_DEBUG << "Set only 2D layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(Qt::Vertical, m_MultiWidget); hBoxLayout->addWidget(mainSplit); QList splitterSize; auto all2DRenderWindowWidgets = m_MultiWidget->Get2DRenderWindowWidgets(); for (const auto& renderWindowWidget : all2DRenderWindowWidgets) { mainSplit->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ONLY_2D_VERTICAL); } } void QmitkMultiWidgetLayoutManager::SetOneTop3DBottomLayout() { MITK_DEBUG << "Set one top and all 3D bottom layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(Qt::Vertical, m_MultiWidget); hBoxLayout->addWidget(mainSplit); mainSplit->addWidget(m_CurrentRenderWindowWidget); m_CurrentRenderWindowWidget->show(); auto subSplit3D = new QSplitter(mainSplit); QList splitterSize; auto all3DRenderWindowWidgets = m_MultiWidget->Get3DRenderWindowWidgets(); for (const auto& renderWindowWidget : all3DRenderWindowWidgets) { subSplit3D->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } subSplit3D->setSizes(splitterSize); // set size for main splitter splitterSize.clear(); splitterSize.push_back(1000); splitterSize.push_back(1000); mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ONE_TOP_3D_BOTTOM); } } void QmitkMultiWidgetLayoutManager::SetOneLeft3DRightLayout() { MITK_DEBUG << "Set one left and all 3D right layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(m_MultiWidget); hBoxLayout->addWidget(mainSplit); mainSplit->addWidget(m_CurrentRenderWindowWidget); m_CurrentRenderWindowWidget->show(); auto subSplit3D = new QSplitter(Qt::Vertical, mainSplit); QList splitterSize; auto all3DRenderWindowWidgets = m_MultiWidget->Get3DRenderWindowWidgets(); for (const auto& renderWindowWidget : all3DRenderWindowWidgets) { subSplit3D->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } subSplit3D->setSizes(splitterSize); // set size for main splitter splitterSize.clear(); splitterSize.push_back(1000); splitterSize.push_back(1000); mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ONE_LEFT_3D_RIGHT); } } void QmitkMultiWidgetLayoutManager::SetAllHorizontalLayout() { MITK_DEBUG << "Set all horizontal layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(m_MultiWidget); hBoxLayout->addWidget(mainSplit); QList splitterSize; auto allRenderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets(); for (const auto& renderWindowWidget : allRenderWindowWidgets) { if (nullptr != renderWindowWidget.second) { mainSplit->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } } // set size for main splitter mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ALL_HORIZONTAL); } } void QmitkMultiWidgetLayoutManager::SetAllVerticalLayout() { MITK_DEBUG << "Set all vertical layout"; m_MultiWidget->ActivateMenuWidget(false); delete m_MultiWidget->layout(); auto hBoxLayout = new QHBoxLayout(m_MultiWidget); hBoxLayout->setContentsMargins(0, 0, 0, 0); m_MultiWidget->setLayout(hBoxLayout); - hBoxLayout->setMargin(0); + hBoxLayout->setContentsMargins({}); auto mainSplit = new QSplitter(Qt::Vertical, m_MultiWidget); hBoxLayout->addWidget(mainSplit); QList splitterSize; auto allRenderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets(); for (const auto& renderWindowWidget : allRenderWindowWidgets) { mainSplit->addWidget(renderWindowWidget.second.get()); renderWindowWidget.second->show(); splitterSize.push_back(1000); } // set size for splitter mainSplit->setSizes(splitterSize); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::ALL_VERTICAL); } } void QmitkMultiWidgetLayoutManager::RemoveOneLayout() { MITK_DEBUG << "Remove single render window"; m_MultiWidget->ActivateMenuWidget(false); m_CurrentRenderWindowWidget->hide(); m_MultiWidget->ActivateMenuWidget(true); auto allRenderWindows = m_MultiWidget->GetRenderWindows(); for (auto& renderWindow : allRenderWindows) { renderWindow->UpdateLayoutDesignList(LayoutDesign::NONE); } } diff --git a/Modules/QtWidgets/src/QmitkPropertiesTableEditor.cpp b/Modules/QtWidgets/src/QmitkPropertiesTableEditor.cpp index bbaca03d47..3d870a56ec 100644 --- a/Modules/QtWidgets/src/QmitkPropertiesTableEditor.cpp +++ b/Modules/QtWidgets/src/QmitkPropertiesTableEditor.cpp @@ -1,112 +1,112 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkPropertiesTableEditor.h" #include "QmitkPropertiesTableModel.h" #include "QmitkPropertyDelegate.h" #include "mitkBaseRenderer.h" #include #include #include #include #include #include #include QmitkPropertiesTableEditor::QmitkPropertiesTableEditor(QWidget *parent, Qt::WindowFlags f, mitk::DataNode::Pointer /*_Node*/) : QWidget(parent, f), m_NodePropertiesTableView(nullptr), m_Model(nullptr) { // set up empty gui elements this->init(); // set up model m_Model = new QmitkPropertiesTableModel(m_NodePropertiesTableView, nullptr); m_NodePropertiesTableView->setModel(m_Model); } QmitkPropertiesTableEditor::~QmitkPropertiesTableEditor() { } void QmitkPropertiesTableEditor::SetPropertyList(mitk::PropertyList::Pointer _List) { if (_List.IsNotNull()) { m_Model->SetPropertyList(_List); m_NodePropertiesTableView->resizeColumnsToContents(); m_NodePropertiesTableView->resizeRowsToContents(); m_NodePropertiesTableView->horizontalHeader()->setStretchLastSection(true); m_NodePropertiesTableView->setEditTriggers(QAbstractItemView::CurrentChanged); } else { m_Model->SetPropertyList(nullptr); } } QmitkPropertiesTableModel *QmitkPropertiesTableEditor::getModel() const { return m_Model; } void QmitkPropertiesTableEditor::init() { // read/ dim QVBoxLayout *_NodePropertiesLayout = new QVBoxLayout; QWidget *_PropertyFilterKeyWordPane = new QWidget(QWidget::parentWidget()); QHBoxLayout *_PropertyFilterKeyWordLayout = new QHBoxLayout; QLabel *_LabelPropertyFilterKeyWord = new QLabel("Filter: ", _PropertyFilterKeyWordPane); m_TxtPropertyFilterKeyWord = new QLineEdit(_PropertyFilterKeyWordPane); m_NodePropertiesTableView = new QTableView(QWidget::parentWidget()); // write setLayout(_NodePropertiesLayout); _PropertyFilterKeyWordPane->setLayout(_PropertyFilterKeyWordLayout); - _PropertyFilterKeyWordLayout->setMargin(0); + _PropertyFilterKeyWordLayout->setContentsMargins({}); _PropertyFilterKeyWordLayout->addWidget(_LabelPropertyFilterKeyWord); _PropertyFilterKeyWordLayout->addWidget(m_TxtPropertyFilterKeyWord); - _NodePropertiesLayout->setMargin(0); + _NodePropertiesLayout->setContentsMargins({}); _NodePropertiesLayout->addWidget(_PropertyFilterKeyWordPane); _NodePropertiesLayout->addWidget(m_NodePropertiesTableView); m_NodePropertiesTableView->setSelectionMode(QAbstractItemView::SingleSelection); m_NodePropertiesTableView->setSelectionBehavior(QAbstractItemView::SelectItems); m_NodePropertiesTableView->verticalHeader()->hide(); m_NodePropertiesTableView->setItemDelegate(new QmitkPropertyDelegate(this)); m_NodePropertiesTableView->setAlternatingRowColors(true); m_NodePropertiesTableView->setSortingEnabled(true); m_NodePropertiesTableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); QObject::connect(m_TxtPropertyFilterKeyWord, SIGNAL(textChanged(const QString &)), this, SLOT(PropertyFilterKeyWordTextChanged(const QString &))); } void QmitkPropertiesTableEditor::PropertyFilterKeyWordTextChanged(const QString & /*text*/) { m_Model->SetFilterPropertiesKeyWord(m_TxtPropertyFilterKeyWord->text().toStdString()); } QTableView *QmitkPropertiesTableEditor::getTable() const { return m_NodePropertiesTableView; } diff --git a/Modules/QtWidgets/src/QmitkRenderWindowUtilityWidget.cpp b/Modules/QtWidgets/src/QmitkRenderWindowUtilityWidget.cpp index 4a950fb941..4934c397d3 100644 --- a/Modules/QtWidgets/src/QmitkRenderWindowUtilityWidget.cpp +++ b/Modules/QtWidgets/src/QmitkRenderWindowUtilityWidget.cpp @@ -1,185 +1,185 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkRenderWindowUtilityWidget.h" #include // mitk core #include #include #include #include // mitk qt widgets #include #include // itk #include QmitkRenderWindowUtilityWidget::QmitkRenderWindowUtilityWidget( QWidget* parent/* = nullptr */, QmitkRenderWindow* renderWindow/* = nullptr */, mitk::DataStorage* dataStorage/* = nullptr */) : m_NodeSelectionWidget(nullptr) , m_SliceNavigationWidget(nullptr) , m_StepperAdapter(nullptr) , m_ViewDirectionSelector(nullptr) { this->setParent(parent); auto layout = new QHBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins({}); mitk::NodePredicateAnd::Pointer noHelperObjects = mitk::NodePredicateAnd::New(); noHelperObjects->AddPredicate(mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))); noHelperObjects->AddPredicate(mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("hidden object"))); m_BaseRenderer = mitk::BaseRenderer::GetInstance(renderWindow->GetVtkRenderWindow()); m_NodeSelectionWidget = new QmitkSynchronizedNodeSelectionWidget(parent); m_NodeSelectionWidget->SetBaseRenderer(m_BaseRenderer); m_NodeSelectionWidget->SetDataStorage(dataStorage); m_NodeSelectionWidget->SetNodePredicate(noHelperObjects); auto menuBar = new QMenuBar(this); menuBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); menuBar->setNativeMenuBar(false); auto dataMenu = menuBar->addMenu("Data"); QWidgetAction* dataAction = new QWidgetAction(dataMenu); dataAction->setDefaultWidget(m_NodeSelectionWidget); dataMenu->addAction(dataAction); layout->addWidget(menuBar); auto* synchPushButton = new QPushButton(this); auto* synchIcon = new QIcon(); auto synchronizeSvg = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/lock.svg")); auto desynchronizeSvg = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/unlock.svg")); synchIcon->addPixmap(synchronizeSvg.pixmap(64), QIcon::Normal, QIcon::On); synchIcon->addPixmap(desynchronizeSvg.pixmap(64), QIcon::Normal, QIcon::Off); synchPushButton->setIcon(*synchIcon); synchPushButton->setToolTip("Synchronize / desynchronize data management"); synchPushButton->setCheckable(true); synchPushButton->setChecked(true); connect(synchPushButton, &QPushButton::clicked, this, &QmitkRenderWindowUtilityWidget::ToggleSynchronization); layout->addWidget(synchPushButton); auto* sliceNavigationController = m_BaseRenderer->GetSliceNavigationController(); m_SliceNavigationWidget = new QmitkSliceNavigationWidget(this); m_StepperAdapter = new QmitkStepperAdapter(m_SliceNavigationWidget, sliceNavigationController->GetStepper()); layout->addWidget(m_SliceNavigationWidget); mitk::RenderWindowLayerUtilities::RendererVector controlledRenderer{ m_BaseRenderer }; m_RenderWindowViewDirectionController = std::make_unique(); m_RenderWindowViewDirectionController->SetControlledRenderer(controlledRenderer); m_RenderWindowViewDirectionController->SetDataStorage(dataStorage); m_ViewDirectionSelector = new QComboBox(this); QStringList viewDirections{ "axial", "coronal", "sagittal"}; m_ViewDirectionSelector->insertItems(0, viewDirections); m_ViewDirectionSelector->setMinimumContentsLength(12); connect(m_ViewDirectionSelector, &QComboBox::currentTextChanged, this, &QmitkRenderWindowUtilityWidget::ChangeViewDirection); UpdateViewPlaneSelection(); layout->addWidget(m_ViewDirectionSelector); // finally add observer, after all relevant objects have been created / initialized sliceNavigationController->ConnectGeometrySendEvent(this); } QmitkRenderWindowUtilityWidget::~QmitkRenderWindowUtilityWidget() { } void QmitkRenderWindowUtilityWidget::ToggleSynchronization(bool synchronized) { m_NodeSelectionWidget->SetSynchronized(synchronized); emit SynchronizationToggled(m_NodeSelectionWidget); } void QmitkRenderWindowUtilityWidget::SetGeometry(const itk::EventObject& event) { if (!mitk::SliceNavigationController::GeometrySendEvent(nullptr, 0).CheckEvent(&event)) { return; } const auto* sliceNavigationController = m_BaseRenderer->GetSliceNavigationController(); auto viewDirection = sliceNavigationController->GetViewDirection(); unsigned int axis = 0; switch (viewDirection) { case mitk::AnatomicalPlane::Original: return; case mitk::AnatomicalPlane::Axial: { axis = 2; break; } case mitk::AnatomicalPlane::Coronal: { axis = 1; break; } case mitk::AnatomicalPlane::Sagittal: { axis = 0; break; } } const auto* inputTimeGeometry = sliceNavigationController->GetInputWorldTimeGeometry(); const mitk::BaseGeometry* rendererGeometry = m_BaseRenderer->GetCurrentWorldGeometry(); mitk::TimeStepType timeStep = sliceNavigationController->GetStepper()->GetPos(); mitk::BaseGeometry::ConstPointer geometry = inputTimeGeometry->GetGeometryForTimeStep(timeStep); if (geometry == nullptr) return; mitk::AffineTransform3D::MatrixType matrix = geometry->GetIndexToWorldTransform()->GetMatrix(); matrix.GetVnlMatrix().normalize_columns(); mitk::AffineTransform3D::MatrixType::InternalMatrixType inverseMatrix = matrix.GetInverse(); int dominantAxis = itk::Function::Max3(inverseMatrix[0][axis], inverseMatrix[1][axis], inverseMatrix[2][axis]); bool referenceGeometryAxisInverted = inverseMatrix[dominantAxis][axis] < 0; bool rendererZAxisInverted = rendererGeometry->GetAxisVector(2)[axis] < 0; m_SliceNavigationWidget->SetInverseDirection(referenceGeometryAxisInverted != rendererZAxisInverted); } void QmitkRenderWindowUtilityWidget::ChangeViewDirection(const QString& viewDirection) { m_RenderWindowViewDirectionController->SetViewDirectionOfRenderer(viewDirection.toStdString()); } void QmitkRenderWindowUtilityWidget::UpdateViewPlaneSelection() { const auto sliceNavigationController = m_BaseRenderer->GetSliceNavigationController(); const auto viewDirection = sliceNavigationController->GetDefaultViewDirection(); switch (viewDirection) { case mitk::AnatomicalPlane::Axial: m_ViewDirectionSelector->setCurrentIndex(0); break; case mitk::AnatomicalPlane::Coronal: m_ViewDirectionSelector->setCurrentIndex(1); break; case mitk::AnatomicalPlane::Sagittal: m_ViewDirectionSelector->setCurrentIndex(2); break; default: break; } } diff --git a/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp b/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp index 29325720d7..8c7d54c727 100644 --- a/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp +++ b/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp @@ -1,322 +1,322 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkRenderWindowWidget.h" // vtk #include #include QmitkRenderWindowWidget::QmitkRenderWindowWidget(QWidget* parent/* = nullptr*/, const QString& widgetName/* = ""*/, mitk::DataStorage* dataStorage/* = nullptr*/) : QFrame(parent) , m_WidgetName(widgetName) , m_DataStorage(dataStorage) , m_RenderWindow(nullptr) , m_CrosshairManager(nullptr) { this->InitializeGUI(); } QmitkRenderWindowWidget::~QmitkRenderWindowWidget() { auto sliceNavigationController = this->GetSliceNavigationController(); if (nullptr != sliceNavigationController) { sliceNavigationController->SetCrosshairEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkRenderWindowWidget::SetCrosshairPosition)); } this->DisableCrosshair(); } void QmitkRenderWindowWidget::SetDataStorage(mitk::DataStorage* dataStorage) { if (dataStorage == m_DataStorage) { return; } m_DataStorage = dataStorage; if (nullptr != m_RenderWindow) { mitk::BaseRenderer::GetInstance(m_RenderWindow->renderWindow())->SetDataStorage(dataStorage); } } mitk::SliceNavigationController* QmitkRenderWindowWidget::GetSliceNavigationController() const { return m_RenderWindow->GetSliceNavigationController(); } void QmitkRenderWindowWidget::RequestUpdate() { mitk::RenderingManager::GetInstance()->RequestUpdate(m_RenderWindow->renderWindow()); } void QmitkRenderWindowWidget::ForceImmediateUpdate() { mitk::RenderingManager::GetInstance()->ForceImmediateUpdate(m_RenderWindow->renderWindow()); } void QmitkRenderWindowWidget::AddUtilityWidget(QWidget* utilityWidget) { m_Layout->insertWidget(0, utilityWidget); } void QmitkRenderWindowWidget::SetGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower) { vtkRenderer* vtkRenderer = m_RenderWindow->GetRenderer()->GetVtkRenderer(); if (nullptr == vtkRenderer) { return; } m_GradientBackgroundColors.first = upper; m_GradientBackgroundColors.second = lower; vtkRenderer->SetBackground(lower[0], lower[1], lower[2]); vtkRenderer->SetBackground2(upper[0], upper[1], upper[2]); ShowGradientBackground(true); } void QmitkRenderWindowWidget::ShowGradientBackground(bool show) { m_RenderWindow->GetRenderer()->GetVtkRenderer()->SetGradientBackground(show); } bool QmitkRenderWindowWidget::IsGradientBackgroundOn() const { return m_RenderWindow->GetRenderer()->GetVtkRenderer()->GetGradientBackground(); } void QmitkRenderWindowWidget::SetDecorationColor(const mitk::Color& color) { m_DecorationColor = color; m_CornerAnnotation->GetTextProperty()->SetColor(m_DecorationColor[0], m_DecorationColor[1], m_DecorationColor[2]); QColor hexColor(m_DecorationColor[0] * 255, m_DecorationColor[1] * 255, m_DecorationColor[2] * 255); setStyleSheet("QmitkRenderWindowWidget { border: 2px solid " + hexColor.name(QColor::HexRgb) + "; }"); } void QmitkRenderWindowWidget::ShowColoredRectangle(bool show) { if (show) { setFrameStyle(QFrame::Box | QFrame::Plain); } else { setFrameStyle(NoFrame); } } bool QmitkRenderWindowWidget::IsColoredRectangleVisible() const { return frameStyle() > 0; } void QmitkRenderWindowWidget::ShowCornerAnnotation(bool show) { m_CornerAnnotation->SetVisibility(show); } bool QmitkRenderWindowWidget::IsCornerAnnotationVisible() const { return m_CornerAnnotation->GetVisibility() > 0; } void QmitkRenderWindowWidget::SetCornerAnnotationText(const std::string& cornerAnnotation) { m_CornerAnnotation->SetText(0, cornerAnnotation.c_str()); } std::string QmitkRenderWindowWidget::GetCornerAnnotationText() const { return std::string(m_CornerAnnotation->GetText(0)); } bool QmitkRenderWindowWidget::IsRenderWindowMenuActivated() const { return m_RenderWindow->GetActivateMenuWidgetFlag(); } void QmitkRenderWindowWidget::SetCrosshairVisibility(bool visible) { m_CrosshairManager->SetCrosshairVisibility(visible, m_RenderWindow->GetRenderer()); this->RequestUpdate(); } bool QmitkRenderWindowWidget::GetCrosshairVisibility() { return m_CrosshairManager->GetCrosshairVisibility(m_RenderWindow->GetRenderer()); } void QmitkRenderWindowWidget::SetCrosshairGap(unsigned int gapSize) { m_CrosshairManager->SetCrosshairGap(gapSize); } void QmitkRenderWindowWidget::EnableCrosshair() { m_CrosshairManager->AddCrosshairNodeToDataStorage(m_DataStorage); } void QmitkRenderWindowWidget::DisableCrosshair() { m_CrosshairManager->RemoveCrosshairNodeFromDataStorage(m_DataStorage); } void QmitkRenderWindowWidget::InitializeGUI() { m_Layout = new QVBoxLayout(this); - m_Layout->setMargin(0); + m_Layout->setContentsMargins({}); setLayout(m_Layout); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setContentsMargins(0, 0, 0, 0); if (nullptr == m_DataStorage) { return; } mitk::RenderingManager::GetInstance()->SetDataStorage(m_DataStorage); // create render window for this render window widget m_RenderWindow = new QmitkRenderWindow(this, m_WidgetName, nullptr); m_RenderWindow->SetLayoutIndex(mitk::AnatomicalPlane::Sagittal); connect(m_RenderWindow, &QmitkRenderWindow::ResetGeometry, this, &QmitkRenderWindowWidget::OnResetGeometry); auto* sliceNavigationController = this->GetSliceNavigationController(); sliceNavigationController->SetDefaultViewDirection(mitk::AnatomicalPlane::Sagittal); m_Layout->addWidget(m_RenderWindow); // set colors and corner annotation InitializeDecorations(); // use crosshair manager m_CrosshairManager = mitk::CrosshairManager::New(m_RenderWindow->GetRenderer()); sliceNavigationController->SetCrosshairEvent.AddListener( mitk::MessageDelegate1( this, &QmitkRenderWindowWidget::SetCrosshairPosition)); // finally add observer, after all relevant objects have been created / initialized sliceNavigationController->ConnectGeometrySendEvent(this); sliceNavigationController->ConnectGeometrySliceEvent(this); mitk::TimeGeometry::ConstPointer timeGeometry = m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()); mitk::RenderingManager::GetInstance()->InitializeView(m_RenderWindow->GetVtkRenderWindow(), timeGeometry); } void QmitkRenderWindowWidget::InitializeDecorations() { vtkRenderer* vtkRenderer = m_RenderWindow->GetRenderer()->GetVtkRenderer(); if (nullptr == vtkRenderer) { return; } // initialize background color gradients float black[3] = { 0.0f, 0.0f, 0.0f }; SetGradientBackgroundColors(black, black); // initialize annotation text and decoration color setFrameStyle(QFrame::Box | QFrame::Plain); m_CornerAnnotation = vtkSmartPointer::New(); m_CornerAnnotation->SetText(0, "Sagittal"); m_CornerAnnotation->SetMaximumFontSize(12); if (0 == vtkRenderer->HasViewProp(m_CornerAnnotation)) { vtkRenderer->AddViewProp(m_CornerAnnotation); } float white[3] = { 1.0f, 1.0f, 1.0f }; SetDecorationColor(mitk::Color(white)); } void QmitkRenderWindowWidget::SetCrosshairPosition(const mitk::Point3D& newPosition) { m_CrosshairManager->SetCrosshairPosition(newPosition); this->RequestUpdate(); } mitk::Point3D QmitkRenderWindowWidget::GetCrosshairPosition() const { return m_CrosshairManager->GetCrosshairPosition(); } void QmitkRenderWindowWidget::SetGeometry(const itk::EventObject& event) { if (!mitk::SliceNavigationController::GeometrySendEvent(nullptr, 0).CheckEvent(&event)) { return; } const auto* planeGeometry = this->GetSliceNavigationController()->GetCurrentPlaneGeometry(); if (nullptr == planeGeometry) { mitkThrow() << "No valid plane geometry set. Render window is in an invalid state."; } return SetCrosshairPosition(planeGeometry->GetCenter()); } void QmitkRenderWindowWidget::SetGeometrySlice(const itk::EventObject& event) { if (!mitk::SliceNavigationController::GeometrySliceEvent(nullptr, 0).CheckEvent(&event)) { return; } const auto* sliceNavigationController = this->GetSliceNavigationController(); m_CrosshairManager->UpdateCrosshairPosition(sliceNavigationController); } void QmitkRenderWindowWidget::OnResetGeometry() { const auto* baseRenderer = mitk::BaseRenderer::GetInstance(m_RenderWindow->GetVtkRenderWindow()); const auto* interactionReferenceGeometry = baseRenderer->GetInteractionReferenceGeometry(); this->ResetGeometry(interactionReferenceGeometry); m_RenderWindow->ShowOverlayMessage(false); } void QmitkRenderWindowWidget::ResetGeometry(const mitk::TimeGeometry* referenceGeometry) { if (nullptr == referenceGeometry) { return; } mitk::TimeStepType imageTimeStep = 0; // store the current position to set it again later, if the camera should not be reset mitk::Point3D currentPosition = this->GetCrosshairPosition(); // store the current time step to set it again later, if the camera should not be reset auto* renderingManager = mitk::RenderingManager::GetInstance(); const mitk::TimePointType currentTimePoint = renderingManager->GetTimeNavigationController()->GetSelectedTimePoint(); if (referenceGeometry->IsValidTimePoint(currentTimePoint)) { imageTimeStep = referenceGeometry->TimePointToTimeStep(currentTimePoint); } const auto* baseRenderer = mitk::BaseRenderer::GetInstance(m_RenderWindow->renderWindow()); renderingManager->InitializeView(baseRenderer->GetRenderWindow(), referenceGeometry, false); // reset position and time step this->GetSliceNavigationController()->SelectSliceByPoint(currentPosition); renderingManager->GetTimeNavigationController()->GetStepper()->SetPos(imageTimeStep); } diff --git a/Modules/QtWidgetsExt/src/QmitkSliceWidget.cpp b/Modules/QtWidgetsExt/src/QmitkSliceWidget.cpp index 7cfbb790eb..69da61ffbb 100644 --- a/Modules/QtWidgetsExt/src/QmitkSliceWidget.cpp +++ b/Modules/QtWidgetsExt/src/QmitkSliceWidget.cpp @@ -1,266 +1,266 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkSliceWidget.h" #include "QmitkStepperAdapter.h" #include "mitkCameraController.h" #include "mitkImage.h" #include "mitkNodePredicateDataType.h" #include #include #include #include QmitkSliceWidget::QmitkSliceWidget(QWidget *parent, const char *name, Qt::WindowFlags f) : QWidget(parent, f) { this->setupUi(this); if (name != nullptr) this->setObjectName(name); popUp = new QMenu(this); popUp->addAction("Axial"); popUp->addAction("Coronal"); popUp->addAction("Sagittal"); QObject::connect(popUp, SIGNAL(triggered(QAction *)), this, SLOT(ChangeView(QAction *))); setPopUpEnabled(false); m_SlicedGeometry = nullptr; m_View = mitk::AnatomicalPlane::Axial; QHBoxLayout *hlayout = new QHBoxLayout(container); - hlayout->setMargin(0); + hlayout->setContentsMargins({}); // create widget QString composedName("QmitkSliceWidget::"); if (!this->objectName().isEmpty()) composedName += this->objectName(); else composedName += "QmitkGLWidget"; m_RenderWindow = new QmitkRenderWindow(container, composedName); m_Renderer = m_RenderWindow->GetRenderer(); hlayout->addWidget(m_RenderWindow); new QmitkStepperAdapter(sliceNavigationWidget, m_RenderWindow->GetSliceNavigationController()->GetStepper()); SetLevelWindowEnabled(true); } mitk::VtkPropRenderer *QmitkSliceWidget::GetRenderer() { return m_Renderer; } QFrame *QmitkSliceWidget::GetSelectionFrame() { return SelectionFrame; } void QmitkSliceWidget::SetDataStorage(mitk::StandaloneDataStorage::Pointer storage) { m_DataStorage = storage; m_Renderer->SetDataStorage(m_DataStorage); } mitk::StandaloneDataStorage *QmitkSliceWidget::GetDataStorage() { return m_DataStorage; } void QmitkSliceWidget::SetData(mitk::DataStorage::SetOfObjects::ConstIterator it) { SetData(it->Value(), m_View); } void QmitkSliceWidget::SetData(mitk::DataStorage::SetOfObjects::ConstIterator it, mitk::AnatomicalPlane view) { SetData(it->Value(), view); } void QmitkSliceWidget::SetData(mitk::DataNode::Pointer node) { try { if (m_DataStorage.IsNotNull()) { m_DataStorage->Add(node); } } catch (...) { } SetData(node, m_View); } void QmitkSliceWidget::SetData(mitk::DataNode::Pointer node, mitk::AnatomicalPlane view) { mitk::Image::Pointer image = dynamic_cast(node->GetData()); if (image.IsNull()) { MITK_WARN << "QmitkSliceWidget data is not an image!"; return; } m_SlicedGeometry = image->GetSlicedGeometry(); this->InitWidget(view); } void QmitkSliceWidget::InitWidget(mitk::AnatomicalPlane view) { m_View = view; mitk::SliceNavigationController *controller = m_RenderWindow->GetSliceNavigationController(); if (view == mitk::AnatomicalPlane::Axial) { controller->SetViewDirection(mitk::AnatomicalPlane::Axial); } else if (view == mitk::AnatomicalPlane::Coronal) { controller->SetViewDirection(mitk::AnatomicalPlane::Coronal); } // init sagittal view for all other cases ('original' is covered here as well) else { controller->SetViewDirection(mitk::AnatomicalPlane::Sagittal); } if (m_SlicedGeometry.IsNull()) { return; } mitk::BaseGeometry::Pointer geometry = static_cast(m_SlicedGeometry->Clone().GetPointer()); const mitk::BoundingBox::Pointer boundingbox = m_DataStorage->ComputeVisibleBoundingBox(GetRenderer(), nullptr); if (boundingbox->GetPoints()->Size() > 0) { // let's see if we have data with a limited live-span ... mitk::TimeBounds timebounds = m_DataStorage->ComputeTimeBounds(GetRenderer(), nullptr); mitk::ProportionalTimeGeometry::Pointer timeGeometry = mitk::ProportionalTimeGeometry::New(); timeGeometry->Initialize(geometry, 1); { timeGeometry->SetFirstTimePoint(timebounds[0]); timeGeometry->SetStepDuration(1.0); } if (timeGeometry->GetBoundingBoxInWorld()->GetDiagonalLength2() >= mitk::eps) { controller->SetInputWorldTimeGeometry(timeGeometry); controller->Update(); } } GetRenderer()->GetCameraController()->Fit(); mitk::RenderingManager::GetInstance()->RequestUpdate(GetRenderer()->GetRenderWindow()); } void QmitkSliceWidget::UpdateGL() { GetRenderer()->GetCameraController()->Fit(); mitk::RenderingManager::GetInstance()->RequestUpdate(GetRenderer()->GetRenderWindow()); } void QmitkSliceWidget::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::RightButton && popUpEnabled) { popUp->popup(QCursor::pos()); } } void QmitkSliceWidget::wheelEvent(QWheelEvent *e) { int val = sliceNavigationWidget->GetPos(); if (e->orientation() * e->delta() > 0) { sliceNavigationWidget->SetPos(val + 1); } else { if (val > 0) sliceNavigationWidget->SetPos(val - 1); } } void QmitkSliceWidget::ChangeView(QAction *val) { if (val->text() == "Axial") { InitWidget(mitk::AnatomicalPlane::Axial); } else if (val->text() == "Coronal") { InitWidget(mitk::AnatomicalPlane::Coronal); } else if (val->text() == "Sagittal") { InitWidget(mitk::AnatomicalPlane::Sagittal); } } void QmitkSliceWidget::setPopUpEnabled(bool b) { popUpEnabled = b; } QmitkSliceNavigationWidget* QmitkSliceWidget::GetSliceNavigationWidget() { return sliceNavigationWidget; } void QmitkSliceWidget::SetLevelWindowEnabled(bool enable) { levelWindow->setEnabled(enable); if (!enable) { levelWindow->setMinimumWidth(0); levelWindow->setMaximumWidth(0); } else { levelWindow->setMinimumWidth(28); levelWindow->setMaximumWidth(28); } } bool QmitkSliceWidget::IsLevelWindowEnabled() { return levelWindow->isEnabled(); } QmitkRenderWindow *QmitkSliceWidget::GetRenderWindow() { return m_RenderWindow; } mitk::SliceNavigationController *QmitkSliceWidget::GetSliceNavigationController() const { return m_RenderWindow->GetSliceNavigationController(); } mitk::CameraRotationController *QmitkSliceWidget::GetCameraRotationController() const { return m_RenderWindow->GetCameraRotationController(); } mitk::BaseController *QmitkSliceWidget::GetController() const { return m_RenderWindow->GetController(); } diff --git a/Modules/QtWidgetsExt/src/QmitkStringPropertyOnDemandEdit.cpp b/Modules/QtWidgetsExt/src/QmitkStringPropertyOnDemandEdit.cpp index 1a20f6a3e4..01f60032ba 100644 --- a/Modules/QtWidgetsExt/src/QmitkStringPropertyOnDemandEdit.cpp +++ b/Modules/QtWidgetsExt/src/QmitkStringPropertyOnDemandEdit.cpp @@ -1,74 +1,74 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkStringPropertyOnDemandEdit.h" #include QmitkStringPropertyOnDemandEdit::QmitkStringPropertyOnDemandEdit(mitk::StringProperty *property, QWidget *parent) : QFrame(parent), PropertyEditor(property), m_StringProperty(property) { setFrameStyle(QFrame::NoFrame); setLineWidth(0); // create HBoxLayout with two buttons m_layout = new QHBoxLayout(this); - m_layout->setMargin(0); + m_layout->setContentsMargins({}); m_label = new QLabel(this); m_layout->addWidget(m_label); m_toolbutton = new QClickableLabel2(this); m_toolbutton->setText("..."); m_layout->addWidget(m_toolbutton); m_layout->addStretch(10); connect(m_toolbutton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked())); ensurePolished(); adjustSize(); PropertyChanged(); } QmitkStringPropertyOnDemandEdit::~QmitkStringPropertyOnDemandEdit() { } void QmitkStringPropertyOnDemandEdit::PropertyChanged() { if (m_Property) m_label->setText(m_StringProperty->GetValue()); } void QmitkStringPropertyOnDemandEdit::PropertyRemoved() { m_Property = nullptr; m_StringProperty = nullptr; m_label->setText("n/a"); } void QmitkStringPropertyOnDemandEdit::onToolButtonClicked() { bool ok(false); QString newText = QInputDialog::getText( this, "Change text", "You can change the displayed text here", QLineEdit::Normal, m_label->text(), &ok); if (ok) { BeginModifyProperty(); // deregister from events m_StringProperty->SetValue(newText.toStdString()); m_label->setText(newText); EndModifyProperty(); // again register for events } } diff --git a/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp b/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp index 4dfd6870d8..c6400ad1d3 100644 --- a/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp +++ b/Modules/SemanticRelationsUI/src/QmitkControlPointDialog.cpp @@ -1,61 +1,61 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkControlPointDialog.h" #include #include #include #include #include QmitkControlPointDialog::QmitkControlPointDialog(QWidget* parent) : QDialog(parent) { QBoxLayout* verticalLayout = new QVBoxLayout(this); - verticalLayout->setMargin(5); + verticalLayout->setContentsMargins(QMargins(5, 5, 5, 5)); verticalLayout->setSpacing(5); QLabel* dateLabel = new QLabel(tr("Set date"), this); verticalLayout->addWidget(dateLabel); m_DateEdit = new QDateEdit(this); m_DateEdit->setDisplayFormat("yyyy-MM-dd"); m_DateEdit->setFocus(); verticalLayout->addWidget(m_DateEdit); QPushButton* acceptButton = new QPushButton(tr("Ok"), this); QPushButton* cancelButton = new QPushButton(tr("Cancel"), this); acceptButton->setDefault(true); connect(acceptButton, &QPushButton::clicked, this, &QmitkControlPointDialog::accept); connect(cancelButton, &QPushButton::clicked, this, &QmitkControlPointDialog::reject); QBoxLayout* horizontalLayout = new QHBoxLayout(); horizontalLayout->setSpacing(5); horizontalLayout->addStretch(); horizontalLayout->addWidget(acceptButton); horizontalLayout->addWidget(cancelButton); verticalLayout->addLayout(horizontalLayout); setMinimumSize(250, 100); } void QmitkControlPointDialog::SetCurrentDate(mitk::SemanticTypes::ControlPoint currentControlPoint) { m_DateEdit->setDate(QDate(currentControlPoint.date.year(), currentControlPoint.date.month(), currentControlPoint.date.day())); } QDate QmitkControlPointDialog::GetCurrentDate() const { return m_DateEdit->date(); } diff --git a/Modules/SemanticRelationsUI/src/QmitkLesionTextDialog.cpp b/Modules/SemanticRelationsUI/src/QmitkLesionTextDialog.cpp index 0eb9a7aefd..1def6eaf60 100644 --- a/Modules/SemanticRelationsUI/src/QmitkLesionTextDialog.cpp +++ b/Modules/SemanticRelationsUI/src/QmitkLesionTextDialog.cpp @@ -1,63 +1,63 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkLesionTextDialog.h" #include #include #include QmitkLesionTextDialog::QmitkLesionTextDialog(QWidget* parent) : QDialog(parent) { QBoxLayout* verticalLayout = new QVBoxLayout(this); - verticalLayout->setMargin(5); + verticalLayout->setContentsMargins(QMargins(5, 5, 5, 5)); verticalLayout->setSpacing(5); QLabel* dialogLabel = new QLabel(tr("Set lesion information"), this); verticalLayout->addWidget(dialogLabel); m_LineEdit = new QLineEdit(this); m_LineEdit->setFocus(); verticalLayout->addWidget(m_LineEdit); QPushButton* acceptButton = new QPushButton(tr("Ok"), this); QPushButton* cancelButton = new QPushButton(tr("Cancel"), this); acceptButton->setDefault(true); connect(acceptButton, &QPushButton::clicked, this, &QmitkLesionTextDialog::accept); connect(cancelButton, &QPushButton::clicked, this, &QmitkLesionTextDialog::reject); QBoxLayout* horizontalLayout = new QHBoxLayout(); horizontalLayout->setSpacing(5); horizontalLayout->addStretch(); horizontalLayout->addWidget(acceptButton); horizontalLayout->addWidget(cancelButton); verticalLayout->addLayout(horizontalLayout); setMinimumSize(250, 100); } void QmitkLesionTextDialog::SetLineEditText(const std::string& lineEditText) { m_LineEdit->setText(QString::fromStdString(lineEditText)); } QString QmitkLesionTextDialog::GetLineEditText() const { return m_LineEdit->text(); } QLineEdit* QmitkLesionTextDialog::GetLineEdit() const { return m_LineEdit; } diff --git a/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpEditorFindWidget.cpp b/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpEditorFindWidget.cpp index dea8dcea63..a5a282d4e3 100644 --- a/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpEditorFindWidget.cpp +++ b/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpEditorFindWidget.cpp @@ -1,164 +1,164 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryHelpEditorFindWidget.h" #include #include #include #include #include #include #include #include namespace berry { HelpEditorFindWidget::HelpEditorFindWidget(QWidget *parent) : QWidget(parent) , appPalette(qApp->palette()) { installEventFilter(this); auto hboxLayout = new QHBoxLayout(this); QString resourcePath = QLatin1String(":/org.blueberry.ui.qt.help"); #ifndef Q_OS_MAC - hboxLayout->setMargin(0); + hboxLayout->setContentsMargins({}); hboxLayout->setSpacing(6); #endif toolClose = setupToolButton(QLatin1String(""), resourcePath + QLatin1String("/close.png")); hboxLayout->addWidget(toolClose); connect(toolClose, SIGNAL(clicked()), SLOT(hide())); editFind = new QLineEdit(this); hboxLayout->addWidget(editFind); editFind->setMinimumSize(QSize(150, 0)); connect(editFind, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString))); connect(editFind, SIGNAL(returnPressed()), this, SIGNAL(findNext())); connect(editFind, SIGNAL(textChanged(QString)), this, SLOT(updateButtons())); toolPrevious = setupToolButton(tr("Previous"), resourcePath + QLatin1String("/go-previous.png")); connect(toolPrevious, SIGNAL(clicked()), this, SIGNAL(findPrevious())); hboxLayout->addWidget(toolPrevious); toolNext = setupToolButton(tr("Next"), resourcePath + QLatin1String("/go-next.png")); hboxLayout->addWidget(toolNext); connect(toolNext, SIGNAL(clicked()), this, SIGNAL(findNext())); checkCase = new QCheckBox(tr("Case Sensitive"), this); hboxLayout->addWidget(checkCase); setMinimumWidth(minimumSizeHint().width()); updateButtons(); } HelpEditorFindWidget::~HelpEditorFindWidget() { } void HelpEditorFindWidget::show() { QWidget::show(); editFind->selectAll(); editFind->setFocus(Qt::ShortcutFocusReason); } void HelpEditorFindWidget::showAndClear() { show(); editFind->clear(); } QString HelpEditorFindWidget::text() const { return editFind->text(); } bool HelpEditorFindWidget::caseSensitive() const { return checkCase->isChecked(); } void HelpEditorFindWidget::setPalette(bool found) { QPalette palette = editFind->palette(); palette.setColor(QPalette::Active, QPalette::Base, found ? Qt::white : QColor(255, 102, 102)); editFind->setPalette(palette); } void HelpEditorFindWidget::hideEvent(QHideEvent* event) { // TODO: remove this once webkit supports setting the palette if (!event->spontaneous()) qApp->setPalette(appPalette); } void HelpEditorFindWidget::showEvent(QShowEvent* event) { // TODO: remove this once webkit supports setting the palette if (!event->spontaneous()) { QPalette p = appPalette; p.setColor(QPalette::Inactive, QPalette::Highlight, p.color(QPalette::Active, QPalette::Highlight)); p.setColor(QPalette::Inactive, QPalette::HighlightedText, p.color(QPalette::Active, QPalette::HighlightedText)); qApp->setPalette(p); } } void HelpEditorFindWidget::updateButtons() { const bool enable = !editFind->text().isEmpty(); toolNext->setEnabled(enable); toolPrevious->setEnabled(enable); } void HelpEditorFindWidget::textChanged(const QString &text) { emit find(text, true); } bool HelpEditorFindWidget::eventFilter(QObject *object, QEvent *e) { if (e->type() == QEvent::KeyPress) { if ((static_cast(e))->key() == Qt::Key_Escape) { hide(); emit escapePressed(); } } return QWidget::eventFilter(object, e); } QToolButton* HelpEditorFindWidget::setupToolButton(const QString &text, const QString &icon) { auto toolButton = new QToolButton(this); toolButton->setText(text); toolButton->setAutoRaise(true); toolButton->setIcon(QIcon(icon)); toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); return toolButton; } } diff --git a/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpIndexView.cpp b/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpIndexView.cpp index d4efe34f72..d027955804 100644 --- a/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpIndexView.cpp +++ b/Plugins/org.blueberry.ui.qt.help/src/internal/berryHelpIndexView.cpp @@ -1,310 +1,310 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryHelpIndexView.h" #include "berryHelpPluginActivator.h" #include "berryHelpEditor.h" #include "berryHelpEditorInput.h" #include "berryQHelpEngineWrapper.h" #include "berryHelpTopicChooser.h" #include #include #include #include #include #include #include namespace berry { HelpIndexWidget::HelpIndexWidget() : QListView(nullptr) { setEditTriggers(QAbstractItemView::NoEditTriggers); setUniformItemSizes(true); connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(showLink(QModelIndex))); } void HelpIndexWidget::showLink(const QModelIndex &index) { if (!index.isValid()) return; QHelpIndexModel *indexModel = qobject_cast(model()); if (!indexModel) return; QVariant v = indexModel->data(index, Qt::DisplayRole); QString name; if (v.isValid()) name = v.toString(); QMap links = indexModel->linksForKeyword(name); if (links.count() == 1) { emit linkActivated(links.constBegin().value(), name); } else if (links.count() > 1) { emit linksActivated(links, name); } } void HelpIndexWidget::activateCurrentItem() { showLink(currentIndex()); } void HelpIndexWidget::filterIndices(const QString &filter, const QString &wildcard) { QHelpIndexModel *indexModel = qobject_cast(model()); if (!indexModel) return; QModelIndex idx = indexModel->filter(filter, wildcard); if (idx.isValid()) setCurrentIndex(idx); } HelpIndexView::HelpIndexView() : m_IndexWidget(nullptr) { } HelpIndexView::~HelpIndexView() { } void HelpIndexView::CreateQtPartControl(QWidget* parent) { if (m_IndexWidget == nullptr) { auto layout = new QVBoxLayout(parent); //QLabel *l = new QLabel(tr("&Look for:")); //layout->addWidget(l); m_SearchLineEdit = new ctkSearchBox(parent); m_SearchLineEdit->setClearIcon(QIcon(":/org.blueberry.ui.qt.help/clear.png")); m_SearchLineEdit->setPlaceholderText("Filter..."); m_SearchLineEdit->setContentsMargins(2,2,2,0); //l->setBuddy(m_SearchLineEdit); connect(m_SearchLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterIndices(QString))); m_SearchLineEdit->installEventFilter(this); - layout->setMargin(0); + layout->setContentsMargins({}); layout->setSpacing(2); layout->addWidget(m_SearchLineEdit); QHelpEngineWrapper& helpEngine = HelpPluginActivator::getInstance()->getQHelpEngine(); m_IndexWidget = new HelpIndexWidget(); m_IndexWidget->setModel(helpEngine.indexModel()); connect(helpEngine.indexModel(), SIGNAL(indexCreationStarted()), this, SLOT(setIndexWidgetBusy())); connect(helpEngine.indexModel(), SIGNAL(indexCreated()), this, SLOT(unsetIndexWidgetBusy())); m_IndexWidget->installEventFilter(this); connect(helpEngine.indexModel(), SIGNAL(indexCreationStarted()), this, SLOT(disableSearchLineEdit())); connect(helpEngine.indexModel(), SIGNAL(indexCreated()), this, SLOT(enableSearchLineEdit())); connect(m_IndexWidget, SIGNAL(linkActivated(QUrl,QString)), this, SLOT(linkActivated(QUrl))); connect(m_IndexWidget, SIGNAL(linksActivated(QMap,QString)), this, SLOT(linksActivated(QMap,QString))); connect(m_SearchLineEdit, SIGNAL(returnPressed()), m_IndexWidget, SLOT(activateCurrentItem())); layout->addWidget(m_IndexWidget); m_IndexWidget->viewport()->installEventFilter(this); } } void HelpIndexView::SetFocus() { if (!(m_IndexWidget->hasFocus() || m_SearchLineEdit->hasFocus())) { m_SearchLineEdit->setFocus(); } } void HelpIndexView::filterIndices(const QString &filter) { if (filter.contains(QLatin1Char('*'))) m_IndexWidget->filterIndices(filter, filter); else m_IndexWidget->filterIndices(filter, QString()); } bool HelpIndexView::eventFilter(QObject *obj, QEvent *e) { if (obj == m_SearchLineEdit && e->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast(e); QModelIndex idx = m_IndexWidget->currentIndex(); switch (ke->key()) { case Qt::Key_Up: idx = m_IndexWidget->model()->index(idx.row()-1, idx.column(), idx.parent()); if (idx.isValid()) { m_IndexWidget->setCurrentIndex(idx); return true; } break; case Qt::Key_Down: idx = m_IndexWidget->model()->index(idx.row()+1, idx.column(), idx.parent()); if (idx.isValid()) { m_IndexWidget->setCurrentIndex(idx); return true; } break; default: ; // stop complaining } } else if (obj == m_IndexWidget && e->type() == QEvent::ContextMenu) { QContextMenuEvent *ctxtEvent = static_cast(e); QModelIndex idx = m_IndexWidget->indexAt(ctxtEvent->pos()); if (idx.isValid()) { QMenu menu; QAction *curTab = menu.addAction(tr("Open Link")); QAction *newTab = menu.addAction(tr("Open Link in New Tab")); menu.move(m_IndexWidget->mapToGlobal(ctxtEvent->pos())); QAction *action = menu.exec(); if (curTab == action) m_IndexWidget->activateCurrentItem(); else if (newTab == action) { open(m_IndexWidget, idx); } } } else if (m_IndexWidget && obj == m_IndexWidget->viewport() && e->type() == QEvent::MouseButtonRelease) { QMouseEvent *mouseEvent = static_cast(e); QModelIndex idx = m_IndexWidget->indexAt(mouseEvent->pos()); if (idx.isValid()) { Qt::MouseButtons button = mouseEvent->button(); if (((button == Qt::LeftButton) && (mouseEvent->modifiers() & Qt::ControlModifier)) || (button == Qt::MidButton)) { open(m_IndexWidget, idx); } } } #ifdef Q_OS_MAC else if (obj == m_IndexWidget && e->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast(e); if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) m_IndexWidget->activateCurrentItem(); } #endif return QObject::eventFilter(obj, e); } void HelpIndexView::enableSearchLineEdit() { m_SearchLineEdit->setDisabled(false); filterIndices(m_SearchLineEdit->text()); } void HelpIndexView::disableSearchLineEdit() { m_SearchLineEdit->setDisabled(true); } void HelpIndexView::setIndexWidgetBusy() { m_IndexWidget->setCursor(Qt::WaitCursor); } void HelpIndexView::unsetIndexWidgetBusy() { m_IndexWidget->unsetCursor(); } void HelpIndexView::setSearchLineEditText(const QString &text) { m_SearchLineEdit->setText(text); } QString HelpIndexView::searchLineEditText() const { return m_SearchLineEdit->text(); } void HelpIndexView::focusInEvent(QFocusEvent *e) { if (e->reason() != Qt::MouseFocusReason) { m_SearchLineEdit->selectAll(); m_SearchLineEdit->setFocus(); } } void HelpIndexView::open(HelpIndexWidget* indexWidget, const QModelIndex &index) { QHelpIndexModel *model = qobject_cast(indexWidget->model()); if (model) { QString keyword = model->data(index, Qt::DisplayRole).toString(); QMap links = model->linksForKeyword(keyword); QUrl url; if (links.count() > 1) { HelpTopicChooser tc(m_IndexWidget, keyword, links); if (tc.exec() == QDialog::Accepted) url = tc.link(); } else if (links.count() == 1) { url = links.constBegin().value(); } else { return; } IEditorInput::Pointer input(new HelpEditorInput(url)); this->GetSite()->GetPage()->OpenEditor(input, HelpEditor::EDITOR_ID); } } void HelpIndexView::linkActivated(const QUrl& link) { IWorkbenchPage::Pointer page = this->GetSite()->GetPage(); HelpPluginActivator::linkActivated(page, link); } void HelpIndexView::linksActivated(const QMap& links, const QString& keyword) { HelpTopicChooser tc(m_IndexWidget, keyword, links); if (tc.exec() == QDialog::Accepted) { IWorkbenchPage::Pointer page = this->GetSite()->GetPage(); HelpPluginActivator::linkActivated(page, tc.link()); } } } diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkAbstractView.cpp b/Plugins/org.mitk.gui.qt.common/src/QmitkAbstractView.cpp index 95103106a7..4f74a40026 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkAbstractView.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkAbstractView.cpp @@ -1,522 +1,522 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkAbstractView.h" #include "QmitkDataNodeSelectionProvider.h" #include "internal/QmitkCommonActivator.h" #include "internal/QmitkDataNodeItemModel.h" // mitk Includes #include #include #include #include #include #include #include #include #include // berry Includes #include #include #include #include // CTK Includes #include // Qt Includes #include #include #include #include #include class QmitkAbstractViewPrivate { public: QmitkAbstractViewPrivate(QmitkAbstractView* qq) : q(qq) , m_DataStorageServiceTracker(QmitkCommonActivator::GetContext()) , m_Parent(nullptr) , m_DataNodeItemModel(new QmitkDataNodeItemModel) , m_DataNodeSelectionModel(new QItemSelectionModel(m_DataNodeItemModel)) , m_InDataStorageChanged(false) { m_DataStorageServiceTracker.open(); } ~QmitkAbstractViewPrivate() { delete m_DataNodeSelectionModel; delete m_DataNodeItemModel; m_DataStorageServiceTracker.close(); } /** * Called when a DataStorage Add Event was thrown. Sets * m_InDataStorageChanged to true and calls NodeAdded afterwards. * \see m_InDataStorageChanged */ void NodeAddedProxy(const mitk::DataNode* node) { // garantuee no recursions when a new node event is thrown in NodeAdded() if(!m_InDataStorageChanged) { m_InDataStorageChanged = true; q->NodeAdded(node); q->DataStorageModified(); m_InDataStorageChanged = false; } } /** * Called when a DataStorage remove event was thrown. Sets * m_InDataStorageChanged to true and calls NodeRemoved afterwards. * \see m_InDataStorageChanged */ void NodeRemovedProxy(const mitk::DataNode* node) { // garantuee no recursions when a new node event is thrown in NodeAdded() if(!m_InDataStorageChanged) { m_InDataStorageChanged = true; q->NodeRemoved(node); q->DataStorageModified(); m_InDataStorageChanged = false; } } /** * Called when a DataStorage changed event was thrown. Sets * m_InDataStorageChanged to true and calls NodeChanged afterwards. * \see m_InDataStorageChanged */ void NodeChangedProxy(const mitk::DataNode* node) { // garantuee no recursions when a new node event is thrown in NodeAdded() if(!m_InDataStorageChanged) { m_InDataStorageChanged = true; q->NodeChanged(node); q->DataStorageModified(); m_InDataStorageChanged = false; } } /** * reactions to selection events from views */ void BlueBerrySelectionChanged(const berry::IWorkbenchPart::Pointer& sourcepart, const berry::ISelection::ConstPointer& selection) { if(sourcepart.IsNull() || sourcepart.GetPointer() == static_cast(q)) return; if(selection.IsNull()) { q->OnNullSelection(sourcepart); return; } mitk::DataNodeSelection::ConstPointer _DataNodeSelection = selection.Cast(); q->OnSelectionChanged(sourcepart, this->DataNodeSelectionToQList(_DataNodeSelection)); } /** * Converts a mitk::DataNodeSelection to a QList (possibly empty) */ QList DataNodeSelectionToQList(mitk::DataNodeSelection::ConstPointer currentSelection) const; QmitkAbstractView* const q; ctkServiceTracker m_DataStorageServiceTracker; /** * Saves the parent of this view (this is the scrollarea created in CreatePartControl(QWidget*) * \see CreatePartControl(QWidget*) */ QWidget* m_Parent; /** * Holds the current selection (selection made by this View !!!) */ QmitkDataNodeSelectionProvider::Pointer m_SelectionProvider; /** * Holds a helper model for firing selection events. */ QmitkDataNodeItemModel* m_DataNodeItemModel; /** * The selection model for the QmitkDataNodeItemModel; */ QItemSelectionModel* m_DataNodeSelectionModel; /** * object to observe BlueBerry selections */ QScopedPointer m_BlueBerrySelectionListener; /** * Saves if this class is currently working on DataStorage changes. * This is a protector variable to avoid recursive calls on event listener functions. */ bool m_InDataStorageChanged; }; QmitkAbstractView::QmitkAbstractView() : d(new QmitkAbstractViewPrivate(this)) { } void QmitkAbstractView::CreatePartControl(QWidget* parent) { // scrollArea auto scrollArea = new QScrollArea; //QVBoxLayout* scrollAreaLayout = new QVBoxLayout(scrollArea); scrollArea->setFrameShadow(QFrame::Plain); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // m_Parent d->m_Parent = new QWidget; //m_Parent->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); this->CreateQtPartControl(d->m_Parent); //scrollAreaLayout->addWidget(m_Parent); //scrollArea->setLayout(scrollAreaLayout); // set the widget now scrollArea->setWidgetResizable(true); scrollArea->setWidget(d->m_Parent); // add the scroll area to the real parent (the view tabbar) QWidget* parentQWidget = static_cast(parent); auto parentLayout = new QVBoxLayout(parentQWidget); - parentLayout->setMargin(0); + parentLayout->setContentsMargins({}); parentLayout->setSpacing(0); parentLayout->addWidget(scrollArea); // finally set the layout containing the scroll area to the parent widget (= show it) parentQWidget->setLayout(parentLayout); this->AfterCreateQtPartControl(); } void QmitkAbstractView::AfterCreateQtPartControl() { this->SetSelectionProvider(); // REGISTER DATASTORAGE LISTENER this->GetDataStorage()->AddNodeEvent.AddListener( mitk::MessageDelegate1 ( d.data(), &QmitkAbstractViewPrivate::NodeAddedProxy ) ); this->GetDataStorage()->ChangedNodeEvent.AddListener( mitk::MessageDelegate1 ( d.data(), &QmitkAbstractViewPrivate::NodeChangedProxy ) ); this->GetDataStorage()->RemoveNodeEvent.AddListener( mitk::MessageDelegate1 ( d.data(), &QmitkAbstractViewPrivate::NodeRemovedProxy ) ); // REGISTER PREFERENCES LISTENER auto* prefs = this->GetPreferences(); if (prefs != nullptr) prefs->OnChanged.AddListener(mitk::MessageDelegate1(this, &QmitkAbstractView::OnPreferencesChanged)); // REGISTER FOR WORKBENCH SELECTION EVENTS d->m_BlueBerrySelectionListener.reset(new berry::NullSelectionChangedAdapter( d.data(), &QmitkAbstractViewPrivate::BlueBerrySelectionChanged)); this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(d->m_BlueBerrySelectionListener.data()); // EMULATE INITIAL SELECTION EVENTS // send the current selection berry::IWorkbenchPart::Pointer activePart = this->GetSite()->GetPage()->GetActivePart(); if (activePart.IsNotNull()) { this->OnSelectionChanged(activePart, this->GetCurrentSelection()); } // send preferences changed event this->OnPreferencesChanged(this->GetPreferences()); } QmitkAbstractView::~QmitkAbstractView() { this->Register(); this->GetDataStorage()->AddNodeEvent.RemoveListener( mitk::MessageDelegate1 ( d.data(), &QmitkAbstractViewPrivate::NodeAddedProxy ) ); this->GetDataStorage()->RemoveNodeEvent.RemoveListener( mitk::MessageDelegate1 ( d.data(), &QmitkAbstractViewPrivate::NodeRemovedProxy) ); this->GetDataStorage()->ChangedNodeEvent.RemoveListener( mitk::MessageDelegate1 ( d.data(), &QmitkAbstractViewPrivate::NodeChangedProxy ) ); auto* prefs = this->GetPreferences(); if(prefs != nullptr) prefs->OnChanged.RemoveListener(mitk::MessageDelegate1(this, &QmitkAbstractView::OnPreferencesChanged)); // REMOVE SELECTION PROVIDER this->GetSite()->SetSelectionProvider(berry::ISelectionProvider::Pointer(nullptr)); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) { s->RemovePostSelectionListener(d->m_BlueBerrySelectionListener.data()); } this->UnRegister(false); } void QmitkAbstractView::SetSelectionProvider() { // REGISTER A SELECTION PROVIDER d->m_SelectionProvider = QmitkDataNodeSelectionProvider::Pointer(new QmitkDataNodeSelectionProvider); d->m_SelectionProvider->SetItemSelectionModel(GetDataNodeSelectionModel()); this->GetSite()->SetSelectionProvider(berry::ISelectionProvider::Pointer(d->m_SelectionProvider)); } QItemSelectionModel *QmitkAbstractView::GetDataNodeSelectionModel() const { return nullptr; } void QmitkAbstractView::OnPreferencesChanged( const mitk::IPreferences* ) { } void QmitkAbstractView::DataStorageModified() { } void QmitkAbstractView::DataStorageChanged(mitk::IDataStorageReference::Pointer /*dsRef*/) { } mitk::IRenderWindowPart* QmitkAbstractView::GetRenderWindowPart(mitk::WorkbenchUtil::IRenderWindowPartStrategies strategies) const { berry::IWorkbenchPage::Pointer page = GetSite()->GetPage(); return mitk::WorkbenchUtil::GetRenderWindowPart(page, strategies); } void QmitkAbstractView::RequestRenderWindowUpdate(mitk::RenderingManager::RequestType requestType) { mitk::IRenderWindowPart* renderPart = this->GetRenderWindowPart(); if (renderPart == nullptr) return; if (mitk::IRenderingManager* renderingManager = renderPart->GetRenderingManager()) { renderingManager->RequestUpdateAll(requestType); } else { renderPart->RequestUpdate(requestType); } } void QmitkAbstractView::HandleException( const char* str, QWidget* parent, bool showDialog ) const { //itkGenericOutputMacro( << "Exception caught: " << str ); MITK_ERROR << str; if ( showDialog ) { QMessageBox::critical ( parent, "Exception caught!", str ); } } void QmitkAbstractView::HandleException( std::exception& e, QWidget* parent, bool showDialog ) const { HandleException( e.what(), parent, showDialog ); } void QmitkAbstractView::WaitCursorOn() { QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); } void QmitkAbstractView::BusyCursorOn() { QApplication::setOverrideCursor( QCursor(Qt::BusyCursor) ); } void QmitkAbstractView::WaitCursorOff() { this->RestoreOverrideCursor(); } void QmitkAbstractView::BusyCursorOff() { this->RestoreOverrideCursor(); } void QmitkAbstractView::RestoreOverrideCursor() { QApplication::restoreOverrideCursor(); } mitk::IPreferences* QmitkAbstractView::GetPreferences() const { mitk::CoreServicePointer prefsService(mitk::CoreServices::GetPreferencesService()); auto* prefs = prefsService->GetSystemPreferences(); if (prefs != nullptr) { auto viewSite = const_cast(this)->GetViewSite(); if (viewSite.IsNotNull()) return prefs->Node("/" + viewSite->GetId().toStdString()); } return nullptr; } mitk::DataStorage::Pointer QmitkAbstractView::GetDataStorage() const { mitk::IDataStorageService* dsService = d->m_DataStorageServiceTracker.getService(); if (dsService != nullptr) { return dsService->GetDataStorage()->GetDataStorage(); } return nullptr; } mitk::IDataStorageReference::Pointer QmitkAbstractView::GetDataStorageReference() const { mitk::IDataStorageService* dsService = d->m_DataStorageServiceTracker.getService(); if (dsService != nullptr) { return dsService->GetDataStorage(); } return mitk::IDataStorageReference::Pointer(nullptr); } QList QmitkAbstractView::GetCurrentSelection() const { berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection()); mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); return d->DataNodeSelectionToQList(currentSelection); } bool QmitkAbstractView::IsCurrentSelectionValid() const { return this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection(); } QList QmitkAbstractView::GetDataManagerSelection() const { berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); return d->DataNodeSelectionToQList(currentSelection); } bool QmitkAbstractView::IsDataManagerSelectionValid() const { return this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager"); } void QmitkAbstractView::SetDataManagerSelection(const berry::ISelection::ConstPointer &selection, QItemSelectionModel::SelectionFlags flags) const { berry::IViewPart::Pointer datamanagerView = this->GetSite()->GetWorkbenchWindow()->GetActivePage()->FindView("org.mitk.views.datamanager"); if (datamanagerView.IsNull()) return; datamanagerView->GetSite()->GetSelectionProvider().Cast()->SetSelection(selection, flags); } void QmitkAbstractView::SynchronizeDataManagerSelection() const { berry::ISelection::ConstPointer currentSelection = this->GetSite()->GetSelectionProvider()->GetSelection(); if (currentSelection.IsNull()) return; SetDataManagerSelection(currentSelection); } void QmitkAbstractView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*part*/, const QList& /*nodes*/) { } void QmitkAbstractView::OnNullSelection(berry::IWorkbenchPart::Pointer /*part*/) { } QList QmitkAbstractViewPrivate::DataNodeSelectionToQList(mitk::DataNodeSelection::ConstPointer currentSelection) const { if (currentSelection.IsNull()) return QList(); return QList::fromStdList(currentSelection->GetSelectedDataNodes()); } void QmitkAbstractView::NodeAdded( const mitk::DataNode* /*node*/ ) { } void QmitkAbstractView::NodeRemoved( const mitk::DataNode* /*node*/ ) { } void QmitkAbstractView::NodeChanged( const mitk::DataNode* /*node*/ ) { } void QmitkAbstractView::FireNodeSelected( mitk::DataNode::Pointer node ) { QList nodes; nodes << node; this->FireNodesSelected(nodes); } void QmitkAbstractView::FireNodesSelected( const QList& nodes ) { // if this is the first call to FireNodesSelected and the selection provider has no QItemSelectiomMode // yet, set our helper model if (d->m_SelectionProvider->GetItemSelectionModel() == nullptr) { d->m_SelectionProvider->SetItemSelectionModel(d->m_DataNodeSelectionModel); } else if (d->m_SelectionProvider->GetItemSelectionModel() != d->m_DataNodeSelectionModel) { MITK_WARN << "A custom data node selection model has been set. Ignoring call to FireNodesSelected()."; return; } if (nodes.empty()) { d->m_DataNodeSelectionModel->clearSelection(); d->m_DataNodeItemModel->clear(); } else { // The helper data node model is just used for sending selection events. // We add the to be selected nodes and set the selection range to everything. d->m_DataNodeItemModel->clear(); foreach(mitk::DataNode::Pointer node, nodes) { d->m_DataNodeItemModel->AddDataNode(node); } d->m_DataNodeSelectionModel->select(QItemSelection(d->m_DataNodeItemModel->index(0,0), d->m_DataNodeItemModel->index(nodes.size()-1, 0)), QItemSelectionModel::ClearAndSelect); } } diff --git a/Plugins/org.mitk.gui.qt.ext/src/internal/QmitkModuleView.cpp b/Plugins/org.mitk.gui.qt.ext/src/internal/QmitkModuleView.cpp index 29f1622c41..e157933464 100644 --- a/Plugins/org.mitk.gui.qt.ext/src/internal/QmitkModuleView.cpp +++ b/Plugins/org.mitk.gui.qt.ext/src/internal/QmitkModuleView.cpp @@ -1,94 +1,94 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkModuleView.h" #include #include #include #include #include #include QmitkModuleView::QmitkModuleView() : tableView(nullptr) { } void QmitkModuleView::SetFocus() { //tableView->setFocus(); } void QmitkModuleView::CreateQtPartControl(QWidget *parent) { auto layout = new QHBoxLayout(); - layout->setMargin(0); + layout->setContentsMargins({}); parent->setLayout(layout); tableView = new QTableView(parent); auto tableModel = new QmitkModuleTableModel(tableView); auto sortProxyModel = new QSortFilterProxyModel(tableView); sortProxyModel->setSourceModel(tableModel); sortProxyModel->setDynamicSortFilter(true); tableView->setModel(sortProxyModel); tableView->verticalHeader()->hide(); tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); tableView->setSelectionBehavior(QAbstractItemView::SelectRows); tableView->setSelectionMode(QAbstractItemView::ExtendedSelection); tableView->setTextElideMode(Qt::ElideMiddle); tableView->setSortingEnabled(true); tableView->sortByColumn(0, Qt::AscendingOrder); tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); tableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents); tableView->horizontalHeader()->setStretchLastSection(true); tableView->horizontalHeader()->setCascadingSectionResizes(true); layout->addWidget(tableView); if (viewState) { berry::IMemento::Pointer tableHeaderState = viewState->GetChild("tableHeader"); if (tableHeaderState) { QString key; tableHeaderState->GetString("qsettings-key", key); if (!key.isEmpty()) { QSettings settings; QByteArray ba = settings.value(key).toByteArray(); tableView->horizontalHeader()->restoreState(ba); } } } } void QmitkModuleView::Init(berry::IViewSite::Pointer site, berry::IMemento::Pointer memento) { berry::QtViewPart::Init(site, memento); viewState = memento; } void QmitkModuleView::SaveState(berry::IMemento::Pointer memento) { QString key = "QmitkModuleView_tableHeader"; QByteArray ba = tableView->horizontalHeader()->saveState(); QSettings settings; settings.setValue(key, ba); berry::IMemento::Pointer tableHeaderState = memento->CreateChild("tableHeader"); tableHeaderState->PutString("qsettings-key", key); } diff --git a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp index 9e3665c522..5f3dfc2b33 100644 --- a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp +++ b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp @@ -1,89 +1,89 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkTubeGraphDeleteLabelGroupDialog.h" #include #include #include #include #include QmitkTubeGraphDeleteLabelGroupDialog::QmitkTubeGraphDeleteLabelGroupDialog(QWidget* parent) :QDialog(parent) { QDialog::setFixedSize(400, 400); auto layout = new QVBoxLayout(this); - layout->setMargin(5); + layout->setContentsMargins(QMargins(5, 5, 5, 5)); layout->setSpacing(5); descriptionLabel = new QLabel("Which Label Group should be removed?", this); layout->addWidget(descriptionLabel); labelGroupListWidget = new QListWidget(this); labelGroupListWidget->setSelectionMode(QAbstractItemView::MultiSelection); layout->addWidget(labelGroupListWidget); auto buttonLayout = new QHBoxLayout(); deleteButton = new QPushButton("Delete", this); buttonLayout->addWidget(deleteButton); connect( deleteButton, SIGNAL(clicked()), this, SLOT(OnDeleteLabelGroupClicked()) ); cancleButton = new QPushButton("Cancel", this); buttonLayout->addWidget(cancleButton); connect( cancleButton, SIGNAL(clicked()), this, SLOT(reject()) ); layout->addLayout(buttonLayout); deleteButton->setFocus(); } QmitkTubeGraphDeleteLabelGroupDialog::~QmitkTubeGraphDeleteLabelGroupDialog() { delete descriptionLabel; delete labelGroupListWidget; delete deleteButton; delete cancleButton; } void QmitkTubeGraphDeleteLabelGroupDialog::OnDeleteLabelGroupClicked() { //get selected items and save it in vector m_LabelGroupList.clear(); for (int i =0; i < labelGroupListWidget->count(); i++) { QListWidgetItem* newItem= labelGroupListWidget->item(i); if(newItem->isSelected()) //For all checked items { m_LabelGroupList.push_back(newItem->text()); } } this->accept(); } QStringList QmitkTubeGraphDeleteLabelGroupDialog::GetSelectedLabelGroups() { return m_LabelGroupList; } void QmitkTubeGraphDeleteLabelGroupDialog::SetLabelGroups(const QStringList &labelGroups) { for (const auto &labelGroup : labelGroups) labelGroupListWidget->addItem(labelGroup); } diff --git a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewAnnotationDialog.cpp b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewAnnotationDialog.cpp index 42242f42f1..07f4761203 100644 --- a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewAnnotationDialog.cpp +++ b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewAnnotationDialog.cpp @@ -1,95 +1,95 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkTubeGraphNewAnnotationDialog.h" #include #include #include #include #include QmitkTubeGraphNewAnnotationDialog::QmitkTubeGraphNewAnnotationDialog(QWidget* parent) :QDialog(parent) { QDialog::setFixedSize(200, 200); layout = new QVBoxLayout(this); - layout->setMargin(5); + layout->setContentsMargins(QMargins(5, 5, 5, 5)); layout->setSpacing(5); annotationNameLabel = new QLabel("Enter the name of the annotation!", this); layout->addWidget(annotationNameLabel); annotationNameLineEdit = new QLineEdit(this); layout->addWidget(annotationNameLineEdit); annotationDescriptionLabel = new QLabel("Enter a description!", this); layout->addWidget(annotationDescriptionLabel); annotationDescriptionLineEdit = new QLineEdit(this); layout->addWidget(annotationDescriptionLineEdit); buttonLayout = new QHBoxLayout(); okButton = new QPushButton("Ok", this); buttonLayout->addWidget(okButton, 0, Qt::AlignRight); connect( okButton, SIGNAL(clicked()), this, SLOT(OnAddingAnnotation()) ); cancleButton = new QPushButton("Cancel", this); buttonLayout->addWidget(cancleButton, 0, Qt::AlignRight); connect( cancleButton, SIGNAL(clicked()), this, SLOT(reject()) ); layout->addLayout(buttonLayout); annotationNameLineEdit->setFocus(); } void QmitkTubeGraphNewAnnotationDialog::OnAddingAnnotation() { if (annotationNameLineEdit->text().isEmpty()) { annotationNameLineEdit->setStyleSheet("border: 1px solid red"); return; } m_NewAnnotationName = annotationNameLineEdit->text(); m_NewAnnotationDescription = annotationDescriptionLineEdit->text(); this->accept(); } QmitkTubeGraphNewAnnotationDialog::~QmitkTubeGraphNewAnnotationDialog() { delete layout; delete okButton; delete cancleButton; // delete buttonLayout; delete annotationNameLabel; delete annotationNameLineEdit; delete annotationDescriptionLabel; delete annotationDescriptionLineEdit; } QString QmitkTubeGraphNewAnnotationDialog::GetAnnotationName() { return m_NewAnnotationName; } QString QmitkTubeGraphNewAnnotationDialog::GetAnnotationDescription() { return m_NewAnnotationDescription; } diff --git a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewLabelGroupDialog.cpp b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewLabelGroupDialog.cpp index d3559fc168..4b785f1bf8 100644 --- a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewLabelGroupDialog.cpp +++ b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphNewLabelGroupDialog.cpp @@ -1,270 +1,270 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkTubeGraphNewLabelGroupDialog.h" #include #include #include #include #include #include #include #include "mitkTubeGraphDefaultLabelGroups.h" QmitkTubeGraphNewLabelGroupDialog::QmitkTubeGraphNewLabelGroupDialog(QWidget* parent) :QDialog(parent) ,m_NewLabelGroup() { QDialog::setFixedSize(200, 200); layout = new QVBoxLayout(this); - layout->setMargin(5); + layout->setContentsMargins(QMargins(5, 5, 5, 5)); layout->setSpacing(5); newLabelGroupButton = new QPushButton("Create new label group", this); layout->addWidget(newLabelGroupButton, 0, Qt::AlignHCenter); connect( newLabelGroupButton, SIGNAL(clicked()), this, SLOT(OnCreateNewLabelGroup()) ); standardLabelGroupButton = new QPushButton("Add standard label group", this); layout->addWidget(standardLabelGroupButton, 0, Qt::AlignHCenter); connect( standardLabelGroupButton, SIGNAL(clicked()), this, SLOT(OnAddStandardLabelGroup()) ); spacer = new QSpacerItem( 20, 40, QSizePolicy::Minimum, QSizePolicy::Minimum ); layout->addSpacerItem(spacer); buttonLayout = new QHBoxLayout(); okButton = new QPushButton("Ok", this); buttonLayout->addWidget(okButton, 0, Qt::AlignRight); okButton->setVisible(false); cancleButton = new QPushButton("Cancel", this); buttonLayout->addWidget(cancleButton, 0, Qt::AlignRight); connect( cancleButton, SIGNAL(clicked()), this, SLOT(reject()) ); layout->addLayout(buttonLayout); newLabelGroupButton->setFocus(); } QmitkTubeGraphNewLabelGroupDialog::~QmitkTubeGraphNewLabelGroupDialog() { //delete layout; ////delete buttonLayout; //delete spacer; //delete okButton; //delete cancleButton; //delete labelGroupDescriptionLabel; /* delete labelGroupLineEdit; delete labelDescriptionLabel; delete labelLineEdit; delete addLabelButton; delete labelListWidget; */ //delete labelGroupTreeWidget; } void QmitkTubeGraphNewLabelGroupDialog::OnCreateNewLabelGroup() { QDialog::setFixedSize(400, 200); layout->removeWidget(newLabelGroupButton); delete newLabelGroupButton; layout->removeWidget(standardLabelGroupButton); delete standardLabelGroupButton; layout->removeWidget(okButton); layout->removeWidget(cancleButton); layout->removeItem(spacer); layout->removeItem(buttonLayout); labelGroupDescriptionLabel = new QLabel("Enter the label group name!", this); layout->addWidget(labelGroupDescriptionLabel); labelGroupLineEdit = new QLineEdit(this); layout->addWidget(labelGroupLineEdit); labelDescriptionLabel = new QLabel("Enter a label name!", this); layout->addWidget(labelDescriptionLabel); auto labelLayout = new QHBoxLayout(); labelLineEdit = new QLineEdit(this); labelLayout->addWidget(labelLineEdit); addLabelButton = new QPushButton("+", this); labelLayout->addWidget(addLabelButton); connect( addLabelButton, SIGNAL(clicked()), this, SLOT(OnAddingLabel()) ); layout->addLayout(labelLayout); labelListWidget = new QListWidget(this); labelListWidget->setDragDropMode(QAbstractItemView::InternalMove); labelListWidget->addItem("Undefined"); layout->addWidget(labelListWidget); layout->addLayout(buttonLayout); connect( okButton, SIGNAL(clicked()), this, SLOT(OnAddingNewLabelGroup()) ); okButton->setVisible(true); } void QmitkTubeGraphNewLabelGroupDialog::OnAddStandardLabelGroup() { QDialog::setFixedSize(400, 200); layout->removeWidget(newLabelGroupButton); delete newLabelGroupButton; layout->removeWidget(standardLabelGroupButton); delete standardLabelGroupButton; layout->removeWidget(okButton); layout->removeWidget(cancleButton); layout->removeItem(spacer); layout->removeItem(buttonLayout); labelGroupDescriptionLabel = new QLabel("Choose one of the standard label group!", this); layout->addWidget(labelGroupDescriptionLabel); labelGroupTreeWidget = new QTreeWidget(this); labelGroupTreeWidget->header()->close(); auto defaultLabelGroups = new mitk::TubeGraphDefaultLabelGroups(); m_LabelGroupsLiver = defaultLabelGroups->GetLabelGroupForLiver(); m_LabelGroupsLung = defaultLabelGroups->GetLabelGroupForLung(); auto liverItem = new QTreeWidgetItem(labelGroupTreeWidget); liverItem->setText(0, tr("Liver")); QTreeWidgetItem* liverChildItem; for (unsigned int k = 0; k < m_LabelGroupsLiver.size(); k++) { liverChildItem = new QTreeWidgetItem(liverItem); liverChildItem->setText(0, QString::fromStdString(m_LabelGroupsLiver.at(k)->labelGroupName)); } liverItem->setExpanded(true); auto lungItem = new QTreeWidgetItem(labelGroupTreeWidget); lungItem->setText(0, tr("Lung")); QTreeWidgetItem* lungChildItem; for (unsigned int k = 0; k < m_LabelGroupsLung.size(); k++) { lungChildItem = new QTreeWidgetItem(lungItem); lungChildItem->setText(0, QString::fromStdString(m_LabelGroupsLung.at(k)->labelGroupName)); } lungItem->setExpanded(true); labelGroupTreeWidget->insertTopLevelItem(1,lungItem); delete defaultLabelGroups; layout->addWidget(labelGroupTreeWidget); layout->addLayout(buttonLayout); connect( okButton, SIGNAL(clicked()), this, SLOT(OnAddingStandardLabelGroup()) ); okButton->setVisible(true); } void QmitkTubeGraphNewLabelGroupDialog::OnAddingLabel() { if (labelLineEdit->text().isEmpty()) { labelLineEdit->setStyleSheet("border: 1px solid red"); return; } labelListWidget->addItem(labelLineEdit->text()); labelLineEdit->clear(); } void QmitkTubeGraphNewLabelGroupDialog::OnAddingNewLabelGroup() { if (labelGroupLineEdit->text().isEmpty()) { labelGroupLineEdit->setStyleSheet("border: 1px solid red"); return; } m_NewLabelGroup = new LabelGroupType(); m_NewLabelGroup->labelGroupName = (labelGroupLineEdit->text()).toStdString(); for (int i =0; i < labelListWidget->count(); i++) { auto label = new LabelType(); label->labelName = (labelListWidget->item(i)->text()).toStdString(); mitk::Color color; if(label->labelName.compare("Undefined") == 0) { color[0] = 170; color[1] = 170; color[2] = 169; } else { color[0] = rand() % 255; color[1] = rand() % 255; color[2] = rand() % 255; } label->labelColor = color; label->isVisible = true; m_NewLabelGroup->labels.push_back(label); } this->accept(); } void QmitkTubeGraphNewLabelGroupDialog::OnAddingStandardLabelGroup() { if (labelGroupTreeWidget->selectedItems().isEmpty()) { labelGroupDescriptionLabel->setStyleSheet("border: 1px solid red"); return; } if(labelGroupTreeWidget->selectedItems().at(0)->parent()->text(0) == "Lung") { for (unsigned int k = 0; k < m_LabelGroupsLung.size(); k++) { if(m_LabelGroupsLung.at(k)->labelGroupName == (labelGroupTreeWidget->selectedItems().at(0)->text(0)).toStdString()) m_NewLabelGroup = m_LabelGroupsLung.at(k); } } else { for (unsigned int k = 0; k < m_LabelGroupsLiver.size(); k++) { if(m_LabelGroupsLiver.at(k)->labelGroupName == (labelGroupTreeWidget->selectedItems().at(0)->text(0)).toStdString()) m_NewLabelGroup = m_LabelGroupsLiver.at(k); } } if (m_NewLabelGroup == nullptr) return; this->accept(); } QmitkTubeGraphNewLabelGroupDialog::LabelGroupType* QmitkTubeGraphNewLabelGroupDialog::GetLabelGroup() { return m_NewLabelGroup; }