cutter/src/widgets/SdbWidget.cpp

104 lines
2.7 KiB
C++
Raw Normal View History

#include "SdbWidget.h"
#include "ui_SdbWidget.h"
#include "core/MainWindow.h"
2018-10-17 07:55:53 +00:00
#include "common/Helpers.h"
#include <QDebug>
#include <QTreeWidget>
SdbWidget::SdbWidget(MainWindow *main, QAction *action) :
CutterDockWidget(main, action),
ui(new Ui::SdbWidget)
{
ui->setupUi(this);
2019-03-23 10:54:34 +00:00
path.clear();
connect(Core(), SIGNAL(refreshAll()), this, SLOT(reload()));
reload();
}
void SdbWidget::reload(QString _path)
{
path = _path;
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);
for (const QString &key : keys) {
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);
ui->treeWidget->insertTopLevelItem(0, tempItem);
}
qhelpers::adjustColumns(ui->treeWidget, 0);
/* namespaces */
2018-04-12 06:33:30 +00:00
keys = Core()->sdbList(path);
if (!path.isEmpty()) {
keys.append("..");
}
for (const QString &key : keys) {
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
2017-04-09 19:55:06 +00:00
tempItem->setText(0, key + "/");
tempItem->setText(1, "");
ui->treeWidget->insertTopLevelItem(0, tempItem);
}
qhelpers::adjustColumns(ui->treeWidget, 0);
}
void SdbWidget::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
if (column < 0)
return;
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-04-09 19:55:06 +00:00
reload(newpath);
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-04-09 19:55:06 +00:00
// enter directory
reload(newpath);
}
}
}
SdbWidget::~SdbWidget() {}
void SdbWidget::on_lockButton_clicked()
{
2018-03-21 20:32:32 +00:00
if (ui->lockButton->isChecked()) {
this->setAllowedAreas(Qt::NoDockWidgetArea);
ui->lockButton->setIcon(QIcon(":/lock"));
2018-03-21 20:32:32 +00:00
} else {
this->setAllowedAreas(Qt::AllDockWidgetAreas);
ui->lockButton->setIcon(QIcon(":/unlock"));
}
}
void SdbWidget::on_treeWidget_itemChanged(QTreeWidgetItem *item, int column)
{
2017-12-03 01:51:51 +00:00
Core()->sdbSet(path, item->text(0), item->text(column));
}