diff --git a/Modules/QtWidgetsExt/CMakeLists.txt b/Modules/QtWidgetsExt/CMakeLists.txt index 95645b8c46..5bf4886802 100644 --- a/Modules/QtWidgetsExt/CMakeLists.txt +++ b/Modules/QtWidgetsExt/CMakeLists.txt @@ -1,6 +1,6 @@ MITK_CREATE_MODULE( INCLUDE_DIRS QmitkApplicationBase QmitkPropertyObservers DEPENDS MitkImageStatistics MitkQtWidgets - PACKAGE_DEPENDS CTK|CTKWidgets Qt4|QtWebKit Qwt + PACKAGE_DEPENDS CTK|CTKWidgets Qt4|QtWebKit Qt5|Concurrent+Svg+WebKitWidgets+Xml Qwt WARNINGS_AS_ERRORS ) diff --git a/Modules/QtWidgetsExt/QmitkCorrespondingPointSetsModel.cpp b/Modules/QtWidgetsExt/QmitkCorrespondingPointSetsModel.cpp index 1135e759da..7f38e78391 100644 --- a/Modules/QtWidgetsExt/QmitkCorrespondingPointSetsModel.cpp +++ b/Modules/QtWidgetsExt/QmitkCorrespondingPointSetsModel.cpp @@ -1,739 +1,748 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkCorrespondingPointSetsModel.h" #include #include "mitkInteractionConst.h" #include "mitkPointOperation.h" #include "mitkRenderingManager.h" #include #include #include #include #include #include #include QmitkCorrespondingPointSetsModel::QmitkCorrespondingPointSetsModel(int, QObject* parent) : QAbstractTableModel(parent), m_PointSetNode(NULL), m_ReferencePointSetNode(NULL), m_TimeStepper(NULL), m_SelectedPointSetIndex(-1), m_Interactor(NULL), m_MultiWidget( NULL ), m_PointSetModifiedObserverTag(0), m_ReferencePointSetModifiedObserverTag(0) { } Qt::ItemFlags QmitkCorrespondingPointSetsModel::flags(const QModelIndex& index) const { if (index.isValid()) return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled; else return Qt::ItemIsDropEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled; } Qt::DropActions QmitkCorrespondingPointSetsModel::supportedDropActions() const { return Qt::CopyAction | Qt::MoveAction; } bool QmitkCorrespondingPointSetsModel::dropMimeData(const QMimeData*, Qt::DropAction action, int row, int, const QModelIndex &parent) { if (action == Qt::IgnoreAction) return true; int targetRow; if (row != -1) targetRow = row; else if (parent.isValid()) targetRow = parent.row(); else targetRow = rowCount(QModelIndex()); this->MoveSelectedPoint(targetRow); return true; } QmitkCorrespondingPointSetsModel::~QmitkCorrespondingPointSetsModel() { ; } void QmitkCorrespondingPointSetsModel::RemoveObservers(){ if (m_PointSetNode) { mitk::PointSet::Pointer oldPointSet = dynamic_cast(m_PointSetNode->GetData()); if (oldPointSet.IsNotNull()) { oldPointSet->RemoveObserver(m_PointSetModifiedObserverTag); } } if (m_ReferencePointSetNode) { mitk::PointSet::Pointer oldPointSet = dynamic_cast(m_ReferencePointSetNode->GetData()); if (oldPointSet.IsNotNull()) { oldPointSet->RemoveObserver(m_ReferencePointSetModifiedObserverTag); } } } void QmitkCorrespondingPointSetsModel::AddObservers() { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if ( pointSet.IsNotNull()) { // add new observer for modified if necessary itk::ReceptorMemberCommand::Pointer modCommand = itk::ReceptorMemberCommand::New(); modCommand->SetCallbackFunction( this, &QmitkCorrespondingPointSetsModel::OnPointSetChanged ); m_PointSetModifiedObserverTag = pointSet->AddObserver( itk::ModifiedEvent(), modCommand ); } else { m_PointSetModifiedObserverTag = 0; } pointSet = this->CheckForPointSetInNode(m_ReferencePointSetNode); if ( pointSet.IsNotNull()) { // add new observer for modified if necessary itk::ReceptorMemberCommand::Pointer modCommand = itk::ReceptorMemberCommand::New(); modCommand->SetCallbackFunction( this, &QmitkCorrespondingPointSetsModel::OnPointSetChanged ); m_ReferencePointSetModifiedObserverTag = pointSet->AddObserver( itk::ModifiedEvent(), modCommand ); } else { m_ReferencePointSetModifiedObserverTag = 0; } } void QmitkCorrespondingPointSetsModel::OnPointSetChanged(const itk::EventObject&) { - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); } void QmitkCorrespondingPointSetsModel::SetPointSetNodes( std::vector nodes ) { this->RemoveObservers(); if ( nodes.size() > 1 ) { m_PointSetNode = nodes.front(); m_ReferencePointSetNode = nodes.back(); } else if ( nodes.size() == 1 ) { m_PointSetNode = nodes.front(); m_ReferencePointSetNode = NULL; } else { m_PointSetNode = NULL; m_ReferencePointSetNode = NULL; } this->AddObservers(); - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); } void QmitkCorrespondingPointSetsModel::SetTimeStep(int t) { if (!m_TimeStepper) return; m_TimeStepper->SetPos(t); - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); } int QmitkCorrespondingPointSetsModel::GetTimeStep() const { if (!m_TimeStepper) return 0; return m_TimeStepper->GetPos(); } int QmitkCorrespondingPointSetsModel::rowCount(const QModelIndex&) const { if (!m_TimeStepper) return 0; mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); mitk::PointSet::Pointer referencePointSet = this->CheckForPointSetInNode(m_ReferencePointSetNode); int sizePS = 0; int sizeRPS = 0; if ( pointSet.IsNotNull() ) { sizePS = pointSet->GetSize(m_TimeStepper->GetPos()); } if ( referencePointSet.IsNotNull() ) { sizeRPS = referencePointSet->GetSize(m_TimeStepper->GetPos()); } if ( sizePS > sizeRPS ) return sizePS; return sizeRPS; } int QmitkCorrespondingPointSetsModel::columnCount(const QModelIndex&) const { return 2; } QVariant QmitkCorrespondingPointSetsModel::data(const QModelIndex& index, int role) const { mitk::PointSet::Pointer pointSet = NULL; if ( index.column() == 0 ) pointSet = this->CheckForPointSetInNode(m_PointSetNode); else if ( index.column() == 1 ) pointSet = this->CheckForPointSetInNode(m_ReferencePointSetNode); if ( pointSet.IsNull() ) { return QVariant(); } if ( !index.isValid() ) { return QVariant(); } if ( index.row() >= pointSet->GetSize(m_TimeStepper->GetPos()) ) { return QVariant(); } if (role == Qt::DisplayRole) { int id; mitk::PointSet::PointType p; bool pointFound = this->GetPointForModelIndex(index, p, id); if (pointFound == false) return QVariant(); QString s = ""; bool firstProp = true; if (this->QTPropIdsEnabled()) { s.append(QString("%0").arg( id, 3)); firstProp = false; } if (this->QTPropCoordinatesEnabled()) { if(!firstProp) s.append(QString(": ")); s.append(QString("(%0, %1, %2)") .arg( p[0], 0, 'f', 2 ) .arg( p[1], 0, 'f', 2 ) .arg( p[2], 0, 'f', 2 )); } return QVariant(s); } else { return QVariant(); } } QVariant QmitkCorrespondingPointSetsModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) { return QVariant(); } if (orientation == Qt::Horizontal) { if (section == 0) { if ( m_PointSetNode ) return QString::fromStdString(this->m_PointSetNode->GetName()); } else if (section == 1) { if ( m_ReferencePointSetNode ) return QString::fromStdString(this->m_ReferencePointSetNode->GetName()); } return QString(); } return QString("%1").arg(section); } bool QmitkCorrespondingPointSetsModel::GetPointForModelIndex(const QModelIndex &index, mitk::PointSet::PointType& p, int& id) const { if (!m_TimeStepper) return false; mitk::PointSet::Pointer pointSet = NULL; if ( index.column() == 0 ) pointSet = this->CheckForPointSetInNode(m_PointSetNode); else if ( index.column() == 1 ) pointSet = this->CheckForPointSetInNode(m_ReferencePointSetNode); if (pointSet.IsNull() || !pointSet->GetPointSet(m_TimeStepper->GetPos())) return false; if ((index.row() < 0) || (index.row() >= (int)pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->Size())) return false; // get the nth. element, if it exists. // we can not use the index directly, because PointSet uses a map container, // where the index is not necessarily the same as the key. // Therefore we have to count the elements mitk::PointSet::PointsContainer::Iterator it = pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->Begin(); for (int i = 0; i < index.row(); ++i) { ++it; if (it == pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->End()) return false; } if (it != pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->End()) // not at the end, { p = it->Value(); id = it->Index(); return true; } return false; } bool QmitkCorrespondingPointSetsModel::GetPointForModelIndex(int row, int column, mitk::PointSet::PointType& p, int& id) const { if (!m_TimeStepper) return false; mitk::PointSet::Pointer pointSet = NULL; if (column == 0 ) pointSet = this->CheckForPointSetInNode(m_PointSetNode); else if ( column == 1 ) pointSet = this->CheckForPointSetInNode(m_ReferencePointSetNode); if (pointSet.IsNull() || !pointSet->GetPointSet(m_TimeStepper->GetPos())) return false; if ((row < 0) || (row >= (int)pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->Size())) return false; // get the nth. element, if it exists. // we can not use the index directly, because PointSet uses a map container, // where the index is not necessarily the same as the key. // Therefore we have to count the elements mitk::PointSet::PointsContainer::Iterator it = pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->Begin(); for (int i = 0; i < row; ++i) { ++it; if (it == pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->End()) return false; } if (it != pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->End()) // not at the end, { p = it->Value(); id = it->Index(); return true; } return false; } bool QmitkCorrespondingPointSetsModel::GetModelIndexForPointID(int id, QModelIndex& index, int column) const { if (!m_TimeStepper) return false; mitk::PointSet::Pointer pointSet = NULL; if (column == 0) pointSet = this->CheckForPointSetInNode(m_PointSetNode); else if (column == 1) pointSet = this->CheckForPointSetInNode(m_ReferencePointSetNode); if (!pointSet.IsNull() || !pointSet->GetPointSet(m_TimeStepper->GetPos())) { mitk::PointSet::PointsContainer::Pointer points = pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints(); if (!points->IndexExists(id)) return false; unsigned int idx = 0; for (mitk::PointSet::PointsContainer::Iterator it = points->Begin(); it != points->End(); ++it) { if (static_cast(it->Index()) == id) // we found the correct element { index = this->index(idx, column); return true; } idx++; } } return false; // nothing found } bool QmitkCorrespondingPointSetsModel::GetModelIndexForSelectedPoint(QModelIndex& index) const { if (!m_TimeStepper) return false; mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0) dataNode = this->m_PointSetNode; else if (this->m_SelectedPointSetIndex == 1) dataNode = this->m_ReferencePointSetNode; mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(dataNode); if (pointSet.IsNull()) return false; return this->GetModelIndexForPointID( pointSet->SearchSelectedPoint(m_TimeStepper->GetPos()), index, this->m_SelectedPointSetIndex); } void QmitkCorrespondingPointSetsModel::MoveSelectedPointUp() { if (!m_TimeStepper) return; mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0) dataNode = this->m_PointSetNode; else if (this->m_SelectedPointSetIndex == 1) dataNode = this->m_ReferencePointSetNode; mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(dataNode); if (pointSet.IsNull()) return; int selectedID = pointSet->SearchSelectedPoint(m_TimeStepper->GetPos()); if (selectedID == -1) return; mitk::ScalarType tsInMS = pointSet->GetTimeGeometry()->TimeStepToTimePoint(m_TimeStepper->GetPos()); mitk::PointOperation* doOp = new mitk::PointOperation(mitk::OpMOVEPOINTUP,tsInMS, pointSet->GetPoint(selectedID, m_TimeStepper->GetPos()), selectedID, true); pointSet->ExecuteOperation(doOp); - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalPointSetChanged(); } void QmitkCorrespondingPointSetsModel::MoveSelectedPointDown() { if (!m_TimeStepper) return; mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0) dataNode = this->m_PointSetNode; else if (this->m_SelectedPointSetIndex == 1) dataNode = this->m_ReferencePointSetNode; mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(dataNode); if (pointSet.IsNull()) return; int selectedID = pointSet->SearchSelectedPoint(m_TimeStepper->GetPos()); if (selectedID == -1) return; mitk::ScalarType tsInMS = pointSet->GetTimeGeometry()->TimeStepToTimePoint(m_TimeStepper->GetPos()); mitk::PointOperation* doOp = new mitk::PointOperation(mitk::OpMOVEPOINTDOWN, tsInMS, pointSet->GetPoint(selectedID, m_TimeStepper->GetPos()), selectedID, true); pointSet->ExecuteOperation(doOp); - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalPointSetChanged(); } int QmitkCorrespondingPointSetsModel::SearchSelectedPoint() { if (!m_TimeStepper) return -1; mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0) dataNode = this->m_PointSetNode; else if (this->m_SelectedPointSetIndex == 1) dataNode = this->m_ReferencePointSetNode; mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(dataNode); if (pointSet.IsNull()) return -1; return pointSet->SearchSelectedPoint(m_TimeStepper->GetPos()); } void QmitkCorrespondingPointSetsModel::RemoveSelectedPoint() { if (!m_TimeStepper) return; mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0){ dataNode = this->m_PointSetNode; } else if (this->m_SelectedPointSetIndex == 1){ dataNode = this->m_ReferencePointSetNode; } if (dataNode == NULL) return; //send a DEL event to pointsetinteractor const mitk::Event* delEvent = new mitk::Event(this->m_MultiWidget->GetRenderWindow1()->GetRenderer(), mitk::Type_KeyPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_Delete); mitk::StateEvent* delStateEvent = new mitk::StateEvent(mitk::EIDDELETE, delEvent); m_Interactor->HandleEvent(delStateEvent); delete delEvent; delete delStateEvent; - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalPointSetChanged(); } void QmitkCorrespondingPointSetsModel::MoveSelectedPoint(int targetID) { if (!m_TimeStepper) return; mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0) dataNode = this->m_PointSetNode; else if (this->m_SelectedPointSetIndex == 1) dataNode = this->m_ReferencePointSetNode; if (dataNode == NULL) return; mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(dataNode); if (pointSet.IsNull()) return; int selectedID = pointSet->SearchSelectedPoint(m_TimeStepper->GetPos()); if (targetID >= pointSet->GetSize()) targetID = pointSet->GetSize()-1; mitk::PointSet::PointsContainer::Iterator it = pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->Begin(); for (int i=0; iIndex(); if (selectedID < 0 || targetID < 0) return; int direction = mitk::OpNOTHING; if (selectedID > targetID) direction = mitk::OpMOVEPOINTUP; else if (selectedID < targetID) direction = mitk::OpMOVEPOINTDOWN; while (selectedID != targetID){ mitk::ScalarType tsInMS = pointSet->GetTimeGeometry()->TimeStepToTimePoint(m_TimeStepper->GetPos()); mitk::PointOperation* doOp = new mitk::PointOperation(direction, tsInMS, pointSet->GetPoint(selectedID, m_TimeStepper->GetPos()), selectedID, true); pointSet->ExecuteOperation(doOp); selectedID = pointSet->SearchSelectedPoint(m_TimeStepper->GetPos()); } - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalPointSetChanged(); } mitk::PointSet* QmitkCorrespondingPointSetsModel::CheckForPointSetInNode(mitk::DataNode* node) const { if (node != NULL) { mitk::PointSet::Pointer pointSet = dynamic_cast(node->GetData()); if (pointSet.IsNotNull()) return pointSet; } return NULL; } bool QmitkCorrespondingPointSetsModel::QTPropCoordinatesEnabled() const { return this->QTPropShowCoordinates; } void QmitkCorrespondingPointSetsModel::QTPropSetCoordinatesEnabled(bool showCoordinates) { this->QTPropShowCoordinates = showCoordinates; } bool QmitkCorrespondingPointSetsModel::QTPropIdsEnabled() const { return this->QTPropShowIds; } void QmitkCorrespondingPointSetsModel::QTPropSetIdsEnabled(bool showIds) { this->QTPropShowIds = showIds; } std::vector QmitkCorrespondingPointSetsModel::GetPointSetNodes(){ std::vector pointSetNodes; if ( this->m_PointSetNode ) pointSetNodes.push_back(this->m_PointSetNode); if ( this->m_ReferencePointSetNode ) pointSetNodes.push_back(this->m_ReferencePointSetNode); return pointSetNodes; } void QmitkCorrespondingPointSetsModel::SetSelectedPointSetIndex(int index) { if (index<-1 || index>1) return; this->m_SelectedPointSetIndex = index; } void QmitkCorrespondingPointSetsModel::ClearSelectedPointSet() { mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0) dataNode = this->m_PointSetNode; else if (this->m_SelectedPointSetIndex == 1) dataNode = this->m_ReferencePointSetNode; if (dataNode == NULL) return; mitk::PointSet* pointSet = dynamic_cast(dataNode->GetData()); mitk::PointSet::PointsContainer::Iterator it; if (this->m_TimeStepper->GetRangeMax()==-1) { while( !pointSet->IsEmptyTimeStep(0) ) { if (pointSet->GetPointSet(0)) { it = pointSet->GetPointSet(0)->GetPoints()->Begin(); pointSet->SetSelectInfo(it->Index(),true, 0); this->RemoveSelectedPoint(); } else { break; } } } else { int oldTimeStep = this->m_TimeStepper->GetPos(); for (int i=0; im_TimeStepper->GetRangeMax(); i++) { this->m_TimeStepper->SetPos(i); while( !pointSet->IsEmptyTimeStep(i) ) { if (pointSet->GetPointSet(i)) { it = pointSet->GetPointSet(i)->GetPoints()->Begin(); pointSet->SetSelectInfo(it->Index(),true, i); this->RemoveSelectedPoint(); } } } this->m_TimeStepper->SetPos(oldTimeStep); } - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalPointSetChanged(); } void QmitkCorrespondingPointSetsModel::ClearCurrentTimeStep() { if (!m_TimeStepper) return; mitk::DataNode* dataNode = NULL; if (this->m_SelectedPointSetIndex == 0) dataNode = this->m_PointSetNode; else if (this->m_SelectedPointSetIndex == 1) dataNode = this->m_ReferencePointSetNode; if (dataNode == NULL) return; mitk::PointSet* pointSet = dynamic_cast(dataNode->GetData()); mitk::PointSet::PointsContainer::Iterator it; while( !pointSet->IsEmptyTimeStep(m_TimeStepper->GetPos()) ) { it = pointSet->GetPointSet(m_TimeStepper->GetPos())->GetPoints()->Begin(); pointSet->SetSelectInfo(it->Index(),true, m_TimeStepper->GetPos()); this->RemoveSelectedPoint(); } - QAbstractTableModel::reset(); + QAbstractTableModel::beginResetModel(); + QAbstractTableModel::endResetModel(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalPointSetChanged(); } mitk::Stepper::Pointer QmitkCorrespondingPointSetsModel::GetStepper() { return this->m_TimeStepper; } void QmitkCorrespondingPointSetsModel::SetStepper(mitk::Stepper::Pointer stepper) { this->m_TimeStepper = stepper; } int QmitkCorrespondingPointSetsModel::GetSelectedPointSetIndex() { return this->m_SelectedPointSetIndex; } void QmitkCorrespondingPointSetsModel::UpdateSelection(mitk::DataNode* selectedNode) { this->RemoveInteractor(); if(!selectedNode) return; m_Interactor = dynamic_cast(selectedNode->GetInteractor()); if (m_Interactor.IsNull())//if not present, instanciate one m_Interactor = mitk::PointSetInteractor::New("pointsetinteractor", selectedNode); //add it to global interaction to activate it mitk::GlobalInteraction::GetInstance()->AddInteractor( m_Interactor ); } void QmitkCorrespondingPointSetsModel::RemoveInteractor() { if (m_Interactor){ mitk::GlobalInteraction::GetInstance()->RemoveInteractor( m_Interactor ); m_Interactor = NULL; } } QmitkStdMultiWidget* QmitkCorrespondingPointSetsModel::GetMultiWidget() { return this->m_MultiWidget; } void QmitkCorrespondingPointSetsModel::SetMultiWidget( QmitkStdMultiWidget* multiWidget ) { this->m_MultiWidget = multiWidget; this->m_TimeStepper = m_MultiWidget->GetTimeNavigationController()->GetTime(); } diff --git a/Modules/QtWidgetsExt/QmitkGnuplotWidget.cpp b/Modules/QtWidgetsExt/QmitkGnuplotWidget.cpp index b12ae3e7eb..d134224f01 100644 --- a/Modules/QtWidgetsExt/QmitkGnuplotWidget.cpp +++ b/Modules/QtWidgetsExt/QmitkGnuplotWidget.cpp @@ -1,221 +1,221 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include "QmitkGnuplotWidget.h" QmitkGnuplotWidget::QmitkGnuplotWidget(QWidget* parent) : QWidget(parent), m_Ui(new Ui::QmitkGnuplotWidget), m_ContextMenu(NULL), m_CopyPlotAction(NULL), m_CopyScriptAction(NULL), m_Process(new QProcess(this)) { m_Ui->setupUi(this); connect(m_Process, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(OnProcessStateChanged(QProcess::ProcessState))); connect(m_Process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(OnProcessError(QProcess::ProcessError))); connect(m_Process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(OnProcessFinished(int, QProcess::ExitStatus))); this->CreateContextMenu(); } QmitkGnuplotWidget::~QmitkGnuplotWidget() { } void QmitkGnuplotWidget::CreateContextMenu() { m_CopyPlotAction = new QAction("Copy &Plot", this); connect(m_CopyPlotAction, SIGNAL(triggered()), this, SLOT(OnCopyPlot())); m_CopyScriptAction = new QAction("Copy &Script", this); connect(m_CopyScriptAction, SIGNAL(triggered()), this, SLOT(OnCopyScript())); m_ContextMenu = new QMenu(this); m_ContextMenu->addActions(QList() << m_CopyPlotAction << m_CopyScriptAction); } void QmitkGnuplotWidget::contextMenuEvent(QContextMenuEvent* event) { const QPixmap* plot = m_Ui->label->pixmap(); m_CopyPlotAction->setEnabled(plot != NULL && !plot->isNull()); m_CopyScriptAction->setEnabled(!m_Commands.empty()); m_ContextMenu->popup(event->globalPos()); event->accept(); } void QmitkGnuplotWidget::OnCopyPlot() { const QPixmap* plot = m_Ui->label->pixmap(); if (plot != NULL && !plot->isNull()) QApplication::clipboard()->setPixmap(*plot); } void QmitkGnuplotWidget::OnCopyScript() { if (m_Commands.empty()) return; QString script = this->CreateSetTermCommand(); Q_FOREACH(const QString& command, m_Commands) { script += command + "\n"; } QApplication::clipboard()->setText(script); } void QmitkGnuplotWidget::resizeEvent(QResizeEvent*) { m_ModifiedTime.Modified(); if (m_Process->isOpen() || m_Commands.isEmpty() || m_GnuplotPath.isEmpty()) return; this->Update(); } QString QmitkGnuplotWidget::GetGnuplotPath() const { return m_GnuplotPath; } void QmitkGnuplotWidget::SetGnuplotPath(const QString &path) { m_GnuplotPath = path; m_ModifiedTime.Modified(); } QStringList QmitkGnuplotWidget::GetCommands() const { return m_Commands; } void QmitkGnuplotWidget::SetCommands(const QStringList& commands) { m_Commands = commands; m_ModifiedTime.Modified(); } void QmitkGnuplotWidget::Update() { if (m_UpdateTime < m_ModifiedTime) m_Process->start(m_GnuplotPath, QStringList() << "-"); } QSize QmitkGnuplotWidget::sizeHint() const { return QSize(400, 300); } QString QmitkGnuplotWidget::CreateSetTermCommand() const { return QString("set term pngcairo size %1,%2 enhanced font '%3,%4'\n") .arg(this->width()) .arg(this->height()) .arg(this->font().family()) .arg(this->font().pointSize()); } void QmitkGnuplotWidget::OnProcessStateChanged(QProcess::ProcessState state) { if (state == QProcess::Running) { m_UpdateTime = m_ModifiedTime; - m_Process->write(this->CreateSetTermCommand().toAscii()); + m_Process->write(this->CreateSetTermCommand().toLatin1()); Q_FOREACH(const QString& command, m_Commands) { - m_Process->write(QString("%1\n").arg(command).toAscii()); + m_Process->write(QString("%1\n").arg(command).toLatin1()); } m_Process->write("exit\n"); m_Process->closeWriteChannel(); } } void QmitkGnuplotWidget::OnProcessError(QProcess::ProcessError error) { switch (error) { case QProcess::FailedToStart: m_Ui->label->setText("Gnuplot failed to start!"); break; case QProcess::Crashed: m_Ui->label->setText("Gnuplot crashed!"); break; case QProcess::Timedout: m_Ui->label->setText("Gnuplot timed out!"); break; case QProcess::WriteError: m_Ui->label->setText("Could not write to gnuplot!"); break; case QProcess::ReadError: m_Ui->label->setText("Could not read from gnuplot!"); break; default: m_Ui->label->setText("An unknown error occurred!"); break; } } void QmitkGnuplotWidget::OnProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { bool needUpdate = false; if (exitStatus != QProcess::CrashExit) { if (exitCode == 0) { if (m_UpdateTime < m_ModifiedTime) { needUpdate = true; } else { m_Ui->label->setPixmap(QPixmap::fromImage(QImage::fromData(m_Process->readAllStandardOutput(), "PNG"))); } } else { m_Ui->label->setText(QString("Gnuplot exit code: %1!").arg(exitCode)); } } m_Process->close(); if (needUpdate) this->Update(); } diff --git a/Modules/QtWidgetsExt/QmitkHistogramJSWidget.cpp b/Modules/QtWidgetsExt/QmitkHistogramJSWidget.cpp index 453cce79dd..76f0ccd1a9 100644 --- a/Modules/QtWidgetsExt/QmitkHistogramJSWidget.cpp +++ b/Modules/QtWidgetsExt/QmitkHistogramJSWidget.cpp @@ -1,239 +1,240 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkHistogramJSWidget.h" #include "mitkPixelTypeMultiplex.h" #include #include #include "mitkRenderingManager.h" #include "mitkBaseRenderer.h" #include "mitkImageTimeSelector.h" #include "mitkExtractSliceFilter.h" +#include QmitkHistogramJSWidget::QmitkHistogramJSWidget(QWidget *parent) : QWebView(parent) { // set histogram type to barchart in first instance m_UseLineGraph = false; m_Page = new QmitkJSWebPage(this); setPage(m_Page); // set html from source connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(AddJSObject())); QUrl myUrl = QUrl("qrc:///QtWidgetsExt/Histogram.html"); setUrl(myUrl); // set Scrollbars to be always disabled page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); m_ParametricPath = ParametricPathType::New(); } QmitkHistogramJSWidget::~QmitkHistogramJSWidget() { } // adds an Object of Type QmitkHistogramJSWidget to the JavaScript, using QtWebkitBridge void QmitkHistogramJSWidget::AddJSObject() { page()->mainFrame()->addToJavaScriptWindowObject(QString("histogramData"), this); } // reloads WebView, everytime its size has been changed, so the size of the Histogram fits to the size of the widget void QmitkHistogramJSWidget::resizeEvent(QResizeEvent* resizeEvent) { QWebView::resizeEvent(resizeEvent); // workaround for Qt Bug: https://bugs.webkit.org/show_bug.cgi?id=75984 page()->mainFrame()->evaluateJavaScript("disconnectSignals()"); this->reload(); } // method to expose data to JavaScript by using properties void QmitkHistogramJSWidget::ComputeHistogram(HistogramType* histogram) { m_Histogram = histogram; HistogramConstIteratorType startIt = m_Histogram->End(); HistogramConstIteratorType endIt = m_Histogram->End(); HistogramConstIteratorType it = m_Histogram->Begin(); ClearData(); unsigned int i = 0; bool firstValue = false; // removes frequencies of 0, which are outside the first and last bin for (; it != m_Histogram->End(); ++it) { if (it.GetFrequency() > 0.0) { endIt = it; if (!firstValue) { firstValue = true; startIt = it; } } } ++endIt; // generating Lists of measurement and frequencies for (it = startIt ; it != endIt; ++it, ++i) { QVariant frequency = QVariant::fromValue(it.GetFrequency()); QVariant measurement = it.GetMeasurementVector()[0]; m_Frequency.insert(i, frequency); m_Measurement.insert(i, measurement); } m_IntensityProfile = false; this->SignalDataChanged(); } void QmitkHistogramJSWidget::ClearData() { m_Frequency.clear(); m_Measurement.clear(); } void QmitkHistogramJSWidget::ClearHistogram() { this->ClearData(); this->SignalDataChanged(); } QList QmitkHistogramJSWidget::GetFrequency() { return m_Frequency; } QList QmitkHistogramJSWidget::GetMeasurement() { return m_Measurement; } bool QmitkHistogramJSWidget::GetUseLineGraph() { return m_UseLineGraph; } void QmitkHistogramJSWidget::OnBarRadioButtonSelected() { if (m_UseLineGraph) { m_UseLineGraph = false; this->SignalGraphChanged(); } } void QmitkHistogramJSWidget::OnLineRadioButtonSelected() { if (!m_UseLineGraph) { m_UseLineGraph = true; this->SignalGraphChanged(); } } void QmitkHistogramJSWidget::SetImage(mitk::Image* image) { m_Image = image; } void QmitkHistogramJSWidget::SetPlanarFigure(const mitk::PlanarFigure* planarFigure) { m_PlanarFigure = planarFigure; } template void ReadPixel(mitk::PixelType, mitk::Image::Pointer image, itk::Index<3> indexPoint, double& value) { if (image->GetDimension() == 2) { mitk::ImagePixelReadAccessor readAccess(image, image->GetSliceData(0)); itk::Index<2> idx; idx[0] = indexPoint[0]; idx[1] = indexPoint[1]; value = readAccess.GetPixelByIndex(idx); } else if (image->GetDimension() == 3) { mitk::ImagePixelReadAccessor readAccess(image, image->GetVolumeData(0)); itk::Index<3> idx; idx[0] = indexPoint[0]; idx[1] = indexPoint[1]; idx[2] = indexPoint[2]; value = readAccess.GetPixelByIndex(idx); } else { //unhandled } } void QmitkHistogramJSWidget::ComputeIntensityProfile(unsigned int timeStep) { this->ClearData(); m_ParametricPath->Initialize(); if (m_PlanarFigure.IsNull()) { mitkThrow() << "PlanarFigure not set!"; } if (m_Image.IsNull()) { mitkThrow() << "Image not set!"; } mitk::Image::Pointer image; if (m_Image->GetDimension() == 4) { mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New(); timeSelector->SetInput(m_Image); timeSelector->SetTimeNr(timeStep); timeSelector->Update(); image = timeSelector->GetOutput(); } else { image = m_Image; } mitk::IntensityProfile::Pointer intensityProfile = mitk::ComputeIntensityProfile(image, const_cast(m_PlanarFigure.GetPointer())); m_Frequency.clear(); m_Measurement.clear(); int i = -1; mitk::IntensityProfile::ConstIterator end = intensityProfile->End(); for (mitk::IntensityProfile::ConstIterator it = intensityProfile->Begin(); it != end; ++it) { m_Frequency.push_back(it.GetMeasurementVector()[0]); m_Measurement.push_back(++i); } m_IntensityProfile = true; m_UseLineGraph = true; this->SignalDataChanged(); } bool QmitkHistogramJSWidget::GetIntensityProfile() { return m_IntensityProfile; } diff --git a/Modules/QtWidgetsExt/QmitkHistogramJSWidget.h b/Modules/QtWidgetsExt/QmitkHistogramJSWidget.h index b0de9b52f5..b5c1909c44 100644 --- a/Modules/QtWidgetsExt/QmitkHistogramJSWidget.h +++ b/Modules/QtWidgetsExt/QmitkHistogramJSWidget.h @@ -1,278 +1,278 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKHISTOGRAMJSWIDGET_H #define QMITKHISTOGRAMJSWIDGET_H #include #include -#include +#include #include "MitkQtWidgetsExtExports.h" #include #include "mitkImage.h" #include "mitkPlanarFigure.h" #include #include /** * \brief Widget which shows a histogram using JavaScript. * * This class is a QWebView. It shows the histogram for a selected image * or segmentation. It also can display an intesity profile for * path elements, which lais over an image. */ class MitkQtWidgetsExt_EXPORT QmitkHistogramJSWidget : public QWebView { Q_OBJECT /** * \brief Measurement property. * * This property is used in JavaScript as member of the current object. * It holds a QList, containing the measurements of the current histogram. * @see GetMeasurement() */ Q_PROPERTY(QList measurement READ GetMeasurement) /** * \brief Frequency property. * * This property is used in JavaScript as member of the current object. * It holds a QList, containing the frequencies of the current histogram. * @see GetFrequency() */ Q_PROPERTY(QList frequency READ GetFrequency) /** * \brief Line graph property. * * This property is used in JavaScript as member of the current object. * It holds a boolean, which sais wether to use a line or not. * @see GetUseLineGraph() */ Q_PROPERTY(bool useLineGraph READ GetUseLineGraph) /** * @brief Intesity profile property. * * This property is used in JavaScript as member of the current object. * It holds a boolean, which sais wether to use an intesity profile or not. * @see GetIntensityProfile() */ Q_PROPERTY(bool intensityProfile READ GetIntensityProfile) public: typedef mitk::Image::HistogramType HistogramType; typedef mitk::Image::HistogramType::ConstIterator HistogramConstIteratorType; typedef itk::PolyLineParametricPath< 3 > ParametricPathType; typedef itk::ParametricPath< 3 >::Superclass PathType; typedef mitk::PlanarFigure::PolyLineType VertexContainerType; explicit QmitkHistogramJSWidget(QWidget *parent = 0); ~QmitkHistogramJSWidget(); /** * \brief Event which notifies a change of the widget size. * * Reimplemented from QWebView::resizeEvent(), * reloads the webframe */ void resizeEvent(QResizeEvent* resizeEvent); /** * \brief Calculates the histogram. * * This function removes all frequencies of 0 until the first bin and behind the last bin. * It writes the measurement and frequency, which are given from the HistogramType, into * m_Measurement and m_Frequency. * The SignalDataChanged is called, to update the information, which is displayed in the webframe. */ void ComputeHistogram(HistogramType* histogram); /** * \brief Calculates the intesityprofile. * * If an image and a pathelement are set, this function * calculates an intensity profile for a pathelement which lies over an image. * Sets m_IntensityProfile and m_UseLineGraph to true. * The SignalDataChanged is called, to update the information, which is displayed in the webframe. */ void ComputeIntensityProfile(unsigned int timeStep = 0); /** * \brief Clears the Histogram. * * This function clears the data and calls SignalDataChanged to update * the displayed information in the webframe. */ void ClearHistogram(); /** * \brief Getter for measurement. * * @return List of measurements. */ QList GetMeasurement(); /** * \brief Getter for frequency. * * @return List of frequencies. */ QList GetFrequency(); /** * \brief Getter for uselineGraph. * * @return True if a linegraph should be used. */ bool GetUseLineGraph(); /** * \brief Getter for intensity profile. * * @return True if current histogram is an intesityprofile */ bool GetIntensityProfile(); /** * \brief Setter for reference image. * * @param image The corresponding image for an intensity profile. */ void SetImage(mitk::Image* image); /** * \brief Setter for planarFigure. * * @param planarFigure The pathelement for an intensity profile. */ void SetPlanarFigure(const mitk::PlanarFigure* planarFigure); private: /** * \brief List of frequencies. * * A QList which holds the frequencies of the current histogram * or holds the intesities of current intensity profile. */ QList m_Frequency; /** * \brief List of measurements. * * A QList which holds the measurements of the current histogram * or holds the distances of current intensity profile. */ QList m_Measurement; /** * \brief Reference image. * * Holds the image to calculate an intesity profile. */ mitk::Image::Pointer m_Image; /** * \brief Pathelement. * * Holds a not closed planar figure to calculate an intesity profile. */ mitk::PlanarFigure::ConstPointer m_PlanarFigure; bool m_UseLineGraph; bool m_IntensityProfile; /** * Holds the current histogram */ HistogramType::ConstPointer m_Histogram; /** * Path derived either form user-specified path or from PlanarFigure-generated * path */ PathType::ConstPointer m_DerivedPath; /** * Parametric path as generated from PlanarFigure */ ParametricPathType::Pointer m_ParametricPath; /** * \brief Clears data. * * Clears the QLists m_Measurement and m_Frequency */ void ClearData(); QmitkJSWebPage* m_Page; private slots: /** * \brief Adds an object to JavaScript. * * Adds an object of the widget to JavaScript. * By using this object JavaScript can react to the signals of the widget * and can access the QProperties as members of the object. */ void AddJSObject(); public slots: /** * \brief Slot for radiobutton m_barRadioButton. * * Sets m_UseLineGraph to false. * Calls signal GraphChanged to update the graph in the webframe. */ void OnBarRadioButtonSelected(); /** * \brief Slot for radiobutton m_lineRadioButton. * * Sets m_UseLineGraph to true. * Calls signal GraphChanged to update the graph in the webframe. */ void OnLineRadioButtonSelected(); signals: /** * \brief Signal data has changed. * * It has to be called when the data of the histogram or intesity profile has changed. */ void SignalDataChanged(); /** * \brief Signal graph has changed. * * It has to be called when the graph changed from barchart to linegraph. Vice versa. */ void SignalGraphChanged(); }; #endif diff --git a/Modules/QtWidgetsExt/QmitkModulesDialog.cpp b/Modules/QtWidgetsExt/QmitkModulesDialog.cpp index 3c3f339a3a..2f3f0636ac 100644 --- a/Modules/QtWidgetsExt/QmitkModulesDialog.cpp +++ b/Modules/QtWidgetsExt/QmitkModulesDialog.cpp @@ -1,66 +1,72 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkModulesDialog.h" #include #include #include #include #include #include "QmitkModuleTableModel.h" QmitkModulesDialog::QmitkModulesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { this->setWindowTitle("MITK Modules"); QVBoxLayout* layout = new QVBoxLayout(); this->setLayout(layout); QTableView* tableView = new QTableView(this); QmitkModuleTableModel* tableModel = new QmitkModuleTableModel(tableView); QSortFilterProxyModel* 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); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) tableView->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents); tableView->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents); tableView->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents); +#else + tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + tableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents); + tableView->horizontalHeader()->setSectionResizeMode(5, QHeaderView::ResizeToContents); +#endif tableView->horizontalHeader()->setStretchLastSection(true); tableView->horizontalHeader()->setCascadingSectionResizes(true); layout->addWidget(tableView); QDialogButtonBox* btnBox = new QDialogButtonBox(QDialogButtonBox::Close); layout->addWidget(btnBox); this->resize(800, 600); connect(btnBox, SIGNAL(rejected()), this, SLOT(reject())); } diff --git a/Modules/QtWidgetsExt/QmitkPointListModel.cpp b/Modules/QtWidgetsExt/QmitkPointListModel.cpp index f84b221e5e..05350abee6 100644 --- a/Modules/QtWidgetsExt/QmitkPointListModel.cpp +++ b/Modules/QtWidgetsExt/QmitkPointListModel.cpp @@ -1,315 +1,319 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkPointListModel.h" #include #include "mitkInteractionConst.h" #include "mitkPointOperation.h" #include "mitkRenderingManager.h" #include #include #include #include #include QmitkPointListModel::QmitkPointListModel( mitk::DataNode* pointSetNode, int t, QObject* parent ) :QAbstractListModel(parent), m_PointSetNode(NULL), m_PointSetModifiedObserverTag(0), m_PointSetDeletedObserverTag(0), m_TimeStep(t) { ObserveNewPointSet( pointSetNode ); } Qt::ItemFlags QmitkPointListModel::flags(const QModelIndex& /*index*/) const { // no editing so far, return default (enabled, selectable) return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QmitkPointListModel::~QmitkPointListModel() { this->ObserveNewPointSet( NULL ); } void QmitkPointListModel::SetPointSetNode( mitk::DataNode* pointSetNode ) { this->ObserveNewPointSet( pointSetNode ); - QAbstractListModel::reset(); + QAbstractListModel::beginResetModel(); + QAbstractListModel::beginResetModel(); emit SignalUpdateSelection(); } mitk::PointSet* QmitkPointListModel::GetPointSet() const { return this->CheckForPointSetInNode(m_PointSetNode); } void QmitkPointListModel::SetTimeStep(int t) { m_TimeStep = t; - QAbstractListModel::reset(); + QAbstractListModel::beginResetModel(); + QAbstractListModel::endResetModel(); emit SignalUpdateSelection(); } int QmitkPointListModel::GetTimeStep() const { return m_TimeStep; } void QmitkPointListModel::ObserveNewPointSet( mitk::DataNode* pointSetNode ) { //remove old observers if (m_PointSetNode != NULL) { mitk::PointSet::Pointer oldPointSet = dynamic_cast(m_PointSetNode->GetData()); if (oldPointSet.IsNotNull()) { oldPointSet->RemoveObserver(m_PointSetModifiedObserverTag); oldPointSet->RemoveObserver(m_PointSetDeletedObserverTag); } } //get the new pointset mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(pointSetNode); m_PointSetNode = pointSetNode; if ( pointSet.IsNotNull()) { // add new observer for modified if necessary itk::ReceptorMemberCommand::Pointer modCommand = itk::ReceptorMemberCommand::New(); modCommand->SetCallbackFunction( this, &QmitkPointListModel::OnPointSetChanged ); m_PointSetModifiedObserverTag = pointSet->AddObserver( itk::ModifiedEvent(), modCommand ); // add new observer for detele if necessary itk::ReceptorMemberCommand::Pointer delCommand = itk::ReceptorMemberCommand::New(); delCommand->SetCallbackFunction( this, &QmitkPointListModel::OnPointSetDeleted ); m_PointSetDeletedObserverTag = pointSet->AddObserver( itk::DeleteEvent(), delCommand ); } else { m_PointSetModifiedObserverTag = 0; m_PointSetDeletedObserverTag = 0; } } void QmitkPointListModel::OnPointSetChanged(const itk::EventObject&) { - QAbstractListModel::reset(); + QAbstractListModel::beginResetModel(); + QAbstractListModel::endResetModel(); emit SignalUpdateSelection(); } void QmitkPointListModel::OnPointSetDeleted(const itk::EventObject&) { mitk::PointSet::Pointer ps = CheckForPointSetInNode(m_PointSetNode); if (ps) { ps->RemoveObserver(m_PointSetModifiedObserverTag); ps->RemoveObserver(m_PointSetDeletedObserverTag); } m_PointSetModifiedObserverTag = 0; m_PointSetDeletedObserverTag = 0; - QAbstractListModel::reset(); + QAbstractListModel::beginResetModel(); + QAbstractListModel::endResetModel(); } int QmitkPointListModel::rowCount(const QModelIndex&) const { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if ( pointSet.IsNotNull() ) { return pointSet->GetSize(m_TimeStep); } else { return 0; } } QVariant QmitkPointListModel::data(const QModelIndex& index, int role) const { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if ( pointSet.IsNull() ) { return QVariant(); } if ( !index.isValid() ) { return QVariant(); } if ( index.row() >= pointSet->GetSize(m_TimeStep) ) { return QVariant(); } if (role == Qt::DisplayRole) { mitk::PointSet::PointsContainer::ElementIdentifier id; mitk::PointSet::PointType p; bool pointFound = this->GetPointForModelIndex(index, p, id); if (pointFound == false) return QVariant(); QString s = QString("%0: (%1, %2, %3)") .arg( id, 3) .arg( p[0], 0, 'f', 3 ) .arg( p[1], 0, 'f', 3 ) .arg( p[2], 0, 'f', 3 ); return QVariant(s); } else { return QVariant(); } } QVariant QmitkPointListModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) { return QVariant(); } if (orientation == Qt::Horizontal) { return QString("Coordinates").arg(section); } else { return QString("Row %1").arg(section); } } bool QmitkPointListModel::GetPointForModelIndex( const QModelIndex &index, mitk::PointSet::PointType& p, mitk::PointSet::PointIdentifier& id) const { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if (pointSet.IsNull()) return false; if ((index.row() < 0) || (index.row() >= (int)pointSet->GetPointSet(m_TimeStep)->GetPoints()->Size())) return false; // get the nth. element, if it exists. // we can not use the index directly, because PointSet uses a map container, // where the index is not necessarily the same as the key. // Therefore we have to count the elements mitk::PointSet::PointsContainer::Iterator it = pointSet->GetPointSet(m_TimeStep)->GetPoints()->Begin(); for (int i = 0; i < index.row(); ++i) { ++it; if (it == pointSet->GetPointSet(m_TimeStep)->GetPoints()->End()) return false; } if (it != pointSet->GetPointSet(m_TimeStep)->GetPoints()->End()) // not at the end, { p = it->Value(); id = it->Index(); return true; } return false; } bool QmitkPointListModel::GetModelIndexForPointID(mitk::PointSet::PointIdentifier id, QModelIndex& index) const { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if (pointSet.IsNull()) return false; mitk::PointSet::PointsContainer::Pointer points = pointSet->GetPointSet(m_TimeStep)->GetPoints(); if (points->IndexExists(id) == false) return false; unsigned int idx = 0; for (mitk::PointSet::PointsContainer::Iterator it = points->Begin(); it != points->End(); ++it) { if (it->Index() == id) // we found the correct element { index = this->index(idx); return true; } idx++; } return false; // nothing found } void QmitkPointListModel::MoveSelectedPointUp() { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if (pointSet.IsNull()) return; mitk::PointSet::PointIdentifier selectedID; selectedID = pointSet->SearchSelectedPoint(m_TimeStep); mitk::ScalarType tsInMS = pointSet->GetTimeGeometry()->TimeStepToTimePoint(m_TimeStep); mitk::PointOperation* doOp = new mitk::PointOperation(mitk::OpMOVEPOINTUP,tsInMS, pointSet->GetPoint(selectedID, m_TimeStep), selectedID, true); pointSet->ExecuteOperation(doOp); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper } void QmitkPointListModel::MoveSelectedPointDown() { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if (pointSet.IsNull()) return; mitk::PointSet::PointIdentifier selectedID; selectedID = pointSet->SearchSelectedPoint(m_TimeStep); mitk::ScalarType tsInMS = pointSet->GetTimeGeometry()->TimeStepToTimePoint(m_TimeStep); mitk::PointOperation* doOp = new mitk::PointOperation(mitk::OpMOVEPOINTDOWN, tsInMS, pointSet->GetPoint(selectedID, m_TimeStep), selectedID, true); pointSet->ExecuteOperation(doOp); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper } void QmitkPointListModel::RemoveSelectedPoint() { mitk::PointSet::Pointer pointSet = this->CheckForPointSetInNode(m_PointSetNode); if (pointSet.IsNull()) return; mitk::PointSet::PointIdentifier selectedID; selectedID = pointSet->SearchSelectedPoint(m_TimeStep); mitk::ScalarType tsInMS = pointSet->GetTimeGeometry()->TimeStepToTimePoint(m_TimeStep); mitk::PointOperation* doOp = new mitk::PointOperation(mitk::OpREMOVE, tsInMS, pointSet->GetPoint(selectedID, m_TimeStep), selectedID, true); pointSet->ExecuteOperation(doOp); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper } mitk::PointSet* QmitkPointListModel::CheckForPointSetInNode(mitk::DataNode* node) const { if (node != NULL) { mitk::PointSet::Pointer pointSet = dynamic_cast(node->GetData()); if (pointSet.IsNotNull()) return pointSet; } return NULL; } diff --git a/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp b/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp index d5fed5e961..245e019d3c 100755 --- a/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp +++ b/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp @@ -1,260 +1,259 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkTransferFunctionWidget.h" #include -#include QmitkTransferFunctionWidget::QmitkTransferFunctionWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { this->setupUi(this); // signals and slots connections connect(m_XEditScalarOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetXValueScalar( const QString & ))); connect(m_YEditScalarOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetYValueScalar( const QString & ))); connect(m_XEditGradientOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetXValueGradient( const QString & ))); connect(m_YEditGradientOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetYValueGradient( const QString & ))); connect(m_XEditColor, SIGNAL( textEdited ( const QString & ) ), this, SLOT(SetXValueColor( const QString & ))); m_RangeSlider->setMinimum(-2048); m_RangeSlider->setMaximum(2048); connect(m_RangeSlider, SIGNAL(valuesChanged(int,int)),this, SLOT(OnSpanChanged(int,int))); //reset button connect(m_RangeSliderReset, SIGNAL(pressed()), this, SLOT(OnResetSlider())); m_ScalarOpacityFunctionCanvas->SetQLineEdits(m_XEditScalarOpacity, m_YEditScalarOpacity); m_GradientOpacityCanvas->SetQLineEdits(m_XEditGradientOpacity, m_YEditGradientOpacity); m_ColorTransferFunctionCanvas->SetQLineEdits(m_XEditColor, 0); m_ScalarOpacityFunctionCanvas->SetTitle("Grayvalue -> Opacity"); m_GradientOpacityCanvas->SetTitle("Grayvalue/Gradient -> Opacity"); m_ColorTransferFunctionCanvas->SetTitle("Grayvalue -> Color"); } QmitkTransferFunctionWidget::~QmitkTransferFunctionWidget() { } void QmitkTransferFunctionWidget::SetScalarLabel(const QString& scalarLabel) { m_textLabelX->setText(scalarLabel); m_textLabelX_2->setText(scalarLabel); m_textLabelX_3->setText(scalarLabel); m_ScalarOpacityFunctionCanvas->SetTitle(scalarLabel + " -> Opacity"); m_GradientOpacityCanvas->SetTitle(scalarLabel + "/Gradient -> Opacity"); m_ColorTransferFunctionCanvas->SetTitle(scalarLabel + " -> Color"); } void QmitkTransferFunctionWidget::ShowScalarOpacityFunction(bool show) { m_ScalarOpacityWidget->setVisible(show); } void QmitkTransferFunctionWidget::ShowColorFunction(bool show) { m_ColorWidget->setVisible(show); } void QmitkTransferFunctionWidget::ShowGradientOpacityFunction(bool show) { m_GradientOpacityWidget->setVisible(show); } void QmitkTransferFunctionWidget::SetScalarOpacityFunctionEnabled(bool enable) { m_ScalarOpacityWidget->setEnabled(enable); } void QmitkTransferFunctionWidget::SetColorFunctionEnabled(bool enable) { m_ColorWidget->setEnabled(enable); } void QmitkTransferFunctionWidget::SetGradientOpacityFunctionEnabled(bool enable) { m_GradientOpacityWidget->setEnabled(enable); } void QmitkTransferFunctionWidget::SetDataNode(mitk::DataNode* node, const mitk::BaseRenderer* renderer) { if (node) { tfpToChange = dynamic_cast(node->GetProperty("TransferFunction", renderer)); if(!tfpToChange) { if (! dynamic_cast(node->GetData())) { MITK_WARN << "QmitkTransferFunctionWidget::SetDataNode called with non-image node"; goto turnOff; } node->SetProperty("TransferFunction", tfpToChange = mitk::TransferFunctionProperty::New() ); } mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); if( mitk::BaseData* data = node->GetData() ) { mitk::SimpleHistogram *h = histogramCache[data]; m_RangeSliderMin= h->GetMin(); m_RangeSliderMax= h->GetMax(); m_RangeSlider->blockSignals(true); m_RangeSlider->setMinimum(m_RangeSliderMin); m_RangeSlider->setMaximum(m_RangeSliderMax); m_RangeSlider->setMinimumValue(m_RangeSliderMin); m_RangeSlider->setMaximumValue(m_RangeSliderMax); m_RangeSlider->blockSignals(false); m_ScalarOpacityFunctionCanvas->SetHistogram( h ); m_GradientOpacityCanvas->SetHistogram( h ); m_ColorTransferFunctionCanvas->SetHistogram( h ); } OnUpdateCanvas(); return; } turnOff: m_ScalarOpacityFunctionCanvas->setEnabled(false); m_ScalarOpacityFunctionCanvas->SetHistogram(0); m_GradientOpacityCanvas->setEnabled(false); m_GradientOpacityCanvas->SetHistogram(0); m_ColorTransferFunctionCanvas->setEnabled(false); m_ColorTransferFunctionCanvas->SetHistogram(0); tfpToChange = 0; } void QmitkTransferFunctionWidget::OnUpdateCanvas() { if(tfpToChange.IsNull()) return; mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); if(tf.IsNull()) return; m_ScalarOpacityFunctionCanvas->SetPiecewiseFunction( tf->GetScalarOpacityFunction() ); m_GradientOpacityCanvas->SetPiecewiseFunction( tf->GetGradientOpacityFunction() ); m_ColorTransferFunctionCanvas->SetColorTransferFunction( tf->GetColorTransferFunction() ); UpdateRanges(); m_ScalarOpacityFunctionCanvas->update(); m_GradientOpacityCanvas->update(); m_ColorTransferFunctionCanvas->update(); } void QmitkTransferFunctionWidget::SetXValueScalar( const QString text ) { if ( !text.endsWith( "." )) { m_ScalarOpacityFunctionCanvas->SetX(text.toFloat()); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkTransferFunctionWidget::SetYValueScalar( const QString text ) { if ( !text.endsWith( "." )) { m_ScalarOpacityFunctionCanvas->SetY(text.toFloat()); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkTransferFunctionWidget::SetXValueGradient( const QString text ) { if ( !text.endsWith( "." )) { m_GradientOpacityCanvas->SetX(text.toFloat()); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkTransferFunctionWidget::SetYValueGradient( const QString text ) { if ( !text.endsWith( "." )) { m_GradientOpacityCanvas->SetY(text.toFloat()); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkTransferFunctionWidget::SetXValueColor( const QString text ) { if ( !text.endsWith( "." )) { m_ColorTransferFunctionCanvas->SetX(text.toFloat()); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkTransferFunctionWidget::UpdateRanges() { int lower = m_RangeSlider->minimumValue(); int upper = m_RangeSlider->maximumValue(); m_ScalarOpacityFunctionCanvas->SetMin(lower); m_ScalarOpacityFunctionCanvas->SetMax(upper); m_GradientOpacityCanvas->SetMin(lower); m_GradientOpacityCanvas->SetMax(upper); m_ColorTransferFunctionCanvas->SetMin(lower); m_ColorTransferFunctionCanvas->SetMax(upper); } void QmitkTransferFunctionWidget::OnSpanChanged(int, int) { UpdateRanges(); m_GradientOpacityCanvas->update(); m_ColorTransferFunctionCanvas->update(); m_ScalarOpacityFunctionCanvas->update(); } void QmitkTransferFunctionWidget::OnResetSlider() { m_RangeSlider->blockSignals(true); m_RangeSlider->setMaximumValue(m_RangeSliderMax); m_RangeSlider->setMinimumValue(m_RangeSliderMin); m_RangeSlider->blockSignals(false); UpdateRanges(); m_GradientOpacityCanvas->update(); m_ColorTransferFunctionCanvas->update(); m_ScalarOpacityFunctionCanvas->update(); } diff --git a/Modules/QtWidgetsExt/QmitkWebPage.h b/Modules/QtWidgetsExt/QmitkWebPage.h index c7a6c33ca8..90a55ae0ee 100644 --- a/Modules/QtWidgetsExt/QmitkWebPage.h +++ b/Modules/QtWidgetsExt/QmitkWebPage.h @@ -1,54 +1,54 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include +#include #ifndef QMITK_WEBPAGE_H #define QMITK_WEBPAGE_H /** * @brief The QmitkWebPage class * * This class reimplements QWebPage as a fix for bug 16158. */ class QmitkJSWebPage : public QWebPage { Q_OBJECT public: /** * @brief Constructor */ QmitkJSWebPage(QObject *parent=0); /** * @brief Destructor */ virtual ~QmitkJSWebPage(); public slots: /** * @brief shouldInterruptJavaScript * * Overwritten from QWebView, to stop asking Qt to stop the JavaScript. * @return false so JavaScript is not stopped */ bool shouldInterruptJavaScript(); }; #endif diff --git a/Modules/QtWidgetsExt/qclickablelabel.cpp b/Modules/QtWidgetsExt/qclickablelabel.cpp index a6fc72a82d..fb441c85b3 100644 --- a/Modules/QtWidgetsExt/qclickablelabel.cpp +++ b/Modules/QtWidgetsExt/qclickablelabel.cpp @@ -1,115 +1,123 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "qclickablelabel.h" #include #include +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QClickableLabel::QClickableLabel( QWidget* parent, Qt::WFlags f ) +#else +QClickableLabel::QClickableLabel( QWidget* parent, Qt::WindowFlags f ) +#endif :QLabel(parent, f) { } +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QClickableLabel::QClickableLabel( const QString& text, QWidget* parent, Qt::WFlags f ) +#else +QClickableLabel::QClickableLabel( const QString& text, QWidget* parent, Qt::WindowFlags f ) +#endif :QLabel(text, parent, f) { } QClickableLabel::~QClickableLabel() { } void QClickableLabel::AddHotspot( const QString& name, const QRect position ) { m_Hotspots.push_back( position ); m_HotspotIndexForName.insert( std::make_pair( name, (int)m_Hotspots.size()-1 ) ); m_HotspotNameForIndex.insert( std::make_pair( (int)m_Hotspots.size()-1, name ) ); } void QClickableLabel::RemoveHotspot( const QString& name ) { NameToIndexMapType::iterator iter = m_HotspotIndexForName.find( name ); if ( iter != m_HotspotIndexForName.end() ) { RemoveHotspot( iter->second ); } } void QClickableLabel::RemoveHotspot( unsigned int hotspotIndex ) { if ( hotspotIndex < m_Hotspots.size() ) { m_Hotspots.erase( m_Hotspots.begin() + hotspotIndex ); QString name = m_HotspotNameForIndex[hotspotIndex]; m_HotspotNameForIndex.erase( hotspotIndex ); m_HotspotIndexForName.erase( name ); } } void QClickableLabel::RemoveAllHotspots() { m_Hotspots.clear(); m_HotspotIndexForName.clear(); m_HotspotNameForIndex.clear(); } void QClickableLabel::mousePressEvent( QMouseEvent* e ) { unsigned int index = matchingRect( e->pos() ); if ( index < m_Hotspots.size() ) { emit mouseReleased( index ); emit mouseReleased( m_HotspotNameForIndex[index] ); } } void QClickableLabel::mouseReleaseEvent( QMouseEvent* e ) { unsigned int index = matchingRect( e->pos() ); if ( index < m_Hotspots.size() ) { emit mousePressed( index ); emit mousePressed( m_HotspotNameForIndex[index] ); } } unsigned int QClickableLabel::matchingRect( const QPoint& p ) { unsigned int index(0); for ( RectVectorType::iterator iter = m_Hotspots.begin(); iter != m_Hotspots.end(); ++iter ) { if ( iter->contains(p) ) { return index; } ++index; } return index; } diff --git a/Modules/QtWidgetsExt/qclickablelabel.h b/Modules/QtWidgetsExt/qclickablelabel.h index 8da31dca32..5daf55ce5f 100644 --- a/Modules/QtWidgetsExt/qclickablelabel.h +++ b/Modules/QtWidgetsExt/qclickablelabel.h @@ -1,77 +1,81 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef qclickablelabelhincluded #define qclickablelabelhincluded #include #include "MitkQtWidgetsExtExports.h" #include #include #include "mitkCommon.h" /** \brief A QLabel with multiple hotspots, that can be clicked Specially useful in connection with a pixmap. Stretched images should be avoided, because the hotspots will not be adjusted in any way. */ class MitkQtWidgetsExt_EXPORT QClickableLabel : public QLabel { Q_OBJECT public: - +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QClickableLabel( QWidget* parent, Qt::WFlags f = 0 ); QClickableLabel( const QString& text, QWidget* parent, Qt::WFlags f = 0 ); +#else + QClickableLabel( QWidget* parent, Qt::WindowFlags f = 0 ); + QClickableLabel( const QString& text, QWidget* parent, Qt::WindowFlags f = 0 ); +#endif virtual ~QClickableLabel(); void AddHotspot( const QString& name, const QRect position ); void RemoveHotspot( const QString& name ); void RemoveHotspot( unsigned int hotspotIndex ); void RemoveAllHotspots(); signals: void mousePressed( const QString& hotspotName ); void mousePressed( unsigned int hotspotIndex ); void mouseReleased( const QString& hotspotName ); void mouseReleased( unsigned int hotspotIndex ); protected: virtual void mousePressEvent ( QMouseEvent* e ); virtual void mouseReleaseEvent ( QMouseEvent* e ); /// returns index == m_Hotspots.size() if nothing is hit unsigned int matchingRect( const QPoint& p ); typedef std::vector< QRect > RectVectorType; RectVectorType m_Hotspots; typedef std::map< QString, unsigned int > NameToIndexMapType; typedef std::map< unsigned int, QString > IndexToNameMapType; NameToIndexMapType m_HotspotIndexForName; IndexToNameMapType m_HotspotNameForIndex; }; #endif