From 03ff43237dc145a22ba36b009551f26db6cb3abe Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 4 Nov 2019 15:26:03 +0100 Subject: [PATCH] Add a view id tag to project tree and tooltip * Remove it from property editor --- .../Application/RiaPreferences.cpp | 24 ++- ApplicationCode/Application/RiaPreferences.h | 2 + .../Flow/RimFlowCharacteristicsPlot.cpp | 1 - .../Flow/RimWellAllocationPlot.cpp | 4 +- .../ProjectDataModel/Flow/RimWellPltPlot.cpp | 2 - .../ProjectDataModel/Flow/RimWellRftPlot.cpp | 1 - .../GridCrossPlots/RimGridCrossPlot.cpp | 2 - .../ProjectDataModel/Rim3dView.cpp | 2 - .../ProjectDataModel/RimPlotInterface.h | 9 ++ .../ProjectDataModel/RimProject.cpp | 6 +- .../ProjectDataModel/RimViewWindow.cpp | 20 ++- .../ProjectDataModel/RimViewWindow.h | 3 +- .../RimWellBoreStabilityPlot.cpp | 2 - .../ProjectDataModel/RimWellLogPlot.cpp | 2 - .../Summary/RimSummaryPlot.cpp | 2 - .../UserInterface/RiuQwtPlotWidget.cpp | 8 +- .../cafPdmUiTreeSelectionEditor.cpp | 1 + .../cafPdmUiTreeViewEditor.cpp | 139 +++++++++++++++++- .../cafUserInterface/cafPdmUiTreeViewEditor.h | 42 +++++- .../cafPdmUiTreeViewQModel.cpp | 22 +++ .../cafUserInterface/cafPdmUiTreeViewQModel.h | 2 + 21 files changed, 261 insertions(+), 35 deletions(-) diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index 7c6ae06a52..608e1bde66 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -191,6 +191,9 @@ RiaPreferences::RiaPreferences( void ) "", "" ); m_appendFieldKeywordToToolTipText.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + CAF_PDM_InitField( &m_showViewIdInProjectTree, "showViewIdInTree", false, "Show View Id in Project Tree", "", "", "" ); + m_showViewIdInProjectTree.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + CAF_PDM_InitField( &m_showTestToolbar, "showTestToolbar", false, "Enable Test Toolbar", "", "", "" ); m_showTestToolbar.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); CAF_PDM_InitField( &m_includeFractureDebugInfoFile, @@ -357,12 +360,12 @@ void RiaPreferences::defineEditorAttribute( const caf::PdmFieldHandle* field, } if ( field == &octaveShowHeaderInfoWhenExecutingScripts || field == &autocomputeDepthRelatedProperties || - field == &loadAndShowSoil || field == &useShaders || field == &showHud || - field == &m_appendClassNameToUiText || field == &m_appendFieldKeywordToToolTipText || - field == &m_showTestToolbar || field == &m_includeFractureDebugInfoFile || - field == &showLasCurveWithoutTvdWarning || field == &holoLensDisableCertificateVerification || - field == &m_showProjectChangedDialog || field == &m_searchPlotTemplateFoldersRecursively || - field == &showLegendBackground || field == &m_showSummaryTimeAsLongString ) + field == &loadAndShowSoil || field == &useShaders || field == &showHud || field == &m_appendClassNameToUiText || + field == &m_appendFieldKeywordToToolTipText || field == &m_showTestToolbar || + field == &m_includeFractureDebugInfoFile || field == &showLasCurveWithoutTvdWarning || + field == &holoLensDisableCertificateVerification || field == &m_showProjectChangedDialog || + field == &m_searchPlotTemplateFoldersRecursively || field == &showLegendBackground || + field == &m_showSummaryTimeAsLongString || field == &m_showViewIdInProjectTree ) { caf::PdmUiCheckBoxEditorAttribute* myAttr = dynamic_cast( attribute ); if ( myAttr ) @@ -481,6 +484,7 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& { uiOrdering.add( &m_appendClassNameToUiText ); uiOrdering.add( &m_appendFieldKeywordToToolTipText ); + uiOrdering.add( &m_showViewIdInProjectTree ); uiOrdering.add( &m_showProjectChangedDialog ); @@ -653,6 +657,14 @@ bool RiaPreferences::appendFieldKeywordToToolTipText() const return RiaApplication::enableDevelopmentFeatures() && m_appendFieldKeywordToToolTipText(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiaPreferences::showViewIdInProjectTree() const +{ + return RiaApplication::enableDevelopmentFeatures() && m_showViewIdInProjectTree(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index 975a0195b6..9dc52d1f4c 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -71,6 +71,7 @@ public: // Debug settings bool appendClassNameToUiText() const; bool appendFieldKeywordToToolTipText() const; + bool showViewIdInProjectTree() const; bool showTestToolbar() const; bool includeFractureDebugInfoFile() const; bool showProjectChangedDialog() const; @@ -163,6 +164,7 @@ private: caf::PdmChildField m_readerSettings; caf::PdmField m_appendClassNameToUiText; caf::PdmField m_appendFieldKeywordToToolTipText; + caf::PdmField m_showViewIdInProjectTree; caf::PdmField m_showProjectChangedDialog; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp index db0bdeda30..eed12db7f3 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp @@ -366,7 +366,6 @@ QList //-------------------------------------------------------------------------------------------------- void RimFlowCharacteristicsPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); { // Ensure a case is selected if one is available RimProject* proj = nullptr; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 4b95a0ae84..0d72b941d2 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -124,7 +124,7 @@ RimWellAllocationPlot::RimWellAllocationPlot() m_accumulatedWellFlowPlot->setAvailableDepthUnits( {} ); m_accumulatedWellFlowPlot->setAvailableDepthTypes( - {RimWellLogPlot::CONNECTION_NUMBER, RimWellLogPlot::TRUE_VERTICAL_DEPTH, RimWellLogPlot::PSEUDO_LENGTH} ); + { RimWellLogPlot::CONNECTION_NUMBER, RimWellLogPlot::TRUE_VERTICAL_DEPTH, RimWellLogPlot::PSEUDO_LENGTH } ); m_accumulatedWellFlowPlot->setCommonDataSourceEnabled( false ); } @@ -796,8 +796,6 @@ QImage RimWellAllocationPlot::snapshotWindowContent() //-------------------------------------------------------------------------------------------------- void RimWellAllocationPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); - uiOrdering.add( &m_userName ); uiOrdering.add( &m_showPlotTitle ); diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp index 68db97c685..0bbf9a51da 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp @@ -976,8 +976,6 @@ void RimWellPltPlot::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrderin //-------------------------------------------------------------------------------------------------- void RimWellPltPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); - uiOrdering.add( &m_wellPathName ); caf::PdmUiGroup* sourcesGroup = uiOrdering.addNewGroupWithKeyword( "Sources", "Sources" ); diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp index 9f1abbf590..392a0c1179 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp @@ -883,7 +883,6 @@ void RimWellRftPlot::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrderin //-------------------------------------------------------------------------------------------------- void RimWellRftPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); uiOrdering.add( &m_wellPathNameOrSimWellName ); uiOrdering.add( &m_showStatisticsCurves ); uiOrdering.add( &m_showEnsembleCurves ); diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp index 5fef700ecd..a2dfdb40d3 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp @@ -452,8 +452,6 @@ void RimGridCrossPlot::initAfterRead() //-------------------------------------------------------------------------------------------------- void RimGridCrossPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); - uiOrdering.add( &m_showInfoBox ); if ( isStandalonePlot() ) diff --git a/ApplicationCode/ProjectDataModel/Rim3dView.cpp b/ApplicationCode/ProjectDataModel/Rim3dView.cpp index 4c5813c517..12d466d37e 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dView.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dView.cpp @@ -327,8 +327,6 @@ void Rim3dView::deleteViewWidget() //-------------------------------------------------------------------------------------------------- void Rim3dView::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); - caf::PdmUiGroup* viewGroup = uiOrdering.addNewGroupWithKeyword( "Viewer", "ViewGroup" ); viewGroup->add( &m_backgroundColor ); diff --git a/ApplicationCode/ProjectDataModel/RimPlotInterface.h b/ApplicationCode/ProjectDataModel/RimPlotInterface.h index be4203fbb0..d9377fc92a 100644 --- a/ApplicationCode/ProjectDataModel/RimPlotInterface.h +++ b/ApplicationCode/ProjectDataModel/RimPlotInterface.h @@ -62,6 +62,15 @@ public: } virtual void setWidthScaleFactor( WidthScaleFactor scaleFactor ) {} + virtual int rowSpan() const + { + return 1; + } + virtual int colSpan() const + { + return 1; + } + virtual bool hasCustomFontSizes( RiaDefines::FontSettingType fontSettingType, int defaultFontSize ) const = 0; virtual bool applyFontSize( RiaDefines::FontSettingType fontSettingType, int oldFontSize, diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index 237e62077f..7fe4553816 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -101,9 +101,9 @@ CAF_PDM_SOURCE_INIT( RimProject, "ResInsightProject" ); /// //-------------------------------------------------------------------------------------------------- RimProject::RimProject( void ) - : m_nextValidCaseId( 0 ) - , m_nextValidCaseGroupId( 0 ) - , m_nextValidViewId( 0 ) + : m_nextValidCaseId( 1 ) + , m_nextValidCaseGroupId( 1 ) + , m_nextValidViewId( 1 ) { CAF_PDM_InitObject( "Project", "", "", "" ); diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp index 8e13173455..14f23b084c 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp @@ -19,13 +19,18 @@ #include "RimViewWindow.h" #include "RiaApplication.h" +#include "RiaColorTables.h" +#include "RiaColorTools.h" #include "RiaFieldHandleTools.h" #include "RiaGuiApplication.h" +#include "RiaPreferences.h" + #include "RicfCommandObject.h" #include "RimMdiWindowController.h" #include "RimProject.h" +#include "cafPdmUiTreeViewEditor.h" #include "cvfAssert.h" #include @@ -54,7 +59,10 @@ RimViewWindow::RimViewWindow( void ) // Obsolete field CAF_PDM_InitFieldNoDefault( &obsoleteField_windowGeometry, "WindowGeometry", "", "", "", "" ); RiaFieldhandleTools::disableWriteAndSetFieldHidden( &obsoleteField_windowGeometry ); + RiaApplication::instance()->project()->assignViewIdToView( this ); + QString viewIdTooltip = QString( "View id: %1" ).arg( m_viewId ); + this->setUiToolTip( viewIdTooltip ); } //-------------------------------------------------------------------------------------------------- @@ -306,7 +314,15 @@ void RimViewWindow::initAfterRead() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimViewWindow::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) +void RimViewWindow::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) { - uiOrdering.add( &m_viewId ); + caf::PdmUiTreeViewItemAttribute* treeItemAttribute = dynamic_cast( attribute ); + if ( treeItemAttribute && RiaApplication::instance()->preferences()->showViewIdInProjectTree() ) + { + treeItemAttribute->tag = QString( "%1" ).arg( m_viewId ); + cvf::Color3f viewColor = RiaColorTables::contrastCategoryPaletteColors().cycledColor3f( (size_t)m_viewId ); + cvf::Color3f viewTextColor = RiaColorTools::contrastColor( viewColor ); + treeItemAttribute->bgColor = QColor( RiaColorTools::toQColor( viewColor ) ); + treeItemAttribute->fgColor = QColor( RiaColorTools::toQColor( viewTextColor ) ); + } } diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.h b/ApplicationCode/ProjectDataModel/RimViewWindow.h index f2f9ff7da9..bc85eb7ab3 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.h @@ -126,7 +126,8 @@ protected: const QVariant& oldValue, const QVariant& newValue ) override; void initAfterRead() override; - void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; + + void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; private: void setAsMdiWindow( int mainWindowID ); diff --git a/ApplicationCode/ProjectDataModel/RimWellBoreStabilityPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellBoreStabilityPlot.cpp index f6419a60dc..a54212cd85 100644 --- a/ApplicationCode/ProjectDataModel/RimWellBoreStabilityPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellBoreStabilityPlot.cpp @@ -125,8 +125,6 @@ double RimWellBoreStabilityPlot::userDefinedUcs() const //-------------------------------------------------------------------------------------------------- void RimWellBoreStabilityPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); - m_commonDataSource->uiOrdering( RimWellLogCurveCommonDataSource::smoothingUiOrderinglabel(), uiOrdering ); caf::PdmUiGroup* parameterSources = uiOrdering.addNewGroup( "Parameter Sources" ); diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index e332cd5468..267217619b 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -593,8 +593,6 @@ void RimWellLogPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField, //-------------------------------------------------------------------------------------------------- void RimWellLogPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); - if ( m_commonDataSourceEnabled ) { m_commonDataSource->uiOrdering( uiConfigName, uiOrdering ); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index a4b475ba52..66982d5a9d 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -1668,8 +1668,6 @@ void RimSummaryPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& mainOptions->add( &m_normalizeCurveYValues ); - RimViewWindow::defineUiOrdering( uiConfigName, uiOrdering ); - uiOrdering.skipRemainingFields( true ); } diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp index 9aaec9e273..e6379219b6 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp @@ -627,8 +627,8 @@ RiuWidgetStyleSheet RiuQwtPlotWidget::createPlotStyleSheet() const { QColor backgroundColor = QColor( "white" ); QColor highlightColor = QApplication::palette().highlight().color(); - QColor blendedHighlightColor = RiaColorTools::blendQColors( highlightColor, backgroundColor, 1, 10 ); - QColor nearlyBackgroundColor = RiaColorTools::blendQColors( highlightColor, backgroundColor, 1, 30 ); + QColor blendedHighlightColor = RiaColorTools::blendQColors( highlightColor, backgroundColor, 1, 20 ); + QColor nearlyBackgroundColor = RiaColorTools::blendQColors( highlightColor, backgroundColor, 1, 40 ); RiuWidgetStyleSheet styleSheet; styleSheet.set( "background-color", backgroundColor.name() ); @@ -639,12 +639,14 @@ RiuWidgetStyleSheet RiuQwtPlotWidget::createPlotStyleSheet() const if ( m_draggable ) { QString backgroundGradient = QString( QString( "qlineargradient( x1 : 1, y1 : 0, x2 : 1, y2 : 1," - "stop: 0 %1, stop: 0.015 %2, stop:1 %3 )" ) + "stop: 0 %1, stop: 0.02 %2, stop:1 %3 )" ) .arg( blendedHighlightColor.name() ) .arg( nearlyBackgroundColor.name() ) .arg( backgroundColor.name() ) ); styleSheet.state( RiuWidgetStyleSheet::HOVER ).set( "background", backgroundGradient ); + styleSheet.state( RiuWidgetStyleSheet::HOVER ) + .set( "border", QString( "1px dashed %1" ).arg( blendedHighlightColor.name() ) ); } styleSheet.state( RiuWidgetStyleSheet::DRAG_TARGET_BEFORE ).set( "border-left", "1px solid lime" ); styleSheet.state( RiuWidgetStyleSheet::DRAG_TARGET_AFTER ).set( "border-right", "1px solid lime" ); diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp index 24959a67d2..7a315dd09b 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp @@ -351,6 +351,7 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName) } } } + // If the tree doesn't have grand children we treat this as a straight list m_treeView->setRootIsDecorated(m_model->hasGrandChildren()); diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp index b3d6f44e2d..70eae6726a 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp @@ -51,7 +51,9 @@ #include #include #include +#include #include +#include #include #include @@ -108,6 +110,7 @@ PdmUiTreeViewEditor::PdmUiTreeViewEditor() m_layout = nullptr; m_treeView = nullptr; m_treeViewModel = nullptr; + m_delegate = nullptr; } //-------------------------------------------------------------------------------------------------- @@ -133,6 +136,10 @@ QWidget* PdmUiTreeViewEditor::createWidget(QWidget* parent) m_treeView->setModel(m_treeViewModel); m_treeView->installEventFilter(this); + m_delegate = new PdmUiTreeViewItemDelegate(m_treeView, m_treeViewModel); + + m_treeView->setItemDelegate(m_delegate); + connect(treeView()->selectionModel(), SIGNAL(selectionChanged( const QItemSelection & , const QItemSelection & )), SLOT(slotOnSelectionChanged( const QItemSelection & , const QItemSelection & ))); m_layout->addWidget(m_treeView); @@ -153,7 +160,7 @@ void PdmUiTreeViewEditor::configureAndUpdateUi(const QString& uiConfigName) PdmUiObjectHandle* uiObjectHandle = dynamic_cast(this->pdmItemRoot()); if (uiObjectHandle) { - uiObjectHandle->objectEditorAttribute(uiConfigName, &editorAttributes); + uiObjectHandle->objectEditorAttribute(uiConfigName, &editorAttributes); } } @@ -169,6 +176,12 @@ void PdmUiTreeViewEditor::configureAndUpdateUi(const QString& uiConfigName) selectAsCurrentItem(uiObjectHandle); } } + + if (m_delegate) + { + m_delegate->clearAttributes(); + updateItemDelegateForSubTree(); + } } //-------------------------------------------------------------------------------------------------- @@ -213,7 +226,12 @@ void PdmUiTreeViewEditor::selectedUiItems(std::vector& objects) //-------------------------------------------------------------------------------------------------- void PdmUiTreeViewEditor::updateMySubTree(PdmUiItem* uiItem) { - if (m_treeViewModel) { m_treeViewModel->updateSubTree(uiItem); } + if (m_treeViewModel) + { + m_treeViewModel->updateSubTree(uiItem); + QModelIndex index = m_treeViewModel->findModelIndex(uiItem); + updateItemDelegateForSubTree(index); + } } //-------------------------------------------------------------------------------------------------- @@ -422,6 +440,29 @@ void PdmUiTreeViewEditor::updateSelectionManager() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiTreeViewEditor::updateItemDelegateForSubTree(const QModelIndex& modelIndex /*= QModelIndex()*/) +{ + + auto allIndices = m_treeViewModel->allIndicesRecursive(); + for (QModelIndex index : allIndices) + { + PdmUiItem* uiItem = m_treeViewModel->uiItemFromModelIndex(index); + PdmUiObjectHandle* uiObjectHandle = dynamic_cast(uiItem); + if (uiObjectHandle) + { + PdmUiTreeViewItemAttribute attribute; + uiObjectHandle->objectEditorAttribute("", &attribute); + if (!attribute.tag.isEmpty()) + { + m_delegate->addAttribute(index, attribute); + } + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -439,4 +480,98 @@ bool PdmUiTreeViewEditor::isAppendOfClassNameToUiItemTextEnabled() } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiTreeViewItemDelegate::PdmUiTreeViewItemDelegate(QObject* parent, PdmUiTreeViewQModel* model) + : QStyledItemDelegate(parent) + , m_model(model) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiTreeViewItemDelegate::clearAttributes() +{ + m_attributes.clear(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiTreeViewItemDelegate::addAttribute(QModelIndex index, const PdmUiTreeViewItemAttribute& attribute) +{ + m_attributes[index] = attribute; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiTreeViewItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QStyledItemDelegate::paint(painter, option, index); + + // Save painter so we can restore it + painter->save(); + + auto it = m_attributes.find(index); + if (it == m_attributes.end()) return; + + const int insideTopBottomMargins = 1; + const int insideleftRightMargins = 6; + const int outsideLeftRightMargins = 4; + + QFont font = QApplication::font(); + if (font.pixelSize() > 0) + { + font.setPixelSize(std::max(1, font.pixelSize() - 2)); + } + else + { + font.setPointSize(std::max(1, font.pointSize() - 2)); + } + painter->setFont(font); + + QString text = it->second.tag; + QColor bgColor = it->second.bgColor; + QColor fgColor = it->second.fgColor; + + QSize textSize(QFontMetrics(font).size(Qt::TextSingleLine, text)); + QRect rect = option.rect; + QSize fullSize = rect.size(); + int textDiff = (fullSize.height() - textSize.height()); + + QRect textRect; + if (it->second.position == PdmUiTreeViewItemAttribute::AT_END) + { + QPoint bottomRight = rect.bottomRight() - QPoint(outsideLeftRightMargins, 0); + QPoint textBottomRight = bottomRight - QPoint(insideleftRightMargins, textDiff / 2); + QPoint textTopLeft = textBottomRight - QPoint(textSize.width(), textSize.height()); + textRect = QRect(textTopLeft, textBottomRight); + } + else + { + QPoint textTopLeft = QPoint(0, rect.topLeft().y()) + QPoint(outsideLeftRightMargins + insideleftRightMargins, + textDiff / 2); + QPoint textBottomRight = textTopLeft + QPoint(textSize.width(), textSize.height()); + textRect = QRect(textTopLeft, textBottomRight); + } + QRect tagRect = textRect.marginsAdded(QMargins(insideleftRightMargins, insideTopBottomMargins, insideleftRightMargins, insideTopBottomMargins)); + + QBrush brush(bgColor); + + painter->setBrush(brush); + painter->setPen(bgColor); + painter->setRenderHint(QPainter::Antialiasing); + const double xRoundingRadiusPercent = 50.0; + const double yRoundingRadiusPercent = 25.0; + painter->drawRoundedRect(tagRect, xRoundingRadiusPercent, yRoundingRadiusPercent, Qt::RelativeSize); + + painter->setPen(fgColor); + painter->drawText(textRect, Qt::AlignCenter, text); + + // Restore painter + painter->restore(); +} + } // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h index 47de8a8126..ea4afd6af1 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h @@ -42,9 +42,11 @@ #include "cafPdmUiTreeViewQModel.h" #include +#include #include #include #include +#include #include @@ -61,9 +63,45 @@ namespace caf class PdmChildArrayFieldHandle; class PdmUiDragDropInterface; class PdmUiItem; +class PdmUiTreeViewEditor; class PdmUiTreeViewQModel; class PdmUiTreeViewWidget; +class PdmUiTreeViewItemAttribute : public PdmUiEditorAttribute +{ +public: + enum Position + { + IN_FRONT, + AT_END + }; + PdmUiTreeViewItemAttribute() + : tag() + , position(AT_END) + , bgColor(Qt::red) + , fgColor(Qt::white) + { + + } + QString tag; + Position position; + QColor bgColor; + QColor fgColor; +}; + +class PdmUiTreeViewItemDelegate : public QStyledItemDelegate +{ +public: + PdmUiTreeViewItemDelegate(QObject* parent, PdmUiTreeViewQModel* model); + void clearAttributes(); + void addAttribute(QModelIndex index, const PdmUiTreeViewItemAttribute& attribute); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + +private: + PdmUiTreeViewQModel* m_model; + std::map m_attributes; +}; + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -131,6 +169,7 @@ private: PdmChildArrayFieldHandle* currentChildArrayFieldHandle(); void updateSelectionManager(); + void updateItemDelegateForSubTree(const QModelIndex& modelIndex = QModelIndex()); bool eventFilter(QObject *obj, QEvent *event) override; @@ -139,7 +178,8 @@ private: QVBoxLayout* m_layout; PdmUiTreeViewWidget* m_treeView; - PdmUiTreeViewQModel* m_treeViewModel; + PdmUiTreeViewQModel* m_treeViewModel; + PdmUiTreeViewItemDelegate* m_delegate; bool m_useDefaultContextMenu; bool m_updateSelectionManager; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.cpp index 44c8b1727c..518257f7c6 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.cpp @@ -396,6 +396,28 @@ void PdmUiTreeViewQModel::updateEditorsForSubTree(PdmUiTreeOrdering* root) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::list PdmUiTreeViewQModel::allIndicesRecursive(const QModelIndex& current) const +{ + std::list currentAndDescendants; + currentAndDescendants.push_back(current); + + int rows = rowCount(current); + int cols = columnCount(current); + for (int row = 0; row < rows; ++row) + { + for (int col = 0; col < cols; ++col) + { + QModelIndex childIndex = index(row, col, current); + std::list subList = allIndicesRecursive(childIndex); + currentAndDescendants.insert(currentAndDescendants.end(), subList.begin(), subList.end()); + } + } + return currentAndDescendants; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.h index 94b19dd49b..2c9f0e837b 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewQModel.h @@ -75,6 +75,8 @@ public: void setDragDropInterface(PdmUiDragDropInterface* dragDropInterface); PdmUiDragDropInterface* dragDropInterface(); + + std::list allIndicesRecursive(const QModelIndex& current = QModelIndex()) const; private: void updateSubTreeRecursive(const QModelIndex& uiSubTreeRootModelIdx, PdmUiTreeOrdering* uiModelSubTreeRoot, PdmUiTreeOrdering* updatedPdmSubTreeRoot);