File indexing completed on 2024-04-14 03:48:02
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 0004 // 0005 0006 #include "RenderPluginModel.h" 0007 0008 #include "DialogConfigurationInterface.h" 0009 #include "RenderPlugin.h" 0010 0011 namespace Marble 0012 { 0013 0014 class Q_DECL_HIDDEN RenderPluginModel::Private 0015 { 0016 public: 0017 Private(); 0018 0019 static bool renderPluginGuiStringLessThan( RenderPlugin* one, RenderPlugin* two ) 0020 { 0021 // Sort by gui string ignoring keyboard accelerators 0022 return one->guiString().remove( QLatin1Char( '&' ) ) < two->guiString().remove( QLatin1Char( '&' ) ); 0023 } 0024 0025 QList<RenderPlugin *> m_renderPlugins; 0026 }; 0027 0028 RenderPluginModel::Private::Private() : 0029 m_renderPlugins() 0030 { 0031 } 0032 0033 RenderPluginModel::RenderPluginModel( QObject *parent ) : 0034 QStandardItemModel( parent ), 0035 d( new Private ) 0036 { 0037 } 0038 0039 RenderPluginModel::~RenderPluginModel() 0040 { 0041 // our model doesn't own the items, so take them away 0042 while ( invisibleRootItem()->hasChildren() ) { 0043 invisibleRootItem()->takeRow( 0 ); 0044 } 0045 0046 delete d; 0047 } 0048 0049 void RenderPluginModel::setRenderPlugins( const QList<RenderPlugin *> &renderPlugins ) 0050 { 0051 // our model doesn't own the items, so take them away 0052 while ( invisibleRootItem()->hasChildren() ) { 0053 invisibleRootItem()->takeRow( 0 ); 0054 } 0055 0056 d->m_renderPlugins = renderPlugins; 0057 std::sort( d->m_renderPlugins.begin(), d->m_renderPlugins.end(), Private::renderPluginGuiStringLessThan ); 0058 0059 QStandardItem *parentItem = invisibleRootItem(); 0060 for ( RenderPlugin *plugin: d->m_renderPlugins ) { 0061 parentItem->appendRow( plugin->item() ); 0062 } 0063 } 0064 0065 QVector<PluginAuthor> RenderPluginModel::pluginAuthors( const QModelIndex &index ) const 0066 { 0067 if ( !index.isValid() ) 0068 return QVector<PluginAuthor>(); 0069 0070 if ( index.row() < 0 || index.row() >= d->m_renderPlugins.count() ) 0071 return QVector<PluginAuthor>(); 0072 0073 return d->m_renderPlugins.at( index.row() )->pluginAuthors(); 0074 } 0075 0076 DialogConfigurationInterface *RenderPluginModel::pluginDialogConfigurationInterface( const QModelIndex &index ) 0077 { 0078 if ( !index.isValid() ) 0079 return nullptr; 0080 0081 if ( index.row() < 0 || index.row() >= d->m_renderPlugins.count() ) 0082 return nullptr; 0083 0084 RenderPlugin *plugin = d->m_renderPlugins.at( index.row() ); 0085 return qobject_cast<DialogConfigurationInterface *>( plugin ); 0086 } 0087 0088 void RenderPluginModel::retrievePluginState() 0089 { 0090 for ( RenderPlugin *plugin: d->m_renderPlugins ) { 0091 plugin->retrieveItemState(); 0092 } 0093 } 0094 0095 void RenderPluginModel::applyPluginState() 0096 { 0097 for ( RenderPlugin *plugin: d->m_renderPlugins ) { 0098 plugin->applyItemState(); 0099 } 0100 } 0101 0102 } 0103 0104 #include "moc_RenderPluginModel.cpp"