Commit ed286943 authored by Shubham  .'s avatar Shubham .
Browse files

Remove unneeded code and properly save settings

parent 26f05746
......@@ -18,12 +18,9 @@
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#include <QTreeWidgetItem>
#include "maximasettingswidget.h"
#include "../qthelpconfig.h"
#include <QDebug>
#include <KConfigGroup>
#include <KSharedConfig>
......@@ -32,25 +29,20 @@ MaximaSettingsWidget::MaximaSettingsWidget(QWidget *parent) : QWidget(parent)
setupUi(this);
// Add QtHelp widget
/*QtHelpConfig**/ docWidget = new QtHelpConfig();
QtHelpConfig* docWidget = new QtHelpConfig();
static_cast<QGridLayout*>(this->layout())->addWidget(docWidget, 6, 0, 1, 3);
loadSettings(); // load previously saved settings from read KConfig
}
MaximaSettingsWidget::~MaximaSettingsWidget()
void MaximaSettingsWidget::loadSettings()
{
const KConfigGroup cg = KSharedConfig::openConfig()->group(QLatin1String("Settings_Documentation"));
/*KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_Documentation"));
QString name;
QString path;
for (int i = 0; i < docWidget->qchTable->topLevelItemCount(); i++)
{
const QTreeWidgetItem* item = docWidget->qchTable->topLevelItem(i);
name = item->text(0);
path = item->text(1);
}
QStringList nameList = cg.readEntry("Names", QStringList());
QStringList pathList = cg.readEntry("Paths", QStringList());
group.writeEntry(QLatin1String("Name"), name);
group.writeEntry(QLatin1String("Path"), path);*/
qDebug() << nameList.at(0);
/*ui.chkShowColumnType->setChecked(group.readEntry(QLatin1String("Names"), QStringList()));
ui.chkShowPlotDesignation->setChecked(group.readEntry(QLatin1String("Paths"), QStringList()));*/
}
......@@ -23,17 +23,16 @@
#include "../qthelpconfig.h"
#include "ui_settings.h"
#include <QDebug>
class MaximaSettingsWidget : public QWidget, public Ui::MaximaSettingsBase
{
Q_OBJECT
public:
explicit MaximaSettingsWidget(QWidget *parent = nullptr);
~MaximaSettingsWidget();
private:
QtHelpConfig* docWidget;
private:
void loadSettings();
};
#endif /* _MAXIMASETTINGSWIDGET_H */
......@@ -113,7 +113,7 @@ QtHelpConfig::QtHelpConfig()
m_configWidget->tableCtrlLayout->insertWidget(1, knsButton);
connect(knsButton, &KNS3::Button::dialogFinished, this, &QtHelpConfig::knsUpdate);
reset();
connect(this, &QtHelpConfig::settingsChanged, this, &QtHelpConfig::saveSettings);
}
QtHelpConfig::~QtHelpConfig()
......@@ -121,48 +121,13 @@ QtHelpConfig::~QtHelpConfig()
delete m_configWidget;
}
void QtHelpConfig::apply()
{
QStringList iconList, nameList, pathList, ghnsList;
for (int i = 0; i < m_configWidget->qchTable->topLevelItemCount(); i++) {
const QTreeWidgetItem* item = m_configWidget->qchTable->topLevelItem(i);
nameList << item->text(0);
pathList << item->text(1);
iconList << item->text(2);
ghnsList << item->text(3);
}
qtHelpWriteConfig(iconList, nameList, pathList, ghnsList);
//static_cast<QtHelpPlugin*>(plugin())->readConfig();*/
}
void QtHelpConfig::reset()
{
m_configWidget->qchTable->clear();
QStringList iconList, nameList, pathList, ghnsList;
qtHelpReadConfig(iconList, nameList, pathList, ghnsList);
const int size = qMin(qMin(iconList.size(), nameList.size()), pathList.size());
for(int i = 0; i < size; ++i) {
QString ghnsStatus = ghnsList.size()>i ? ghnsList.at(i) : QStringLiteral("0");
addTableItem(iconList.at(i), nameList.at(i), pathList.at(i), ghnsStatus);
}
}
void QtHelpConfig::defaults()
{
if(m_configWidget->qchTable->topLevelItemCount() > 0) {
m_configWidget->qchTable->clear();
}
}
void QtHelpConfig::add()
{
QPointer<QtHelpConfigEditDialog> dialog = new QtHelpConfigEditDialog(nullptr, this);
if (dialog->exec()) {
QTreeWidgetItem* item = addTableItem(dialog->qchIcon->icon(), dialog->qchName->text(), dialog->qchRequester->text(), QStringLiteral("0"));
m_configWidget->qchTable->setCurrentItem(item);
emit settingsChanged();
}
delete dialog;
}
......@@ -195,6 +160,7 @@ void QtHelpConfig::modify(QTreeWidgetItem* item)
if(item->text(GhnsColumn) == QLatin1String("0")) {
item->setText(PathColumn, dialog->qchRequester->text());
}
emit settingsChanged();
}
delete dialog;
}
......@@ -227,6 +193,7 @@ void QtHelpConfig::remove(QTreeWidgetItem* item)
return;
delete item;
emit settingsChanged();
}
void QtHelpConfig::knsUpdate(const KNS3::Entry::List& list)
......@@ -259,6 +226,7 @@ void QtHelpConfig::knsUpdate(const KNS3::Entry::List& list)
}
}
}
emit settingsChanged();
}
QTreeWidgetItem * QtHelpConfig::addTableItem(const QString &icon, const QString &name,
......@@ -303,24 +271,23 @@ QTreeWidgetItem * QtHelpConfig::addTableItem(const QString &icon, const QString
return item;
}
void QtHelpConfig::qtHelpReadConfig(QStringList& iconList, QStringList& nameList,
QStringList& pathList, QStringList& ghnsList)
void QtHelpConfig::saveSettings()
{
KConfigGroup cg(KSharedConfig::openConfig(), "QtHelp Documentation");
iconList = cg.readEntry("iconList", QStringList());
nameList = cg.readEntry("nameList", QStringList());
pathList = cg.readEntry("pathList", QStringList());
ghnsList = cg.readEntry("ghnsList", QStringList());
}
qDebug() << "settings changed";
KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_Documentation"));
void QtHelpConfig::qtHelpWriteConfig(const QStringList& iconList, const QStringList& nameList,
const QStringList& pathList, const QStringList& ghnsList)
{
KConfigGroup cg(KSharedConfig::openConfig(), "QtHelp Documentation");
cg.writeEntry("iconList", iconList);
cg.writeEntry("nameList", nameList);
cg.writeEntry("pathList", pathList);
cg.writeEntry("ghnsList", ghnsList);
QStringList name;
QStringList path;
for (int i = 0; i < m_configWidget->qchTable->topLevelItemCount(); i++)
{
const QTreeWidgetItem* item = m_configWidget->qchTable->topLevelItem(i);
name << item->text(0);
path << item->text(1);
}
group.writeEntry(QLatin1String("Names"), name);
group.writeEntry(QLatin1String("Paths"), path);
}
#include "qthelpconfig.moc"
......@@ -33,12 +33,17 @@ namespace Ui
class QtHelpConfig : public QWidget
{
Q_OBJECT
public:
explicit QtHelpConfig();
~QtHelpConfig();
bool checkNamespace(const QString &filename, QTreeWidgetItem* modifiedItem);
Q_SIGNALS:
void settingsChanged();
private Q_SLOTS:
void add();
void remove(QTreeWidgetItem* item);
......@@ -46,17 +51,11 @@ class QtHelpConfig : public QWidget
void knsUpdate(const KNS3::Entry::List& list);
public Q_SLOTS:
void apply();
void defaults();
void reset();
void saveSettings();
private:
QTreeWidgetItem * addTableItem(const QString &icon, const QString &name,
const QString &path, const QString &ghnsStatus);
void qtHelpReadConfig(QStringList& iconList, QStringList& nameList, QStringList& pathList, QStringList& ghnsList);
void qtHelpWriteConfig(const QStringList& iconList, const QStringList& nameList, const QStringList& pathList,
const QStringList& ghnsList);
Ui::QtHelpConfigUI* m_configWidget;
};
......
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