File indexing completed on 2025-01-05 03:59:31
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 "PluginInterface.h" 0010 #include "RenderPlugin.h" 0011 0012 namespace Marble 0013 { 0014 0015 class Q_DECL_HIDDEN RenderPluginModel::Private 0016 { 0017 public: 0018 0019 Private(); 0020 0021 static bool renderPluginGuiStringLessThan(RenderPlugin* one, RenderPlugin* two) 0022 { 0023 // Sort by gui string ignoring keyboard accelerators 0024 0025 return one->guiString().remove(QLatin1Char('&')) < two->guiString().remove(QLatin1Char('&')); 0026 } 0027 0028 QList<RenderPlugin*> m_renderPlugins; 0029 }; 0030 0031 RenderPluginModel::Private::Private() 0032 : m_renderPlugins() 0033 { 0034 } 0035 0036 RenderPluginModel::RenderPluginModel(QObject* parent) 0037 : QStandardItemModel(parent), 0038 d (new Private) 0039 { 0040 } 0041 0042 RenderPluginModel::~RenderPluginModel() 0043 { 0044 // our model doesn't own the items, so take them away 0045 0046 while (invisibleRootItem()->hasChildren()) 0047 { 0048 invisibleRootItem()->takeRow(0); 0049 } 0050 0051 delete d; 0052 } 0053 0054 void RenderPluginModel::setRenderPlugins(const QList<RenderPlugin*> &renderPlugins) 0055 { 0056 // our model doesn't own the items, so take them away 0057 0058 while (invisibleRootItem()->hasChildren()) 0059 { 0060 invisibleRootItem()->takeRow(0); 0061 } 0062 0063 d->m_renderPlugins = renderPlugins; 0064 std::sort(d->m_renderPlugins.begin(), d->m_renderPlugins.end(), Private::renderPluginGuiStringLessThan); 0065 0066 QStandardItem* parentItem = invisibleRootItem(); 0067 0068 for (RenderPlugin* plugin : d->m_renderPlugins) 0069 { 0070 parentItem->appendRow(plugin->item()); 0071 } 0072 } 0073 0074 QVector<PluginAuthor> RenderPluginModel::pluginAuthors( const QModelIndex &index ) const 0075 { 0076 if (!index.isValid()) 0077 return QVector<PluginAuthor>(); 0078 0079 if ((index.row() < 0) || (index.row() >= d->m_renderPlugins.count())) 0080 return QVector<PluginAuthor>(); 0081 0082 return d->m_renderPlugins.at(index.row())->pluginAuthors(); 0083 } 0084 0085 RenderPlugin* RenderPluginModel::plugin(const QModelIndex& index) 0086 { 0087 if (!index.isValid()) 0088 return nullptr; 0089 0090 if ((index.row() < 0) || (index.row() >= d->m_renderPlugins.count())) 0091 return nullptr; 0092 0093 RenderPlugin* const plugin = d->m_renderPlugins.at(index.row()); 0094 0095 return plugin; 0096 } 0097 0098 DialogConfigurationInterface* RenderPluginModel::pluginDialogConfigurationInterface(const QModelIndex& index) 0099 { 0100 return qobject_cast<DialogConfigurationInterface*>(plugin(index)); 0101 } 0102 0103 PluginInterface* RenderPluginModel::pluginIface(const QModelIndex& index) 0104 { 0105 return dynamic_cast<PluginInterface*>(plugin(index)); 0106 } 0107 0108 void RenderPluginModel::retrievePluginState() 0109 { 0110 for (RenderPlugin* plugin : d->m_renderPlugins) 0111 { 0112 plugin->retrieveItemState(); 0113 } 0114 } 0115 0116 void RenderPluginModel::applyPluginState() 0117 { 0118 for (RenderPlugin* plugin : d->m_renderPlugins) 0119 { 0120 plugin->applyItemState(); 0121 } 0122 } 0123 0124 } 0125 0126 #include "moc_RenderPluginModel.cpp"