Marble

MarblePluginSettingsWidget.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Torsten Rahn <rahn@kde.org>
4// SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
5//
6
8#include "ui_MarblePluginSettingsWidget.h"
9
10// Qt
11#include <QDialog>
12#include <QPointer>
13
14// Marble
15#include "DialogConfigurationInterface.h"
16#include "PluginAboutDialog.h"
17#include "PluginItemDelegate.h"
18#include "RenderPluginModel.h"
19
20namespace Marble
21{
22
23class MarblePluginSettingsWidgetPrivate : public Ui::MarblePluginSettingsWidget
24{
25public:
26 explicit MarblePluginSettingsWidgetPrivate(Marble::MarblePluginSettingsWidget *parent)
27 : q(parent)
28 , m_itemDelegate(nullptr)
29 {
30 }
31
32 /**
33 * Shows the about dialog for the plugin with the corresponding @p nameId.
34 */
35 void showPluginAboutDialog(const QModelIndex &index);
36
37 /**
38 * Shows the configuration dialog for the plugin with the corresponding @p nameId.
39 */
40 void showPluginConfigDialog(const QModelIndex &index);
41
42 Marble::MarblePluginSettingsWidget *const q;
43 PluginItemDelegate *m_itemDelegate = nullptr;
44 QPointer<RenderPluginModel> m_pluginModel;
45};
46
47void MarblePluginSettingsWidgetPrivate::showPluginAboutDialog(const QModelIndex &index)
48{
49 if (m_pluginModel.isNull())
50 return;
51
52 QPointer<PluginAboutDialog> aboutDialog = new PluginAboutDialog(q);
53
54 aboutDialog->setName(m_pluginModel->data(index, RenderPluginModel::Name).toString());
55 aboutDialog->setIcon(qvariant_cast<QIcon>(m_pluginModel->data(index, RenderPluginModel::Icon)));
56 aboutDialog->setVersion(m_pluginModel->data(index, RenderPluginModel::Version).toString());
57 aboutDialog->setDataText(m_pluginModel->data(index, RenderPluginModel::AboutDataText).toString());
58 const QString copyrightText = QObject::tr("<br/>(c) %1 The Marble Project<br /><br/><a href=\"https://edu.kde.org/marble\">https://edu.kde.org/marble</a>");
59 aboutDialog->setAboutText(copyrightText.arg(m_pluginModel->data(index, RenderPluginModel::CopyrightYears).toString()));
60 aboutDialog->setAuthors(m_pluginModel->pluginAuthors(index));
61
62 aboutDialog->exec();
63 delete aboutDialog;
64}
65
66void MarblePluginSettingsWidgetPrivate::showPluginConfigDialog(const QModelIndex &index)
67{
68 if (m_pluginModel.isNull())
69 return;
70
71 DialogConfigurationInterface *configInterface = m_pluginModel->pluginDialogConfigurationInterface(index);
72 QDialog *configDialog = configInterface ? configInterface->configDialog() : nullptr;
73 if (configDialog) {
74 configDialog->show();
75 }
76}
77
78MarblePluginSettingsWidget::MarblePluginSettingsWidget(QWidget *parent)
79 : QWidget(parent)
80 , d(new MarblePluginSettingsWidgetPrivate(this))
81{
82 d->setupUi(this);
83
84 d->m_itemDelegate = new PluginItemDelegate(d->m_pluginListView, this);
85 d->m_pluginListView->setItemDelegate(d->m_itemDelegate);
86 connect(d->m_itemDelegate, SIGNAL(aboutPluginClicked(QModelIndex)), this, SLOT(showPluginAboutDialog(QModelIndex)));
87 connect(d->m_itemDelegate, SIGNAL(configPluginClicked(QModelIndex)), this, SLOT(showPluginConfigDialog(QModelIndex)));
88}
89
90void MarblePluginSettingsWidget::setAboutIcon(const QIcon &icon)
91{
92 d->m_itemDelegate->setAboutIcon(icon);
93}
94
95MarblePluginSettingsWidget::~MarblePluginSettingsWidget()
96{
97 delete d;
98}
99
100void MarblePluginSettingsWidget::setConfigIcon(const QIcon &icon)
101{
102 d->m_itemDelegate->setConfigIcon(icon);
103}
104
105void MarblePluginSettingsWidget::setModel(RenderPluginModel *pluginModel)
106{
107 if (!d->m_pluginModel.isNull()) {
108 disconnect(d->m_pluginModel.data(), nullptr, this, nullptr);
109 }
110
111 d->m_pluginModel = pluginModel;
112 d->m_pluginListView->setModel(pluginModel);
113
114 if (!d->m_pluginModel.isNull()) {
115 connect(d->m_pluginModel.data(), SIGNAL(itemChanged(QStandardItem *)), this, SIGNAL(pluginListViewClicked()));
116 }
117}
118
119} // namespace Marble
120
121#include "moc_MarblePluginSettingsWidget.cpp"
This file contains the multiple inheritance ui-wrapper for the MarblePluginSettingsWidget ui file.
Binds a QML item to a specific geodetic location in screen coordinates.
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setupUi(QWidget *widget)
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.