Commit 125bca5f authored by Alexander Semke's avatar Alexander Semke
Browse files

Delay the initialization of the documentaion widget and the loading of

the information about the available documentation file for the different
backends to the point where the user really wants to see this
information, i.e. when the user navigated to the documentation tab in
the settings for the specific backend. Introduced a new base class for
the backend settings widget to handle this logic in one central place
for all backend settings widgets.
parent dff3dc49
......@@ -21,7 +21,7 @@ set(cantor_HELP
ki18n_wrap_ui(cantor_HELP qthelpconfig.ui)
ki18n_wrap_ui(cantor_HELP qthelpconfigeditdialog.ui)
add_library(cantor_help STATIC ${cantor_HELP})
add_library(cantor_help STATIC ${cantor_HELP} backendsettingswidget.cpp)
target_link_libraries(cantor_help KF5::SyntaxHighlighting KF5::I18n KF5::IconThemes KF5::NewStuff KF5::KIOWidgets Qt5::Help)
if(NOT WIN32)
......
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
*/
#include "backendsettingswidget.h"
#include "qthelpconfig.h"
#include <QHBoxLayout>
#include <QTabWidget>
BackendSettingsWidget::BackendSettingsWidget(QWidget* parent, const QString& id) : QWidget(parent), m_id(id)
{
}
void BackendSettingsWidget::tabChanged(int index) {
if (!m_tabWidget || !m_tabDocumentation)
return;
//if the documentation tab was selected and there is not doc widget available yet, create it
if (m_tabWidget->widget(index) == m_tabDocumentation)
{
if (!m_docWidget)
{
m_docWidget = new QtHelpConfig(m_id);
auto hboxLayout = new QHBoxLayout(m_tabDocumentation);
hboxLayout->addWidget(m_docWidget);
}
}
}
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
*/
#ifndef BACKENDSETTINGSWIDGET_H
#define BACKENDSETTINGSWIDGET_H
#include <QWidget>
class QTabWidget;
class QtHelpConfig;
class BackendSettingsWidget : public QWidget
{
Q_OBJECT
public:
explicit BackendSettingsWidget(QWidget* parent = nullptr, const QString& id = QString());
private:
QtHelpConfig* m_docWidget = nullptr;
protected:
QString m_id;
QTabWidget* m_tabWidget = nullptr;
QWidget* m_tabDocumentation = nullptr;
public Q_SLOTS:
void tabChanged(int);
};
#endif /* BACKENDSETTINGSWIDGET_H */
......@@ -21,14 +21,12 @@
#include "maximasettingswidget.h"
#include "maximabackend.h"
#include "../qthelpconfig.h"
MaximaSettingsWidget::MaximaSettingsWidget(QWidget* parent, const QString& id) : QWidget(parent)
MaximaSettingsWidget::MaximaSettingsWidget(QWidget* parent, const QString& id) : BackendSettingsWidget(parent, id)
{
setupUi(this);
// Add QtHelp widget
QtHelpConfig* docWidget = new QtHelpConfig(id);
auto hboxLayout = new QHBoxLayout(tabDocumentation);
hboxLayout->addWidget(docWidget);
m_tabWidget = tabWidget;
m_tabDocumentation = tabDocumentation;
connect(tabWidget, &QTabWidget::currentChanged, this, &BackendSettingsWidget::tabChanged);
}
......@@ -23,8 +23,9 @@
#define _MAXIMASETTINGSWIDGET_H
#include "ui_settings.h"
#include "../backendsettingswidget.h"
class MaximaSettingsWidget : public QWidget, public Ui::MaximaSettingsBase
class MaximaSettingsWidget : public BackendSettingsWidget, public Ui::MaximaSettingsBase
{
Q_OBJECT
......
......@@ -41,7 +41,7 @@ PythonBackend::PythonBackend(QObject* parent, const QList<QVariant>& args) : Can
QWidget* PythonBackend::settingsWidget(QWidget* parent) const
{
return new PythonSettingsWidget(parent);
return new PythonSettingsWidget(parent, id());
}
Cantor::Session* PythonBackend::createSession()
......
......@@ -20,14 +20,12 @@
*/
#include "pythonsettingswidget.h"
#include "../qthelpconfig.h"
PythonSettingsWidget::PythonSettingsWidget(QWidget* parent, const QString& id) : QWidget(parent)
PythonSettingsWidget::PythonSettingsWidget(QWidget* parent, const QString& id) : BackendSettingsWidget(parent, id)
{
setupUi(this);
// Add QtHelp widget
QtHelpConfig* docWidget = new QtHelpConfig(id);
auto hboxLayout = new QHBoxLayout(tabDocumentation);
hboxLayout->addWidget(docWidget);
m_tabWidget = tabWidget;
m_tabDocumentation = tabDocumentation;
connect(tabWidget, &QTabWidget::currentChanged, this, &BackendSettingsWidget::tabChanged);
}
......@@ -23,13 +23,14 @@
#define _PYTHONSETTINGSWIDGET_H
#include "ui_settings.h"
#include "../backendsettingswidget.h"
class PythonSettingsWidget : public QWidget, public Ui::PythonSettingsBase
class PythonSettingsWidget : public BackendSettingsWidget, public Ui::PythonSettingsBase
{
Q_OBJECT
public:
explicit PythonSettingsWidget(QWidget *parent = nullptr, const QString& id = QString());
explicit PythonSettingsWidget(QWidget* parent = nullptr, const QString& id = QString());
};
#endif /* _PYTHONSETTINGSWIDGET_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment