mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user