Allow deleting of the last sub plot and have nice visible drop targets

This commit is contained in:
Gaute Lindkvist
2019-10-29 08:53:14 +01:00
parent 089ca3d39d
commit 38e0b150ac
15 changed files with 350 additions and 119 deletions

View File

@@ -27,6 +27,7 @@
#include "RimGridPlotWindow.h" #include "RimGridPlotWindow.h"
#include "RimPlotInterface.h" #include "RimPlotInterface.h"
#include "RimWellLogTrack.h"
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
@@ -46,13 +47,18 @@ bool RicDeleteSubPlotFeature::isCommandEnabled()
if ( selection.size() > 0 ) if ( selection.size() > 0 )
{ {
RimGridPlotWindow* wellLogPlot = nullptr; size_t plotsSelected = 0;
selection[0]->firstAncestorOrThisOfType( wellLogPlot ); for ( caf::PdmObject* object : selection )
if ( dynamic_cast<RimPlotInterface*>( selection[0] ) && wellLogPlot && wellLogPlot->plotCount() > 1 )
{ {
return true; RimGridPlotWindow* gridPlotWindow = nullptr;
object->firstAncestorOrThisOfType( gridPlotWindow );
if ( dynamic_cast<RimPlotInterface*>( object ) && gridPlotWindow )
{
plotsSelected++;
} }
} }
return plotsSelected == selection.size();
}
return false; return false;
} }
@@ -66,7 +72,6 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked )
std::vector<caf::PdmObject*> selection; std::vector<caf::PdmObject*> selection;
caf::SelectionManager::instance()->objectsByType( &selection ); caf::SelectionManager::instance()->objectsByType( &selection );
RiuPlotMainWindow* plotWindow = RiaGuiApplication::instance()->getOrCreateMainPlotWindow();
std::set<RimGridPlotWindow*> alteredWellLogPlots; std::set<RimGridPlotWindow*> alteredWellLogPlots;
for ( size_t i = 0; i < selection.size(); i++ ) for ( size_t i = 0; i < selection.size(); i++ )
@@ -75,7 +80,7 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked )
RimGridPlotWindow* wellLogPlot = nullptr; RimGridPlotWindow* wellLogPlot = nullptr;
selection[i]->firstAncestorOrThisOfType( wellLogPlot ); selection[i]->firstAncestorOrThisOfType( wellLogPlot );
if ( plot && wellLogPlot && wellLogPlot->plotCount() > 1 ) if ( plot && wellLogPlot )
{ {
alteredWellLogPlots.insert( wellLogPlot ); alteredWellLogPlots.insert( wellLogPlot );
wellLogPlot->removePlot( plot ); wellLogPlot->removePlot( plot );
@@ -88,11 +93,6 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked )
for ( RimGridPlotWindow* wellLogPlot : alteredWellLogPlots ) for ( RimGridPlotWindow* wellLogPlot : alteredWellLogPlots )
{ {
RiuGridPlotWindow* viewWidget = dynamic_cast<RiuGridPlotWindow*>( wellLogPlot->viewWidget() );
plotWindow->setWidthOfMdiWindow( viewWidget, viewWidget->preferredWidth() );
// TODO: add back with virtual methods
// wellLogPlot->calculateAvailableDepthRange();
// wellLogPlot->updateDepthZoom();
wellLogPlot->uiCapability()->updateConnectedEditors(); wellLogPlot->uiCapability()->updateConnectedEditors();
} }
} }
@@ -102,7 +102,32 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicDeleteSubPlotFeature::setupActionLook( QAction* actionToSetup ) void RicDeleteSubPlotFeature::setupActionLook( QAction* actionToSetup )
{ {
actionToSetup->setText( "Delete Track" ); QString actionText;
std::vector<caf::PdmObject*> selection;
caf::SelectionManager::instance()->objectsByType( &selection );
size_t tracksSelected = 0u;
for ( caf::PdmObject* object : selection )
{
if ( dynamic_cast<RimWellLogTrack*>( object ) )
{
tracksSelected++;
}
}
if ( tracksSelected == selection.size() )
{
actionText = "Delete Track";
}
else
{
actionText = "Delete Plot";
}
if ( selection.size() > 1u )
{
actionText += "s";
}
actionToSetup->setText( actionText );
actionToSetup->setIcon( QIcon( ":/Erase.png" ) ); actionToSetup->setIcon( QIcon( ":/Erase.png" ) );
applyShortcutWithHintToAction( actionToSetup, QKeySequence::Delete ); applyShortcutWithHintToAction( actionToSetup, QKeySequence::Delete );
} }

