Commit 7ef01c64 authored by Shubham  .'s avatar Shubham .
Browse files

Update the documentation panel if new worksheet with different backend is selected

parent 9bc25167
......@@ -23,7 +23,6 @@
#include "documentationpanelplugin.h"
#include "session.h"
#include <QDebug>
#include <QIcon>
DocumentationPanelPlugin::DocumentationPanelPlugin(QObject* parent, QList<QVariant> args) : Cantor::PanelPlugin(parent), m_widget(nullptr)
......@@ -38,13 +37,10 @@ DocumentationPanelPlugin::~DocumentationPanelPlugin()
QWidget* DocumentationPanelPlugin::widget()
{
//m_backendName = session()->backend()->name();
//m_backendIcon = session()->backend()->icon();
if(!m_widget)
{
m_widget = new DocumentationPanelWidget(QLatin1String("Maxima"), QLatin1String("maxima-backend"), parentWidget());
//m_widget = new DocumentationPanelWidget(m_backendName, m_backendIcon, parentWidget());
// find the default backend and then load it, currently hardcoding the values
m_widget = new DocumentationPanelWidget(QLatin1String("Maxima"), QLatin1String("maximabackend"), parentWidget());
}
return m_widget;
......@@ -88,17 +84,14 @@ void DocumentationPanelPlugin::restoreState(const Cantor::PanelPlugin::State& st
assert(state.inners.size() == 2);
m_backendName = state.inners[0].toString();
m_backendIcon = state.inners[1].toString();
/*if(m_widget)
m_widget->updateBackend(m_backendName, m_backendIcon);*/
}
else if (session())
else if(session())
{
m_backendName = session()->backend()->name();
m_backendIcon = session()->backend()->icon();
qDebug() << m_backendName;
m_widget = new DocumentationPanelWidget(m_backendName, m_backendIcon, parentWidget());
if(m_widget)
m_widget->updateBackend(m_backendName, m_backendIcon);
}
}
......
......@@ -51,6 +51,7 @@
DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const QString& backendIcon, QWidget* parent) :QWidget(parent)
{
m_backend = backend;
m_icon = backendIcon;
// initialize the Help engine
initHelpEngine();
......@@ -97,9 +98,9 @@ DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const
home->setToolTip(i18nc("@button go to contents page", "Go to the contents"));
home->setEnabled(false);
QComboBox* documentationSelector = new QComboBox(this);
m_documentationSelector = new QComboBox(this);
// iterate through the available docs for current backend, for example python may have matplotlib, scikitlearn etc
documentationSelector->addItem(QIcon::fromTheme(backendIcon), m_backend);
m_documentationSelector->addItem(QIcon::fromTheme(m_icon), m_backend);
// real time searcher
m_search = new QLineEdit(this);
......@@ -127,7 +128,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(home);
layout->addWidget(documentationSelector);
layout->addWidget(m_documentationSelector);
layout->addWidget(m_search);
layout->addWidget(seperator);
layout->addWidget(findPage);
......@@ -293,9 +294,44 @@ DocumentationPanelWidget::~DocumentationPanelWidget()
delete m_search;
delete m_findText;
delete m_matchCase;
delete m_documentationSelector;
//delete m_index; this crashes
}
void DocumentationPanelWidget::updateBackend(const QString& backendName, const QString& backendIcon)
{
if(m_backend == backendName)
{
/// in this case the new tab documentation is already opened previously
// so do nothing
return;
}
m_backend = backendName;
m_icon = backendIcon;
// remove previous widgets added on the display ie. browser, contents and index
m_displayArea->removeWidget(m_engine->contentWidget());
m_displayArea->removeWidget(m_textBrowser);
m_displayArea->removeWidget(m_index);
m_documentationSelector->clear();
m_search->clear();
// Now load QtHelp files for newly selected backend worksheet
initHelpEngine();
qDebug() << "New docsfile loaded";
loadDocumentation();
m_search->setCompleter(new QCompleter(m_index->model(), m_search));
// update the QComboBox to display all the docs for newly changed backend worksheet
m_documentationSelector->addItem(QIcon::fromTheme(m_icon), m_backend);
m_displayArea->addWidget(m_engine->contentWidget());
m_displayArea->addWidget(m_textBrowser);
m_displayArea->addWidget(m_index);
}
void DocumentationPanelWidget::initHelpEngine()
{
const QString& fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("documentation/") + m_backend + QLatin1String("/help.qhc"));
......
......@@ -27,6 +27,7 @@
#include <QWebEngineUrlSchemeHandler>
#include <QWidget>
class QComboBox;
class QHelpEngine;
class QHelpIndexWidget;
class QLineEdit;
......@@ -44,6 +45,8 @@ class DocumentationPanelWidget : public QWidget
DocumentationPanelWidget(const QString& backend, const QString& backendIcon, QWidget* parent);
~DocumentationPanelWidget();
void updateBackend(const QString&, const QString&);
Q_SIGNALS:
void activateBrowser();
void zoomFactorChanged();
......@@ -69,11 +72,14 @@ class DocumentationPanelWidget : public QWidget
QStackedWidget* m_displayArea = nullptr;
QHelpIndexWidget* m_index = nullptr;
QString m_backend;
QString m_icon;
// member variables for find in page text widget
QLineEdit* m_search = nullptr; // for searching through keywords
QLineEdit* m_findText = nullptr; // for find in page text widget
QToolButton* m_matchCase = nullptr;
QComboBox* m_documentationSelector = nullptr;
};
// class for handling of custom url scheme ie. qthelp:// inside QWebEngineView
......
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