Plot Template updates (#9002)

* Ensemble plot templates now have .erpt extension and new icon
* Default plot templates are given a checkmark overlay on the icon
* Context menu has been cleaned up a bit
* Old default template is really just the last used template. Rename it.
* Add max. recursive depth setting in preferences for plot template searches
* Only create plots based on correct template type when importing ensembles or single cases
* Support creating new plot from template explorer
* Update last used template when creating a new plot from a template
This commit is contained in:
jonjenssen
2022-06-01 10:45:44 +02:00
committed by GitHub
parent 92afb11a76
commit 9f4d242a5d
24 changed files with 532 additions and 71 deletions

View File

@@ -20,6 +20,7 @@
#include "RiaFieldHandleTools.h"
#include "RiaLogging.h"
#include "RiaPreferencesSummary.h"
#include "cafPdmField.h"
#include "cafPdmUiFilePathEditor.h"
@@ -55,6 +56,9 @@ void RimPlotTemplateFileItem::setFilePath( const QString& filePath )
this->uiCapability()->setUiName( fi.baseName() );
m_absoluteFileName = filePath;
if ( isEnsembleTemplate() )
this->uiCapability()->setUiIcon( caf::IconProvider( ":/SummaryEnsembleTemplate16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
@@ -64,3 +68,39 @@ QString RimPlotTemplateFileItem::absoluteFilePath() const
{
return m_absoluteFileName();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotTemplateFileItem::isEnsembleTemplate() const
{
return m_absoluteFileName().toLower().endsWith( ".erpt" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFileItem::updateIconState()
{
caf::IconProvider iconProvider = this->uiIconProvider();
if ( !iconProvider.valid() ) return;
if ( isDefaultTemplate() )
{
iconProvider.setOverlayResourceString( ":/CheckOverlay16x16.png" );
}
else
{
iconProvider.setOverlayResourceString( "" );
}
this->setUiIcon( iconProvider );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotTemplateFileItem::isDefaultTemplate() const
{
return RiaPreferencesSummary::current()->isDefaultSummaryPlotTemplate( absoluteFilePath() );
}

View File

@@ -36,6 +36,12 @@ public:
void setFilePath( const QString& filePath );
QString absoluteFilePath() const;
bool isEnsembleTemplate() const;
bool isDefaultTemplate() const;
void updateIconState();
private:
caf::PdmField<QString> m_absoluteFileName;
};

View File

@@ -38,6 +38,7 @@ RimPlotTemplateFolderItem::RimPlotTemplateFolderItem()
CAF_PDM_InitObject( "Plot Templates", ":/Folder.png" );
CAF_PDM_InitFieldNoDefault( &m_folderName, "FolderName", "Folder" );
m_folderName.uiCapability()->setUiReadOnly( true );
CAF_PDM_InitFieldNoDefault( &m_fileNames, "FileNames", "" );
m_fileNames.uiCapability()->setUiTreeHidden( true );
CAF_PDM_InitFieldNoDefault( &m_subFolders, "SubFolders", "" );
@@ -59,7 +60,24 @@ void RimPlotTemplateFolderItem::createRootFolderItemsFromFolderPaths( const QStr
m_fileNames.deleteChildren();
m_subFolders.deleteChildren();
createSubFolderItemsFromFolderPaths( folderPaths );
createSubFolderItemsFromFolderPaths( folderPaths, RiaPreferences::current()->maxPlotTemplateFoldersDepth() );
updateIconState();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::updateIconState() const
{
for ( auto& folder : m_subFolders() )
{
folder->updateIconState();
}
for ( auto& item : m_fileNames() )
{
item->updateIconState();
}
}
//--------------------------------------------------------------------------------------------------
@@ -101,16 +119,19 @@ void RimPlotTemplateFolderItem::setFolderPath( const QString& path )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
void RimPlotTemplateFolderItem::searchForFileAndFolderNames( int levelsLeft )
{
m_fileNames.deleteChildren();
m_subFolders.deleteChildren();
levelsLeft--;
if ( levelsLeft < 0 ) return;
if ( m_folderName().path().isEmpty() )
{
for ( size_t i = 0; i < m_subFolders.size(); ++i )
{
if ( m_subFolders[i] ) m_subFolders[i]->searchForFileAndFolderNames();
if ( m_subFolders[i] ) m_subFolders[i]->searchForFileAndFolderNames( levelsLeft );
}
return;
}
@@ -121,10 +142,11 @@ void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
return;
}
// Build a list of all scripts in the specified directory
// Build a list of all templates in the specified directory
{
QStringList nameFilters;
nameFilters << "*.rpt";
nameFilters << "*.erpt";
QStringList fileList = caf::Utils::getFilesInDirectory( m_folderName().path(), nameFilters, true );
for ( int i = 0; i < fileList.size(); i++ )
@@ -140,7 +162,7 @@ void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
}
}
if ( searchSubFoldersRecursively() )
if ( levelsLeft > 0 )
{
QStringList folderPaths;
@@ -152,23 +174,7 @@ void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
folderPaths.push_back( fi.absoluteFilePath() );
}
createSubFolderItemsFromFolderPaths( folderPaths );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
if ( &m_folderName == changedField )
{
QFileInfo fi( m_folderName().path() );
this->setUiName( fi.baseName() );
this->searchForFileAndFolderNames();
createSubFolderItemsFromFolderPaths( folderPaths, levelsLeft );
}
}
@@ -189,6 +195,19 @@ void RimPlotTemplateFolderItem::defineEditorAttribute( const caf::PdmFieldHandle
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
if ( !m_folderName().path().isEmpty() )
{
uiOrdering.add( &m_folderName );
}
uiOrdering.skipRemainingFields( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -209,11 +228,15 @@ void RimPlotTemplateFolderItem::appendOptionItemsForPlotTemplatesRecursively( QL
}
caf::IconProvider templateIcon( ":/SummaryTemplate16x16.png" );
caf::IconProvider ensTemplateIcon( ":/SummaryEnsembleTemplate16x16.png" );
auto files = templateFolderItem->fileNames();
for ( auto file : files )
{
caf::PdmOptionItemInfo optionInfo( file->uiName(), file, false, templateIcon );
caf::IconProvider icon = templateIcon;
if ( file->isEnsembleTemplate() ) icon = ensTemplateIcon;
caf::PdmOptionItemInfo optionInfo( file->uiName(), file, false, icon );
optionInfo.setLevel( menuLevel );
@@ -224,22 +247,14 @@ void RimPlotTemplateFolderItem::appendOptionItemsForPlotTemplatesRecursively( QL
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::createSubFolderItemsFromFolderPaths( const QStringList& folderPaths )
void RimPlotTemplateFolderItem::createSubFolderItemsFromFolderPaths( const QStringList& folderPaths, int levelsLeft )
{
for ( const auto& path : folderPaths )
{
RimPlotTemplateFolderItem* scriptLocation = new RimPlotTemplateFolderItem();
scriptLocation->setFolderPath( path );
scriptLocation->searchForFileAndFolderNames();
RimPlotTemplateFolderItem* templateLocation = new RimPlotTemplateFolderItem();
templateLocation->setFolderPath( path );
templateLocation->searchForFileAndFolderNames( levelsLeft );
m_subFolders.push_back( scriptLocation );
m_subFolders.push_back( templateLocation );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotTemplateFolderItem::searchSubFoldersRecursively() const
{
return RiaPreferences::current()->searchPlotTemplateFoldersRecursively();
}

View File

@@ -48,18 +48,17 @@ public:
static void appendOptionItemsForPlotTemplates( QList<caf::PdmOptionItemInfo>& options,
RimPlotTemplateFolderItem* templateFolderItem );
void updateIconState() const;
private:
void searchForFileAndFolderNames();
void searchForFileAndFolderNames( int levelsLeft );
void setFolderPath( const QString& path );
void createSubFolderItemsFromFolderPaths( const QStringList& folderPaths );
void createSubFolderItemsFromFolderPaths( const QStringList& folderPaths, int levelsLeft );
bool searchSubFoldersRecursively() const;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
static void appendOptionItemsForPlotTemplatesRecursively( QList<caf::PdmOptionItemInfo>& options,
RimPlotTemplateFolderItem* templateFolderItem,