2019-02-13 06:38:47 +00:00
|
|
|
#include "SdbWidget.h"
|
|
|
|
#include "ui_SdbWidget.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Helpers.h"
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
#include <QDebug>
|
2017-04-13 15:14:02 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-02-13 06:38:47 +00:00
|
|
|
SdbWidget::SdbWidget(MainWindow *main, QAction *action) :
|
2018-03-16 21:46:57 +00:00
|
|
|
CutterDockWidget(main, action),
|
2019-02-13 06:38:47 +00:00
|
|
|
ui(new Ui::SdbWidget)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-11-19 12:56:10 +00:00
|
|
|
|
2019-03-23 10:54:34 +00:00
|
|
|
path.clear();
|
2017-11-19 12:56:10 +00:00
|
|
|
|
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(reload()));
|
2019-07-29 04:56:23 +00:00
|
|
|
reload();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:38:47 +00:00
|
|
|
void SdbWidget::reload(QString _path)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2019-07-29 04:56:23 +00:00
|
|
|
path = _path;
|
2017-11-19 12:56:10 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->lineEdit->setText(path);
|
|
|
|
/* insert root sdb keyvalue pairs */
|
|
|
|
|
|
|
|
ui->treeWidget->clear();
|
|
|
|
QList<QString> keys;
|
|
|
|
/* key-values */
|
2018-04-12 06:33:30 +00:00
|
|
|
keys = Core()->sdbListKeys(path);
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QString &key : keys) {
|
2017-03-29 10:18:37 +00:00
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
|
|
|
tempItem->setText(0, key);
|
2018-04-12 06:33:30 +00:00
|
|
|
tempItem->setText(1, Core()->sdbGet(path, key));
|
2018-03-21 20:32:32 +00:00
|
|
|
tempItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |
|
|
|
|
Qt::ItemIsDragEnabled | Qt::ItemIsEditable);
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->treeWidget->insertTopLevelItem(0, tempItem);
|
|
|
|
}
|
2018-04-01 08:25:31 +00:00
|
|
|
qhelpers::adjustColumns(ui->treeWidget, 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
/* namespaces */
|
2018-04-12 06:33:30 +00:00
|
|
|
keys = Core()->sdbList(path);
|
2019-07-29 04:56:23 +00:00
|
|
|
if (!path.isEmpty()) {
|
|
|
|
keys.append("..");
|
|
|
|
}
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const QString &key : keys) {
|
2017-03-29 10:18:37 +00:00
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
2017-04-09 19:55:06 +00:00
|
|
|
tempItem->setText(0, key + "/");
|
2017-03-29 10:18:37 +00:00
|
|
|
tempItem->setText(1, "");
|
|
|
|
ui->treeWidget->insertTopLevelItem(0, tempItem);
|
|
|
|
}
|
2018-04-01 08:25:31 +00:00
|
|
|
qhelpers::adjustColumns(ui->treeWidget, 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-13 06:38:47 +00:00
|
|
|
void SdbWidget::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-04-23 07:54:06 +00:00
|
|
|
if (column < 0)
|
|
|
|
return;
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
QString newpath;
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (column == 0) {
|
|
|
|
if (item->text(0) == "../") {
|
2019-03-23 10:54:34 +00:00
|
|
|
int idx = path.lastIndexOf(QLatin1Char('/'));
|
2018-03-21 20:32:32 +00:00
|
|
|
if (idx != -1) {
|
2017-04-09 19:55:06 +00:00
|
|
|
newpath = path.mid(0, idx);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2019-03-23 10:54:34 +00:00
|
|
|
newpath.clear();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-04-09 19:55:06 +00:00
|
|
|
reload(newpath);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-03-23 10:54:34 +00:00
|
|
|
} else if (item->text(0).indexOf(QLatin1Char('/')) != -1) {
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
newpath = path + "/" + item->text(0).remove(QLatin1Char('/'));
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2019-03-23 10:54:34 +00:00
|
|
|
newpath = path + item->text(0).remove(QLatin1Char('/'));
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-04-09 19:55:06 +00:00
|
|
|
// enter directory
|
|
|
|
reload(newpath);
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 06:38:47 +00:00
|
|
|
SdbWidget::~SdbWidget() {}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-02-13 06:38:47 +00:00
|
|
|
void SdbWidget::on_lockButton_clicked()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->lockButton->isChecked()) {
|
2017-03-29 10:18:37 +00:00
|
|
|
this->setAllowedAreas(Qt::NoDockWidgetArea);
|
2017-06-15 09:53:10 +00:00
|
|
|
ui->lockButton->setIcon(QIcon(":/lock"));
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-03-29 10:18:37 +00:00
|
|
|
this->setAllowedAreas(Qt::AllDockWidgetAreas);
|
2017-06-15 09:53:10 +00:00
|
|
|
ui->lockButton->setIcon(QIcon(":/unlock"));
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 06:38:47 +00:00
|
|
|
void SdbWidget::on_treeWidget_itemChanged(QTreeWidgetItem *item, int column)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-12-03 01:51:51 +00:00
|
|
|
Core()->sdbSet(path, item->text(0), item->text(column));
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|