Marble

RenderPluginModel.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
4//
5
6#include "RenderPluginModel.h"
7
8#include "DialogConfigurationInterface.h"
9#include "RenderPlugin.h"
10
11namespace Marble
12{
13
14class Q_DECL_HIDDEN RenderPluginModel::Private
15{
16public:
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
28RenderPluginModel::Private::Private()
29 : m_renderPlugins()
30{
31}
32
33RenderPluginModel::RenderPluginModel(QObject *parent)
34 : QStandardItemModel(parent)
35 , d(new Private)
36{
37}
38
39RenderPluginModel::~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
49void RenderPluginModel::setRenderPlugins(const QList<RenderPlugin *> &renderPlugins)
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
65QList<PluginAuthor> RenderPluginModel::pluginAuthors(const QModelIndex &index) const
66{
67 if (!index.isValid())
68 return {};
69
70 if (index.row() < 0 || index.row() >= d->m_renderPlugins.count())
71 return {};
72
73 return d->m_renderPlugins.at(index.row())->pluginAuthors();
74}
75
76DialogConfigurationInterface *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
88void RenderPluginModel::retrievePluginState()
89{
90 for (RenderPlugin *plugin : d->m_renderPlugins) {
91 plugin->retrieveItemState();
92 }
93}
94
95void RenderPluginModel::applyPluginState()
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.
Binds a QML item to a specific geodetic location in screen coordinates.
const_reference at(qsizetype i) const const
bool isValid() const const
int row() const const
void appendRow(QStandardItem *item)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.