View File

@@ -64,11 +64,8 @@ void RicNewWellLogPlotTrackFeature::onActionTriggered( bool isChecked )
RimWellLogTrack* plotTrack = new RimWellLogTrack; RimWellLogTrack* plotTrack = new RimWellLogTrack;
wellLogPlot->addPlot( plotTrack ); wellLogPlot->addPlot( plotTrack );
plotTrack->setDescription( QString( "Track %1" ).arg( wellLogPlot->plotCount() ) ); plotTrack->setDescription( QString( "Track %1" ).arg( wellLogPlot->plotCount() ) );
RiuPlotMainWindow* plotWindow = RiaGuiApplication::instance()->getOrCreateMainPlotWindow();
RiuWellLogPlot* viewWidget = dynamic_cast<RiuWellLogPlot*>( wellLogPlot->viewWidget() );
RicWellLogTools::addWellLogExtractionCurve( plotTrack, nullptr, nullptr, nullptr, nullptr, -1, true ); RicWellLogTools::addWellLogExtractionCurve( plotTrack, nullptr, nullptr, nullptr, nullptr, -1, true );
plotWindow->setWidthOfMdiWindow( viewWidget, viewWidget->preferredWidth() );
wellLogPlot->updateConnectedEditors(); wellLogPlot->updateConnectedEditors();
wellLogPlot->loadDataAndUpdate(); wellLogPlot->loadDataAndUpdate();
} }

View File

