aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bookmarks/bookmarksform.ui48
-rw-r--r--lib/bookmarks/bookmarksmodel.cpp41
-rw-r--r--lib/bookmarks/bookmarksmodel.h4
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp35
-rw-r--r--lib/bookmarks/bookmarkswidget.h2
-rw-r--r--lib/bookmarks/xbel.cpp44
6 files changed, 130 insertions, 44 deletions
diff --git a/lib/bookmarks/bookmarksform.ui b/lib/bookmarks/bookmarksform.ui
index 4de5e13..5d0f269 100644
--- a/lib/bookmarks/bookmarksform.ui
+++ b/lib/bookmarks/bookmarksform.ui
@@ -55,6 +55,54 @@
<item>
<widget class="QTreeView" name="treeView"/>
</item>
+ <item>
+ <widget class="QGroupBox" name="bookmark_groupBox">
+ <property name="title">
+ <string>Edit Bookmark</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="bookmarkTitle_label">
+ <property name="text">
+ <string>Title</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="bookmarkHref_label">
+ <property name="text">
+ <string>Address</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="bookmarkTitle"/>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="bookmarkHref"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="folder_groupBox">
+ <property name="title">
+ <string>Edit Folder</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="folderTitle_label">
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="folderTitle"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
diff --git a/lib/bookmarks/bookmarksmodel.cpp b/lib/bookmarks/bookmarksmodel.cpp
index 3498f71..418d456 100644
--- a/lib/bookmarks/bookmarksmodel.cpp
+++ b/lib/bookmarks/bookmarksmodel.cpp
@@ -175,6 +175,15 @@ Qt::ItemFlags BookmarksModel::flags(const QModelIndex &index) const
return flags;
}
+BookmarkItem::BookmarkItemType BookmarksModel::type(const QModelIndex &index) const
+{
+ if(!index.isValid()) {
+ return BookmarkItem::Root;
+ }
+
+ return static_cast<BookmarkItem *>(index.internalPointer())->type();
+}
+
QVariant BookmarksModel::data(const QModelIndex &index, int role) const
{
// get data of invalid index?
@@ -207,6 +216,9 @@ QVariant BookmarksModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+ case TitleRole:
+ return item->title;
+
case OpenUrlRole:
if(item->type() == BookmarkItem::Bookmark) {
return item->href;
@@ -230,25 +242,30 @@ bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, in
return false;
case BookmarkItem::Folder:
- if(index.column() == 0) {
+ if(role == TitleRole && (node->title != value.toString())) {
node->title = value.toString();
modified = true;
- emit dataChanged(index, index);
+ emit dataChanged(this->index(node, 0), this->index(node, 1));
+ //emit dataChanged(index, index);
return true;
}
return false;
case BookmarkItem::Bookmark:
- if(index.column() == 0) {
- node->title = value.toString();
- modified = true;
- emit dataChanged(index, index);
- return true;
- } else if(index.column() == 1) {
- node->href = value.toString();
- modified = true;
- emit dataChanged(index, index);
- return true;
+ if(role == TitleRole && (node->title != value.toString())) {
+ node->title = value.toString();
+ modified = true;
+ emit dataChanged(this->index(node, 0), this->index(node, 1));
+ //emit dataChanged(index, index);
+ return true;
+
+ } else if(role == OpenUrlRole && (node->href != value.toString())) {
+ node->href = value.toString();
+ modified = true;
+ emit dataChanged(this->index(node, 0), this->index(node, 1));
+ //emit dataChanged(index, index);
+ return true;
+
}
return false;
}
diff --git a/lib/bookmarks/bookmarksmodel.h b/lib/bookmarks/bookmarksmodel.h
index 0fb5e04..ea1d203 100644
--- a/lib/bookmarks/bookmarksmodel.h
+++ b/lib/bookmarks/bookmarksmodel.h
@@ -22,7 +22,8 @@ class BookmarksModel : public QAbstractItemModel
public:
enum {
- OpenUrlRole = Qt::UserRole + 1
+ TitleRole = Qt::UserRole + 1,
+ OpenUrlRole = Qt::UserRole + 2
};
explicit BookmarksModel(QStyle *style, QObject *parent = nullptr);
@@ -45,6 +46,7 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
+ BookmarkItem::BookmarkItemType type(const QModelIndex &index) const;
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
index e148831..93287c4 100644
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -20,14 +20,14 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
ui->setupUi(this);
ui->treeView->header()->setSectionResizeMode(QHeaderView::Stretch);
+ ui->bookmark_groupBox->setVisible(false);
+ ui->folder_groupBox->setVisible(false);
ui->addFolder_toolButton->setIcon(style()->standardPixmap(QStyle::SP_DirIcon));
ui->addBookmark_toolButton->setIcon(style()->standardPixmap(QStyle::SP_FileIcon));
ui->deleteItem_toolButton->setIcon(style()->standardPixmap(QStyle::SP_TrashIcon));
ui->deleteItem_toolButton->setShortcut(QKeySequence::Delete);
- editEntry_shortcut = new QShortcut(QKeySequence("F2"), this);
-
m_model = new BookmarksModel(style(), this);
ui->treeView->setModel(m_model);
@@ -36,10 +36,7 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
m_model->expandItems(ui->treeView);
connect(ui->treeView, &QTreeView::activated, this, [this](const QModelIndex &index) {
- if(ui->treeView->isPersistentEditorOpen(index))
- ui->treeView->closePersistentEditor(index);
- else
- emit openUrl(m_model->data(index, BookmarksModel::OpenUrlRole).toUrl());
+ emit openUrl(m_model->data(index, BookmarksModel::OpenUrlRole).toUrl());
});
connect(ui->addBookmark_toolButton, &QToolButton::clicked, this, [this]() {
@@ -51,9 +48,29 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
m_model->insertItem(BookmarkItem::Folder, idx);
});
- connect(editEntry_shortcut, &QShortcut::activated, this, [this]() {
- QModelIndex idx = ui->treeView->currentIndex();
- ui->treeView->openPersistentEditor(idx);
+ connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this](const QModelIndex &current, const QModelIndex &previous) {
+ // save the previous item
+ if(previous.isValid()) {
+ if(m_model->type(previous) == BookmarkItem::Folder) {
+ m_model->setData(previous, ui->folderTitle->text(), BookmarksModel::TitleRole);
+ ui->folder_groupBox->setVisible(false);
+ } else if(m_model->type(previous) == BookmarkItem::Bookmark) {
+ m_model->setData(previous, ui->bookmarkTitle->text(), BookmarksModel::TitleRole);
+ m_model->setData(previous, ui->bookmarkHref->text(), BookmarksModel::OpenUrlRole);
+ ui->bookmark_groupBox->setVisible(false);
+ }
+ }
+
+ if(current.isValid()) {
+ if(m_model->type(current) == BookmarkItem::Folder) {
+ ui->folderTitle->setText(m_model->data(current, BookmarksModel::TitleRole).toString());
+ ui->folder_groupBox->setVisible(true);
+ } else if(m_model->type(current) == BookmarkItem::Bookmark) {
+ ui->bookmarkTitle->setText(m_model->data(current, BookmarksModel::TitleRole).toString());
+ ui->bookmarkHref->setText(m_model->data(current, BookmarksModel::OpenUrlRole).toString());
+ ui->bookmark_groupBox->setVisible(true);
+ }
+ }
});
}
diff --git a/lib/bookmarks/bookmarkswidget.h b/lib/bookmarks/bookmarkswidget.h
index ec3469b..23e275f 100644
--- a/lib/bookmarks/bookmarkswidget.h
+++ b/lib/bookmarks/bookmarkswidget.h
@@ -40,8 +40,6 @@ private:
Ui::BookmarksDialog *ui;
BookmarksModel *m_model;
Xbel *xbel;
-
- QShortcut *editEntry_shortcut;
};
#endif // BOOKMARKSDIALOG_H
diff --git a/lib/bookmarks/xbel.cpp b/lib/bookmarks/xbel.cpp
index d19641c..1be9c7e 100644
--- a/lib/bookmarks/xbel.cpp
+++ b/lib/bookmarks/xbel.cpp
@@ -97,26 +97,30 @@ bool Xbel::write(BookmarkItem *root)
void Xbel::writeChildElements(QXmlStreamWriter &writer, BookmarkItem *parentItem)
{
- for(int i = 0; i < parentItem->childCount(); ++i) {
- BookmarkItem *node = parentItem->child(i);
- switch(node->type()) {
- case BookmarkItem::Root:
- break;
- case BookmarkItem::Folder:
- writer.writeStartElement("folder");
- writer.writeAttribute("folded", node->folded ? "yes" : "no");
- writer.writeTextElement("title", node->title);
- for(int j = 0; j < node->childCount(); ++j) {
- writeChildElements(writer, node);
- }
- writer.writeEndElement();
- break;
- case BookmarkItem::Bookmark:
- writer.writeStartElement("bookmark");
- writer.writeAttribute("href", node->href);
- writer.writeTextElement("title", node->title);
- writer.writeEndElement();
- break;
+ switch(parentItem->type()) {
+ case BookmarkItem::Root:
+ for(int i = 0; i < parentItem->childCount(); ++i) {
+ writeChildElements(writer, parentItem->child(i));
}
+ break;
+
+ case BookmarkItem::Folder:
+ writer.writeStartElement("folder");
+ writer.writeAttribute("folded", parentItem->folded ? "yes" : "no");
+ writer.writeTextElement("title", parentItem->title);
+
+ for(int i = 0; i < parentItem->childCount(); ++i) {
+ writeChildElements(writer, parentItem->child(i));
+ }
+
+ writer.writeEndElement();
+ break;
+
+ case BookmarkItem::Bookmark:
+ writer.writeStartElement("bookmark");
+ writer.writeAttribute("href", parentItem->href);
+ writer.writeTextElement("title", parentItem->title);
+ writer.writeEndElement();
+ break;
}
}