diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-09-25 14:44:01 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-09-25 14:44:01 +0200 |
commit | 9203de811f049c8e604a9c3065781157fa506155 (patch) | |
tree | 96096d8cbeefd58c988ddb97dcd51fa21873ffb6 /lib/bookmarks/forms | |
parent | Bookmarks: add BookmarkItem and BookmarkModel (diff) | |
download | smolbote-9203de811f049c8e604a9c3065781157fa506155.tar.xz |
Bookmarks: integrate model/view
- fix addBookmark and search signals
- fix drag'n'drop
- add xbel::write
Diffstat (limited to 'lib/bookmarks/forms')
-rw-r--r-- | lib/bookmarks/forms/editbookmarkdialog.cpp | 41 | ||||
-rw-r--r-- | lib/bookmarks/forms/editbookmarkdialog.h | 12 | ||||
-rw-r--r-- | lib/bookmarks/forms/editbookmarkdialog.ui | 4 |
3 files changed, 47 insertions, 10 deletions
diff --git a/lib/bookmarks/forms/editbookmarkdialog.cpp b/lib/bookmarks/forms/editbookmarkdialog.cpp index 47aa0b7..7bc1331 100644 --- a/lib/bookmarks/forms/editbookmarkdialog.cpp +++ b/lib/bookmarks/forms/editbookmarkdialog.cpp @@ -18,28 +18,53 @@ EditBookmarkDialog::EditBookmarkDialog(BookmarkModel *model, const QModelIndex & ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); + Q_CHECK_PTR(model); + m_model = model; + m_index = index; + ui->title->setText(model->data(index, BookmarkItem::Title, Qt::DisplayRole).toString()); - connect(ui->title, &QLineEdit::editingFinished, this, [this, model, index]() { - model->setData(index, ui->title->text(), BookmarkItem::Title, Qt::DisplayRole); + connect(ui->title, &QLineEdit::editingFinished, this, [this]() { + titleChanged = true; }); ui->address->setText(model->data(index, BookmarkItem::Href, Qt::DisplayRole).toString()); - connect(ui->address, &QLineEdit::editingFinished, this, [this, model, index]() { - model->setData(index, ui->address->text(), BookmarkItem::Href, Qt::DisplayRole); + connect(ui->address, &QLineEdit::editingFinished, this, [this]() { + hrefChanged = true; }); ui->tags->setText(model->data(index, BookmarkItem::Tags, Qt::DisplayRole).toStringList().join(", ")); - connect(ui->tags, &QLineEdit::editingFinished, this, [this, model, index]() { - model->setData(index, ui->tags->text().split(", "), BookmarkItem::Tags, Qt::DisplayRole); + connect(ui->tags, &QLineEdit::editingFinished, this, [this]() { + tagsChanged = true; }); ui->description->setPlainText(model->data(index, BookmarkItem::Description, Qt::DisplayRole).toString()); - connect(ui->description, &QPlainTextEdit::textChanged, this, [this, model, index]() { - model->setData(index, ui->description->toPlainText(), BookmarkItem::Description, Qt::DisplayRole); + connect(ui->description, &QPlainTextEdit::textChanged, this, [this]() { + descriptionChanged = true; }); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &EditBookmarkDialog::saveChanges); } EditBookmarkDialog::~EditBookmarkDialog() { delete ui; } + +void EditBookmarkDialog::saveChanges() +{ + if(titleChanged) { + m_model->setData(m_index, ui->title->text(), BookmarkItem::Title, Qt::DisplayRole); + } + + if(hrefChanged) { + m_model->setData(m_index, ui->address->text(), BookmarkItem::Href, Qt::DisplayRole); + } + + if(tagsChanged) { + m_model->setData(m_index, ui->tags->text().split(", "), BookmarkItem::Tags, Qt::DisplayRole); + } + + if(descriptionChanged) { + m_model->setData(m_index, ui->description->toPlainText(), BookmarkItem::Description, Qt::DisplayRole); + } +}
\ No newline at end of file diff --git a/lib/bookmarks/forms/editbookmarkdialog.h b/lib/bookmarks/forms/editbookmarkdialog.h index 968b6af..863eaf8 100644 --- a/lib/bookmarks/forms/editbookmarkdialog.h +++ b/lib/bookmarks/forms/editbookmarkdialog.h @@ -10,6 +10,7 @@ #define SMOLBOTE_EDITBOOKMARKDIALOG_H #include <QDialog> +#include <QModelIndex> namespace Ui { @@ -25,8 +26,19 @@ public: explicit EditBookmarkDialog(BookmarkModel *model, const QModelIndex &index, QWidget *parent = nullptr); ~EditBookmarkDialog() override; +public slots: + void saveChanges(); + private: Ui::EditBookmarkDialog *ui; + + BookmarkModel *m_model; + QModelIndex m_index; + + bool titleChanged = false; + bool hrefChanged = false; + bool tagsChanged = false; + bool descriptionChanged = false; }; #endif // SMOLBOTE_EDITBOOKMARKDIALOG_H diff --git a/lib/bookmarks/forms/editbookmarkdialog.ui b/lib/bookmarks/forms/editbookmarkdialog.ui index 1861fcc..b988394 100644 --- a/lib/bookmarks/forms/editbookmarkdialog.ui +++ b/lib/bookmarks/forms/editbookmarkdialog.ui @@ -6,12 +6,12 @@ <rect> <x>0</x> <y>0</y> - <width>262</width> + <width>400</width> <height>320</height> </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Edit Bookmark</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> |