@@ -137,6 +137,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisProperties.h
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.h ${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.h
${CMAKE_CURRENT_LIST_DIR}/RimObservedDataCollection.h ${CMAKE_CURRENT_LIST_DIR}/RimObservedDataCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimObservedFmuRftData.h ${CMAKE_CURRENT_LIST_DIR}/RimObservedFmuRftData.h
${CMAKE_CURRENT_LIST_DIR}/RimGridPlotWindowCollection.h
) )
@@ -278,6 +279,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisProperties.cpp
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.cpp ${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.cpp
${CMAKE_CURRENT_LIST_DIR}/RimObservedDataCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimObservedDataCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimObservedFmuRftData.cpp ${CMAKE_CURRENT_LIST_DIR}/RimObservedFmuRftData.cpp
${CMAKE_CURRENT_LIST_DIR}/RimGridPlotWindowCollection.cpp
) )
list(APPEND CODE_HEADER_FILES list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,76 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimGridPlotWindowCollection.h"
#include "RiaApplication.h"
#include "RimGridPlotWindow.h"
#include "RimProject.h"
CAF_PDM_SOURCE_INIT( RimGridPlotWindowCollection, "RimGridPlotWindowCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridPlotWindowCollection::RimGridPlotWindowCollection()
{
CAF_PDM_InitObject( "Combination Plots", ":/WellFlowPlot16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_gridPlotWindows, "GridPlotWindows", "Combination Plots", "", "", "" );
m_gridPlotWindows.uiCapability()->setUiHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridPlotWindowCollection::~RimGridPlotWindowCollection() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridPlotWindowCollection::deleteAllChildObjects()
{
m_gridPlotWindows.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimGridPlotWindow*> RimGridPlotWindowCollection::gridPlotWindows() const
{
return m_gridPlotWindows.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridPlotWindow* RimGridPlotWindowCollection::createGridPlotWindow()
{
RimGridPlotWindow* plot = new RimGridPlotWindow();
plot->setAsPlotMdiWindow();
addGridPlotWindow( plot );
return plot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridPlotWindowCollection::addGridPlotWindow( RimGridPlotWindow* plot )
{
m_gridPlotWindows().push_back( plot );
}

View File

@@ -0,0 +1,45 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmChildArrayField.h"
#include "cafPdmObject.h"
class RimGridPlotWindow;
//==================================================================================================
///
///
//==================================================================================================
class RimGridPlotWindowCollection : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimGridPlotWindowCollection();
~RimGridPlotWindowCollection() override;
void deleteAllChildObjects();
std::vector<RimGridPlotWindow*> gridPlotWindows() const;
RimGridPlotWindow* createGridPlotWindow();
void addGridPlotWindow( RimGridPlotWindow* plot );
private:
caf::PdmChildArrayField<RimGridPlotWindow*> m_gridPlotWindows;
};

View File

@@ -23,6 +23,7 @@
#include "RimFlowPlotCollection.h" #include "RimFlowPlotCollection.h"
#include "RimGridCrossPlot.h" #include "RimGridCrossPlot.h"
#include "RimGridCrossPlotCollection.h" #include "RimGridCrossPlotCollection.h"
#include "RimGridPlotWindowCollection.h"
#include "RimPltPlotCollection.h" #include "RimPltPlotCollection.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimRftPlotCollection.h" #include "RimRftPlotCollection.h"
@@ -84,6 +85,9 @@ RimMainPlotCollection::RimMainPlotCollection()
"" ); "" );
m_saturationPressurePlotCollection.uiCapability()->setUiHidden( true ); m_saturationPressurePlotCollection.uiCapability()->setUiHidden( true );
CAF_PDM_InitFieldNoDefault( &m_combinationPlotCollection, "RimGridPlotWindowCollection", "Combination Plots", "", "", "" );
m_combinationPlotCollection.uiCapability()->setUiHidden( true );
m_wellLogPlotCollection = new RimWellLogPlotCollection(); m_wellLogPlotCollection = new RimWellLogPlotCollection();
m_rftPlotCollection = new RimRftPlotCollection(); m_rftPlotCollection = new RimRftPlotCollection();
m_pltPlotCollection = new RimPltPlotCollection(); m_pltPlotCollection = new RimPltPlotCollection();
@@ -180,6 +184,14 @@ RimSaturationPressurePlotCollection* RimMainPlotCollection::saturationPressurePl
return m_saturationPressurePlotCollection(); return m_saturationPressurePlotCollection();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridPlotWindowCollection* RimMainPlotCollection::combinationPlotCollection()
{
return m_combinationPlotCollection();
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -193,6 +205,7 @@ void RimMainPlotCollection::deleteAllContainedObjects()
m_gridCrossPlotCollection->deleteAllChildObjects(); m_gridCrossPlotCollection->deleteAllChildObjects();
m_flowPlotCollection()->closeDefaultPlotWindowAndDeletePlots(); m_flowPlotCollection()->closeDefaultPlotWindowAndDeletePlots();
m_saturationPressurePlotCollection()->deleteAllChildObjects(); m_saturationPressurePlotCollection()->deleteAllChildObjects();
m_combinationPlotCollection()->deleteAllChildObjects();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -244,6 +257,14 @@ void RimMainPlotCollection::updatePlotsWithFormations()
crossPlot->loadDataAndUpdate(); crossPlot->loadDataAndUpdate();
} }
} }
if ( m_combinationPlotCollection )
{
for ( RimGridPlotWindow* plotWindow : m_combinationPlotCollection->gridPlotWindows() )
{
plotWindow->loadDataAndUpdate();
}
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -258,6 +279,14 @@ void RimMainPlotCollection::updatePlotsWithCompletions()
wellLogPlot->loadDataAndUpdate(); wellLogPlot->loadDataAndUpdate();
} }
} }
if ( m_combinationPlotCollection )
{
for ( RimGridPlotWindow* plotWindow : m_combinationPlotCollection->gridPlotWindows() )
{
plotWindow->loadDataAndUpdate();
}
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -30,6 +30,7 @@ class RimWellLogPlotCollection;
class RimRftPlotCollection; class RimRftPlotCollection;
class RimPltPlotCollection; class RimPltPlotCollection;
class RimGridCrossPlotCollection; class RimGridCrossPlotCollection;
class RimGridPlotWindowCollection;
class RimSummaryPlotCollection; class RimSummaryPlotCollection;
class RimSummaryCrossPlotCollection; class RimSummaryCrossPlotCollection;
class RimSummaryPlot; class RimSummaryPlot;
@@ -58,6 +59,7 @@ public:
RimFlowPlotCollection* flowPlotCollection(); RimFlowPlotCollection* flowPlotCollection();
RimGridCrossPlotCollection* gridCrossPlotCollection(); RimGridCrossPlotCollection* gridCrossPlotCollection();
RimSaturationPressurePlotCollection* saturationPressurePlotCollection(); RimSaturationPressurePlotCollection* saturationPressurePlotCollection();
RimGridPlotWindowCollection* combinationPlotCollection();
void deleteAllContainedObjects(); void deleteAllContainedObjects();
void updateCurrentTimeStepInPlots(); void updateCurrentTimeStepInPlots();
@@ -81,6 +83,7 @@ private:
caf::PdmChildField<RimFlowPlotCollection*> m_flowPlotCollection; caf::PdmChildField<RimFlowPlotCollection*> m_flowPlotCollection;
caf::PdmChildField<RimGridCrossPlotCollection*> m_gridCrossPlotCollection; caf::PdmChildField<RimGridCrossPlotCollection*> m_gridCrossPlotCollection;
caf::PdmChildField<RimSaturationPressurePlotCollection*> m_saturationPressurePlotCollection; caf::PdmChildField<RimSaturationPressurePlotCollection*> m_saturationPressurePlotCollection;
caf::PdmChildField<RimGridPlotWindowCollection*> m_combinationPlotCollection;
caf::PdmField<bool> m_show; caf::PdmField<bool> m_show;
}; };

