Marble

RenderPluginModel.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <[email protected]>
4 //
5 
6 #include "RenderPluginModel.h"
7 
8 #include "DialogConfigurationInterface.h"
9 #include "RenderPlugin.h"
10 
11 namespace Marble
12 {
13 
14 class Q_DECL_HIDDEN RenderPluginModel::Private
15 {
16 public:
17  Private();
18 
19  static bool renderPluginGuiStringLessThan( RenderPlugin* one, RenderPlugin* two )
20  {
21  // Sort by gui string ignoring keyboard accelerators
22  return one->guiString().remove( QLatin1Char( '&' ) ) < two->guiString().remove( QLatin1Char( '&' ) );
23  }
24 
25  QList<RenderPlugin *> m_renderPlugins;
26 };
27 
28 RenderPluginModel::Private::Private() :
29  m_renderPlugins()
30 {
31 }
32 
33 RenderPluginModel::RenderPluginModel( QObject *parent ) :
34  QStandardItemModel( parent ),
35  d( new Private )
36 {
37 }
38 
39 RenderPluginModel::~RenderPluginModel()
40 {
41  // our model doesn't own the items, so take them away
42  while ( invisibleRootItem()->hasChildren() ) {
43  invisibleRootItem()->takeRow( 0 );
44  }
45 
46  delete d;
47 }
48 
50 {
51  // our model doesn't own the items, so take them away
52  while ( invisibleRootItem()->hasChildren() ) {
53  invisibleRootItem()->takeRow( 0 );
54  }
55 
56  d->m_renderPlugins = renderPlugins;
57  std::sort( d->m_renderPlugins.begin(), d->m_renderPlugins.end(), Private::renderPluginGuiStringLessThan );
58 
59  QStandardItem *parentItem = invisibleRootItem();
60  for ( RenderPlugin *plugin: d->m_renderPlugins ) {
61  parentItem->appendRow( plugin->item() );
62  }
63 }
64 
65 QVector<PluginAuthor> RenderPluginModel::pluginAuthors( const QModelIndex &index ) const
66 {
67  if ( !index.isValid() )
68  return QVector<PluginAuthor>();
69 
70  if ( index.row() < 0 || index.row() >= d->m_renderPlugins.count() )
71  return QVector<PluginAuthor>();
72 
73  return d->m_renderPlugins.at( index.row() )->pluginAuthors();
74 }
75 
76 DialogConfigurationInterface *RenderPluginModel::pluginDialogConfigurationInterface( const QModelIndex &index )
77 {
78  if ( !index.isValid() )
79  return nullptr;
80 
81  if ( index.row() < 0 || index.row() >= d->m_renderPlugins.count() )
82  return nullptr;
83 
84  RenderPlugin *plugin = d->m_renderPlugins.at( index.row() );
85  return qobject_cast<DialogConfigurationInterface *>( plugin );
86 }
87 
89 {
90  for ( RenderPlugin *plugin: d->m_renderPlugins ) {
91  plugin->retrieveItemState();
92  }
93 }
94 
96 {
97  for ( RenderPlugin *plugin: d->m_renderPlugins ) {
98  plugin->applyItemState();
99  }
100 }
101 
102 }
103 
104 #include "moc_RenderPluginModel.cpp"
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:38
void applyPluginState()
Apply the plugin state from the user interface.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void retrievePluginState()
Retrieve the current plugin state for the user interface.
Binds a QML item to a specific geodetic location in screen coordinates.
bool isValid() const const
int row() const const
QList< QStandardItem * > takeRow(int row)
virtual bool hasChildren(const QModelIndex &parent) const const override
QStandardItem * invisibleRootItem() const const
void appendRow(const QList< QStandardItem * > &items)
void setRenderPlugins(const QList< RenderPlugin * > &renderPlugins)
Set the RenderPlugins the model should manage.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:50:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.