cutter/src/widgets/SdbDock.cpp

102 lines
2.7 KiB
C++
Raw Normal View History

#include "SdbDock.h"
#include "ui_SdbDock.h"
2017-10-01 19:09:42 +00:00
#include "MainWindow.h"
#include <QDebug>
#include <QTreeWidget>
SdbDock::SdbDock(MainWindow *main, QAction *action) :
CutterDockWidget(main, action),
ui(new Ui::SdbDock)
{
ui->setupUi(this);
path = "";
connect(Core(), SIGNAL(refreshAll()), this, SLOT(reload()));
2017-12-03 01:51:51 +00:00
reload(nullptr);
}
void SdbDock::reload(QString _path)
{
2018-03-21 20:32:32 +00:00
if (!_path.isNull()) {
path = _path;
}
ui->lineEdit->setText(path);
/* insert root sdb keyvalue pairs */
ui->treeWidget->clear();
QList<QString> keys;
/* key-values */
2017-10-09 18:08:35 +00:00
keys = CutterCore::getInstance()->sdbListKeys(path);
2018-03-21 20:32:32 +00:00
foreach (QString key, keys) {
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, key);
2017-10-09 18:08:35 +00:00
tempItem->setText(1, CutterCore::getInstance()->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);
}
ui->treeWidget->resizeColumnToContents(0);
ui->treeWidget->resizeColumnToContents(1);
/* namespaces */
2017-10-09 18:08:35 +00:00
keys = CutterCore::getInstance()->sdbList(path);
keys.append("..");
2018-03-21 20:32:32 +00:00
foreach (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);
}
ui->treeWidget->resizeColumnToContents(0);
ui->treeWidget->resizeColumnToContents(1);
}
void SdbDock::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
QString newpath;
2018-03-21 20:32:32 +00:00
if (column == 0) {
if (item->text(0) == "../") {
int idx = path.lastIndexOf("/");
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 {
newpath = "";
}
2017-04-09 19:55:06 +00:00
reload(newpath);
2018-03-21 20:32:32 +00:00
} else if (item->text(0).indexOf("/") != -1) {
if (path != "") {
2017-04-09 19:55:06 +00:00
newpath = path + "/" + item->text(0).replace("/", "");
2018-03-21 20:32:32 +00:00
} else {
2017-04-09 19:55:06 +00:00
newpath = path + item->text(0).replace("/", "");
}
2017-04-09 19:55:06 +00:00
// enter directory
reload(newpath);
}
}
}
2017-10-02 09:41:28 +00:00
SdbDock::~SdbDock() {}
void SdbDock::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 SdbDock::on_treeWidget_itemChanged(QTreeWidgetItem *item, int column)
{
2017-12-03 01:51:51 +00:00
Core()->sdbSet(path, item->text(0), item->text(column));
}