View File

@@ -50,6 +50,7 @@
#include "RimGeoMechCase.h" #include "RimGeoMechCase.h"
#include "RimGeoMechModels.h" #include "RimGeoMechModels.h"
#include "RimGridCrossPlotCollection.h" #include "RimGridCrossPlotCollection.h"
#include "RimGridPlotWindowCollection.h"
#include "RimGridSummaryCase.h" #include "RimGridSummaryCase.h"
#include "RimGridView.h" #include "RimGridView.h"
#include "RimIdenticalGridCaseGroup.h" #include "RimIdenticalGridCaseGroup.h"
@@ -1303,6 +1304,10 @@ void RimProject::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, Q
{ {
itemCollection->add( mainPlotCollection->saturationPressurePlotCollection() ); itemCollection->add( mainPlotCollection->saturationPressurePlotCollection() );
} }
if ( mainPlotCollection->combinationPlotCollection() )
{
itemCollection->add( mainPlotCollection->combinationPlotCollection() );
}
} }
uiTreeOrdering.add( m_plotTemplateFolderItem() ); uiTreeOrdering.add( m_plotTemplateFolderItem() );

View File

@@ -34,6 +34,7 @@
#include "RimFlowPlotCollection.h" #include "RimFlowPlotCollection.h"
#include "RimGridCrossPlot.h" #include "RimGridCrossPlot.h"
#include "RimGridCrossPlotCollection.h" #include "RimGridCrossPlotCollection.h"
#include "RimGridPlotWindowCollection.h"
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimSummaryCaseMainCollection.h" #include "RimSummaryCaseMainCollection.h"
@@ -176,5 +177,14 @@ void RimReloadCaseTools::updateAllPlots()
{ {
flowPlotCollection->loadDataAndUpdate(); flowPlotCollection->loadDataAndUpdate();
} }
RimGridPlotWindowCollection* gridPlotWindowCollection = project->mainPlotCollection()->combinationPlotCollection();
if ( gridPlotWindowCollection )
{
for ( RimGridPlotWindow* plotWindow : gridPlotWindowCollection->gridPlotWindows() )
{
plotWindow->loadDataAndUpdate();
}
}
} }
} }

View File

@@ -78,8 +78,8 @@ RiuGridPlotWindow::RiuGridPlotWindow( RimGridPlotWindow* plotDefinition, QWidget
m_plotLayout->addWidget( m_plotWidgetFrame, 1 ); m_plotLayout->addWidget( m_plotWidgetFrame, 1 );
m_gridLayout = new QGridLayout( m_plotWidgetFrame ); m_gridLayout = new QGridLayout( m_plotWidgetFrame );
m_gridLayout->setMargin( 0 ); m_gridLayout->setContentsMargins( 1, 1, 1, 1 );
m_gridLayout->setSpacing( 2 ); m_gridLayout->setSpacing( 1 );
QPalette newPalette( palette() ); QPalette newPalette( palette() );
newPalette.setColor( QPalette::Background, Qt::white ); newPalette.setColor( QPalette::Background, Qt::white );
@@ -96,6 +96,13 @@ RiuGridPlotWindow::RiuGridPlotWindow( RimGridPlotWindow* plotDefinition, QWidget
new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition ); new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition );
m_dropTargetPlaceHolder = new QLabel( "Drag plots here" );
m_dropTargetPlaceHolder->setAlignment( Qt::AlignCenter );
m_dropTargetPlaceHolder->setObjectName(
QString( "%1" ).arg( reinterpret_cast<uint64_t>( m_dropTargetPlaceHolder.data() ) ) );
m_dropTargetStyleSheet = createDropTargetStyleSheet();
m_dropTargetStyleSheet.applyToWidget( m_dropTargetPlaceHolder );
this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding ); this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
@@ -105,6 +112,8 @@ RiuGridPlotWindow::RiuGridPlotWindow( RimGridPlotWindow* plotDefinition, QWidget
RiaApplication* app = RiaApplication::instance(); RiaApplication* app = RiaApplication::instance();
int defaultFontSize = RiaFontCache::pointSizeFromFontSizeEnum( app->preferences()->defaultPlotFontSize() ); int defaultFontSize = RiaFontCache::pointSizeFromFontSizeEnum( app->preferences()->defaultPlotFontSize() );
setFontSize( defaultFontSize ); setFontSize( defaultFontSize );
this->setObjectName( QString( "%1" ).arg( reinterpret_cast<uint64_t>( this ) ) );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -202,28 +211,6 @@ void RiuGridPlotWindow::setPlotTitle( const QString& plotTitle )
m_plotTitle->setText( plotTitle ); m_plotTitle->setText( plotTitle );
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiuGridPlotWindow::preferredWidth() const
{
int titleWidth = 0;
if ( m_plotTitle && m_plotTitle->isVisible() )
{
titleWidth = m_plotTitle->width();
}
QList<QPointer<RiuQwtPlotWidget>> visiblePlotWidgets = this->visiblePlotWidgets();
auto rowAndColumnCount = this->rowAndColumnCount( visiblePlotWidgets.size() );
int sumColumnWidths = 0;
for ( int visibleIndex = 0; visibleIndex < rowAndColumnCount.second; ++visibleIndex )
{
sumColumnWidths += visiblePlotWidgets[visibleIndex]->width();
}
return std::max( titleWidth, sumColumnWidths );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -390,8 +377,10 @@ void RiuGridPlotWindow::showEvent( QShowEvent* event )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuGridPlotWindow::dragEnterEvent( QDragEnterEvent* event ) void RiuGridPlotWindow::dragEnterEvent( QDragEnterEvent* event )
{ {
if ( this->geometry().contains( event->pos() ) ) RiuQwtPlotWidget* source = dynamic_cast<RiuQwtPlotWidget*>( event->source() );
if ( source )
{ {
setWidgetState( RiuWidgetStyleSheet::DRAG_TARGET_INTO );
event->acceptProposedAction(); event->acceptProposedAction();
} }
} }
@@ -401,11 +390,13 @@ void RiuGridPlotWindow::dragEnterEvent( QDragEnterEvent* event )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuGridPlotWindow::dragMoveEvent( QDragMoveEvent* event ) void RiuGridPlotWindow::dragMoveEvent( QDragMoveEvent* event )
{ {
if ( this->geometry().contains( event->pos() ) ) if ( event->answerRect().intersects( this->geometry() ) )
{ {
RiuQwtPlotWidget* source = dynamic_cast<RiuQwtPlotWidget*>( event->source() ); RiuQwtPlotWidget* source = dynamic_cast<RiuQwtPlotWidget*>( event->source() );
if ( source ) if ( source )
{ {
setWidgetState( RiuWidgetStyleSheet::DRAG_TARGET_INTO );
QRect originalGeometry = source->geometry(); QRect originalGeometry = source->geometry();
QPoint offset = source->dragStartPosition(); QPoint offset = source->dragStartPosition();
QRect newRect( event->pos() - offset, originalGeometry.size() ); QRect newRect( event->pos() - offset, originalGeometry.size() );
@@ -431,9 +422,8 @@ void RiuGridPlotWindow::dragMoveEvent( QDragMoveEvent* event )
{ {
int insertAfterIndex = insertBeforeIndex - 1; int insertAfterIndex = insertBeforeIndex - 1;
visiblePlotWidgets[insertAfterIndex]->setWidgetState( RiuWidgetStyleSheet::DRAG_TARGET_AFTER ); visiblePlotWidgets[insertAfterIndex]->setWidgetState( RiuWidgetStyleSheet::DRAG_TARGET_AFTER );
event->acceptProposedAction();
} }
event->acceptProposedAction();
} }
} }
} }
@@ -443,6 +433,8 @@ void RiuGridPlotWindow::dragMoveEvent( QDragMoveEvent* event )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuGridPlotWindow::dragLeaveEvent( QDragLeaveEvent* event ) void RiuGridPlotWindow::dragLeaveEvent( QDragLeaveEvent* event )
{ {
setWidgetState( RiuWidgetStyleSheet::DEFAULT );
for ( int tIdx = 0; tIdx < m_plotWidgets.size(); ++tIdx ) for ( int tIdx = 0; tIdx < m_plotWidgets.size(); ++tIdx )
{ {
m_plotWidgets[tIdx]->setWidgetState( RiuWidgetStyleSheet::DEFAULT ); m_plotWidgets[tIdx]->setWidgetState( RiuWidgetStyleSheet::DEFAULT );
@@ -454,6 +446,8 @@ void RiuGridPlotWindow::dragLeaveEvent( QDragLeaveEvent* event )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuGridPlotWindow::dropEvent( QDropEvent* event ) void RiuGridPlotWindow::dropEvent( QDropEvent* event )
{ {
setWidgetState( RiuWidgetStyleSheet::DEFAULT );
for ( int tIdx = 0; tIdx < m_plotWidgets.size(); ++tIdx ) for ( int tIdx = 0; tIdx < m_plotWidgets.size(); ++tIdx )
{ {
m_plotWidgets[tIdx]->setWidgetState( RiuWidgetStyleSheet::DEFAULT ); m_plotWidgets[tIdx]->setWidgetState( RiuWidgetStyleSheet::DEFAULT );
@@ -533,6 +527,14 @@ void RiuGridPlotWindow::onSelectionManagerSelectionChanged( const std::set<int>&
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridPlotWindow::setWidgetState( RiuWidgetStyleSheet::StateTag widgetState )
{
m_dropTargetStyleSheet.setWidgetState( m_dropTargetPlaceHolder, widgetState );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -589,6 +591,16 @@ void RiuGridPlotWindow::reinsertPlotWidgetsAndScrollbar()
QList<QPointer<RiuQwtPlotWidget>> plotWidgets = this->visiblePlotWidgets(); QList<QPointer<RiuQwtPlotWidget>> plotWidgets = this->visiblePlotWidgets();
QList<QPointer<RiuQwtPlotLegend>> legends = this->visibleLegends(); QList<QPointer<RiuQwtPlotLegend>> legends = this->visibleLegends();
if ( plotWidgets.empty() )
{
m_gridLayout->addWidget( m_dropTargetPlaceHolder, 0, 0 );
m_dropTargetPlaceHolder->setVisible( true );
m_scrollBar->setVisible( false );
}
else
{
m_dropTargetPlaceHolder->setVisible( false );
auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() ); auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() );
for ( int visibleIndex = 0; visibleIndex < plotWidgets.size(); ++visibleIndex ) for ( int visibleIndex = 0; visibleIndex < plotWidgets.size(); ++visibleIndex )
@@ -636,7 +648,8 @@ void RiuGridPlotWindow::reinsertPlotWidgetsAndScrollbar()
} }
m_gridLayout->addLayout( m_scrollBarLayout, 1, rowAndColumnCount.second, rowAndColumnCount.first * 2 - 1, 1 ); m_gridLayout->addLayout( m_scrollBarLayout, 1, rowAndColumnCount.second, rowAndColumnCount.first * 2 - 1, 1 );
m_gridLayout->setColumnStretch( rowAndColumnCount.second, 0 ); m_gridLayout->setColumnStretch( rowAndColumnCount.second, 0 );
m_scrollBar->setVisible( plotWidgets.size() > 0 ); m_scrollBar->setVisible( true );
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -662,6 +675,22 @@ void RiuGridPlotWindow::clearGridLayout()
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWidgetStyleSheet RiuGridPlotWindow::createDropTargetStyleSheet()
{
RiuWidgetStyleSheet styleSheet;
styleSheet.set( "background-color", "white" );
styleSheet.set( "border", "1px solid black" );
styleSheet.set( "font-size", "14pt" );
styleSheet.state( RiuWidgetStyleSheet::DRAG_TARGET_INTO ).set( "border", "1px solid lime" );
styleSheet.state( RiuWidgetStyleSheet::DRAG_TARGET_INTO ).set( "background-color", "#DDFFDD" );
return styleSheet;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -20,6 +20,7 @@
#pragma once #pragma once
#include "RiuInterfaceToViewWindow.h" #include "RiuInterfaceToViewWindow.h"
#include "RiuWidgetStyleSheet.h"
#include "cafPdmPointer.h" #include "cafPdmPointer.h"
#include "cafSelectionChangedReceiver.h" #include "cafSelectionChangedReceiver.h"
@@ -64,7 +65,6 @@ public:
void removePlot( RiuQwtPlotWidget* plotWidget ); void removePlot( RiuQwtPlotWidget* plotWidget );
void setPlotTitle( const QString& plotTitle ); void setPlotTitle( const QString& plotTitle );
int preferredWidth() const;
void setTitleVisible( bool visible ); void setTitleVisible( bool visible );
void setScrollbarVisible( bool visible ); void setScrollbarVisible( bool visible );
@@ -95,6 +95,7 @@ protected:
virtual void onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels ) override; virtual void onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels ) override;
void setWidgetState( RiuWidgetStyleSheet::StateTag widgetState );
private slots: private slots:
void performUpdate(); void performUpdate();
@@ -102,6 +103,7 @@ private:
void alignCanvasTopsAndScrollbar(); void alignCanvasTopsAndScrollbar();
void reinsertPlotWidgetsAndScrollbar(); void reinsertPlotWidgetsAndScrollbar();
void clearGridLayout(); void clearGridLayout();
RiuWidgetStyleSheet createDropTargetStyleSheet();
QList<QPointer<RiuQwtPlotWidget>> visiblePlotWidgets() const; QList<QPointer<RiuQwtPlotWidget>> visiblePlotWidgets() const;
QList<QPointer<RiuQwtPlotLegend>> visibleLegends() const; QList<QPointer<RiuQwtPlotLegend>> visibleLegends() const;
@@ -118,6 +120,9 @@ protected:
QList<int> m_legendColumns; QList<int> m_legendColumns;
QList<QPointer<RiuQwtPlotWidget>> m_plotWidgets; QList<QPointer<RiuQwtPlotWidget>> m_plotWidgets;
caf::PdmPointer<RimGridPlotWindow> m_plotDefinition; caf::PdmPointer<RimGridPlotWindow> m_plotDefinition;
QPointer<QLabel> m_dropTargetPlaceHolder;
RiuWidgetStyleSheet m_dropTargetStyleSheet;
private: private:
friend class RiaPlotWindowRedrawScheduler; friend class RiaPlotWindowRedrawScheduler;

View File

@@ -630,17 +630,9 @@ void RiuPlotMainWindow::addViewer( QWidget* viewer, const RimMdiWindowGeometry&
subWindowSize = QSize( windowsGeometry.width, windowsGeometry.height ); subWindowSize = QSize( windowsGeometry.width, windowsGeometry.height );
} }
else else
{
RiuGridPlotWindow* wellLogPlot = dynamic_cast<RiuGridPlotWindow*>( viewer );
if ( wellLogPlot )
{
subWindowSize = QSize( wellLogPlot->preferredWidth(), m_mdiArea->height() );
}
else
{ {
subWindowSize = QSize( 400, 400 ); subWindowSize = QSize( 400, 400 );
} }
}
addViewerToMdiArea( m_mdiArea, viewer, subWindowPos, subWindowSize ); addViewerToMdiArea( m_mdiArea, viewer, subWindowPos, subWindowSize );

View File

@@ -448,21 +448,7 @@ void RiuQwtPlotWidget::scheduleReplot()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setWidgetState( RiuWidgetStyleSheet::StateTag widgetState ) void RiuQwtPlotWidget::setWidgetState( RiuWidgetStyleSheet::StateTag widgetState )
{ {
// Set all existing dynamic properties to false m_plotStyleSheet.setWidgetState( this, widgetState );
for ( QByteArray existingProperty : dynamicPropertyNames() )
{
setProperty( existingProperty, false );
}
// Set current property state to true
QString propertyName = RiuWidgetStyleSheet::propertyName( widgetState );
if ( !propertyName.isEmpty() )
{
setProperty( propertyName.toLatin1(), true );
}
// Trigger style update
m_plotStyleSheet.refreshWidget( this );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -19,6 +19,7 @@
#include "cafAssert.h" #include "cafAssert.h"
#include <QDebug>
#include <QStringList> #include <QStringList>
#include <QStyle> #include <QStyle>
#include <QWidget> #include <QWidget>
@@ -30,8 +31,9 @@ void RiuWidgetStyleSheet::StateTagEnum::setUp()
{ {
addItem( RiuWidgetStyleSheet::DEFAULT, "", "" ); addItem( RiuWidgetStyleSheet::DEFAULT, "", "" );
addItem( RiuWidgetStyleSheet::SELECTED, "selected", "selected" ); addItem( RiuWidgetStyleSheet::SELECTED, "selected", "selected" );
addItem( RiuWidgetStyleSheet::DRAG_TARGET_BEFORE, "dragTargetBefore", "drop Before" ); addItem( RiuWidgetStyleSheet::DRAG_TARGET_BEFORE, "dragTargetBefore", "drop before" );
addItem( RiuWidgetStyleSheet::DRAG_TARGET_AFTER, "dragTargetAfter", "drop After" ); addItem( RiuWidgetStyleSheet::DRAG_TARGET_AFTER, "dragTargetAfter", "drop after" );
addItem( RiuWidgetStyleSheet::DRAG_TARGET_INTO, "dragTargetInto", "drop into" );
addItem( RiuWidgetStyleSheet::HOVER, "hover", "hover" ); addItem( RiuWidgetStyleSheet::HOVER, "hover", "hover" );
setDefault( RiuWidgetStyleSheet::DEFAULT ); setDefault( RiuWidgetStyleSheet::DEFAULT );
} }
@@ -136,6 +138,7 @@ QString RiuWidgetStyleSheet::propertyName( StateTag state )
void RiuWidgetStyleSheet::applyToWidget( QWidget* widget ) const void RiuWidgetStyleSheet::applyToWidget( QWidget* widget ) const
{ {
QString completeStyleSheet = fullText( QString( widget->metaObject()->className() ), widget->objectName() ); QString completeStyleSheet = fullText( QString( widget->metaObject()->className() ), widget->objectName() );
// qDebug().noquote() << completeStyleSheet;
widget->setStyleSheet( completeStyleSheet ); widget->setStyleSheet( completeStyleSheet );
refreshWidget( widget ); refreshWidget( widget );
} }
@@ -149,6 +152,28 @@ void RiuWidgetStyleSheet::refreshWidget( QWidget* widget ) const
widget->style()->polish( widget ); widget->style()->polish( widget );
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWidgetStyleSheet::setWidgetState( QWidget* widget, StateTag widgetState ) const
{
// Set all existing dynamic properties to false
for ( QByteArray existingProperty : widget->dynamicPropertyNames() )
{
widget->setProperty( existingProperty, false );
}
// Set current property state to true
QString propertyName = RiuWidgetStyleSheet::propertyName( widgetState );
if ( !propertyName.isEmpty() )
{
widget->setProperty( propertyName.toLatin1(), true );
}
// Trigger style update
this->refreshWidget( widget );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -41,6 +41,7 @@ public:
SELECTED = 0x0001, SELECTED = 0x0001,
DRAG_TARGET_BEFORE = 0x0002, DRAG_TARGET_BEFORE = 0x0002,
DRAG_TARGET_AFTER = 0x0004, DRAG_TARGET_AFTER = 0x0004,
DRAG_TARGET_INTO = 0x0008,
// Pseudo States: // Pseudo States:
PSEUDO_STATE_LIMIT = 0x1000, PSEUDO_STATE_LIMIT = 0x1000,
HOVER = 0x1000 HOVER = 0x1000
@@ -72,6 +73,7 @@ public:
void applyToWidget( QWidget* widget ) const; void applyToWidget( QWidget* widget ) const;
void refreshWidget( QWidget* widget ) const; void refreshWidget( QWidget* widget ) const;
void setWidgetState( QWidget* widget, StateTag widgetState ) const;
private: private:
friend class RiuWidgetStyleSheetManager; friend class RiuWidgetStyleSheetManager;