From 73ac56d0b5b163514bdc68e83fc01b0e41837a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 11 Nov 2014 22:57:54 +0100 Subject: [PATCH] renaming lists working for labels --- YACReaderLibrary/db/reading_list_item.cpp | 43 ++++++++++++++++++++- YACReaderLibrary/db/reading_list_item.h | 12 ++++-- YACReaderLibrary/db/reading_list_model.cpp | 16 ++++++-- YACReaderLibrary/db_helper.cpp | 24 ++++++++++++ YACReaderLibrary/db_helper.h | 2 + YACReaderLibrary/images_win.qrc | 1 + YACReaderLibrary/library_window.cpp | 2 +- images/renameListIcon.png | Bin 0 -> 315 bytes 8 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 images/renameListIcon.png diff --git a/YACReaderLibrary/db/reading_list_item.cpp b/YACReaderLibrary/db/reading_list_item.cpp index 4cc123d4..2f89c1d8 100644 --- a/YACReaderLibrary/db/reading_list_item.cpp +++ b/YACReaderLibrary/db/reading_list_item.cpp @@ -16,6 +16,11 @@ QVariant ListItem::data(int column) const return itemData.at(column); } +qulonglong ListItem::getId() const +{ + return 0; +} + //------------------------------------------------------ SpecialListItem::SpecialListItem(const QList &data) @@ -50,7 +55,7 @@ QIcon LabelItem::getIcon() const } } -YACReader::LabelColors LabelItem::colorid() +YACReader::LabelColors LabelItem::colorid() const { if(itemData.count()>3) { @@ -58,7 +63,7 @@ YACReader::LabelColors LabelItem::colorid() } } -QString LabelItem::name() +QString LabelItem::name() const { if(itemData.count()>0) { @@ -66,6 +71,19 @@ QString LabelItem::name() } } +void LabelItem::setName(const QString &name) +{ + itemData[0] = name; +} + +qulonglong LabelItem::getId() const +{ + if(itemData.count()>2) + { + return YACReader::LabelColors(itemData.at(2).toULongLong()); + } +} + //------------------------------------------------------ ReadingListItem::ReadingListItem(const QList &data, ReadingListItem *p) @@ -124,6 +142,27 @@ void ReadingListItem::appendChild(ReadingListItem *item) } +qulonglong ReadingListItem::getId() const +{ + if(itemData.count()>1) + { + return YACReader::LabelColors(itemData.at(1).toULongLong()); + } +} + +QString ReadingListItem::name() const +{ + if(itemData.count()>0) + { + return itemData.at(0).toString(); + } +} + +void ReadingListItem::setName(const QString &name) +{ + itemData[0] = name; +} + int ReadingListItem::row() const { if (parent) diff --git a/YACReaderLibrary/db/reading_list_item.h b/YACReaderLibrary/db/reading_list_item.h index 4cdbeb32..9f7399fa 100644 --- a/YACReaderLibrary/db/reading_list_item.h +++ b/YACReaderLibrary/db/reading_list_item.h @@ -14,7 +14,7 @@ public: int columnCount(); virtual QIcon getIcon() const = 0; QVariant data(int column) const; - + virtual qulonglong getId() const; QList itemData; }; @@ -34,8 +34,11 @@ class LabelItem : public ListItem public: LabelItem(const QList &data); QIcon getIcon() const; - YACReader::LabelColors colorid(); - QString name(); + YACReader::LabelColors colorid() const; + QString name() const; + void setName(const QString & name); + qulonglong getId() const; + }; //------------------------------------------------------ @@ -50,6 +53,9 @@ public: int row() const; ReadingListItem * child(int row); void appendChild(ReadingListItem *item); + qulonglong getId() const; + QString name() const; + void setName(const QString & name); private: QList childItems; diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index 3d20bf48..a007f012 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -26,8 +26,6 @@ int ReadingListModel::rowCount(const QModelIndex &parent) const { ListItem * item = static_cast(parent.internalPointer()); - QLOG_DEBUG() << item->itemData; - if(typeid(*item) == typeid(ReadingListItem)) { ReadingListItem * item = static_cast(parent.internalPointer()); @@ -213,8 +211,20 @@ void ReadingListModel::rename(const QModelIndex &mi, const QString &name) QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); - //TODO + ListItem * item = static_cast(mi.internalPointer()); + if(typeid(*item) == typeid(ReadingListItem)) + { + ReadingListItem * rli = static_cast(item); + rli->setName(name); + DBHelper::renameList(item->getId(), name, db); + } + else if(typeid(*item) == typeid(LabelItem)) + { + LabelItem * li = static_cast(item); + li->setName(name); + DBHelper::renameLabel(item->getId(), name, db); + } emit dataChanged(index(mi.row(), 0), index(mi.row(), 0)); diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index d43e1bd4..373bebbc 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -314,6 +314,30 @@ void DBHelper::updateProgress(qulonglong libraryId, const ComicInfo &comicInfo) QSqlDatabase::removeDatabase(libraryPath); } +void DBHelper::renameLabel(qulonglong id, const QString &name, QSqlDatabase &db) +{ + QSqlQuery renameLabelQuery(db); + renameLabelQuery.prepare("UPDATE label SET " + "name = :name " + "WHERE id = :id"); + renameLabelQuery.bindValue(":name", name); + renameLabelQuery.bindValue(":id", id); + renameLabelQuery.exec(); + + QLOG_DEBUG() << renameLabelQuery.lastError().databaseText(); +} + +void DBHelper::renameList(qulonglong id, const QString &name, QSqlDatabase &db) +{ + QSqlQuery renameLabelQuery(db); + renameLabelQuery.prepare("UPDATE reading_list SET " + "name = :name " + "WHERE id = :id"); + renameLabelQuery.bindValue(":name", name); + renameLabelQuery.bindValue(":id", id); + renameLabelQuery.exec(); +} + //inserts qulonglong DBHelper::insert(Folder * folder, QSqlDatabase & db) { diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index bb818b22..47485b48 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -45,6 +45,8 @@ public: static void updateRead(ComicInfo * comicInfo, QSqlDatabase & db); static void update(const Folder & folder, QSqlDatabase & db); static void updateProgress(qulonglong libraryId,const ComicInfo & comicInfo); + static void renameLabel(qulonglong id, const QString & name, QSqlDatabase & db); + static void renameList(qulonglong id, const QString & name, QSqlDatabase & db); static QList getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true); static QList getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db); diff --git a/YACReaderLibrary/images_win.qrc b/YACReaderLibrary/images_win.qrc index f5d4e3a0..f0f62517 100644 --- a/YACReaderLibrary/images_win.qrc +++ b/YACReaderLibrary/images_win.qrc @@ -25,6 +25,7 @@ ../images/iconSearchNew.png ../images/clearSearchNew.png ../images/addLabelIcon.png + ../images/renameListIcon.png ../images/lists/default_0.png ../images/lists/default_1.png diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 1dec58c2..0a8bf194 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -738,7 +738,7 @@ void LibraryWindow::createActions() renameListAction->setData(RENAME_LIST_ACTION_YL); renameListAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RENAME_LIST_ACTION_YL)); renameListAction->setToolTip(tr("Rename any selected labels or lists")); - renameListAction->setIcon(QIcon(":/images/addLabelIcon.png")); + renameListAction->setIcon(QIcon(":/images/renameListIcon.png")); //disable actions disableAllActions(); diff --git a/images/renameListIcon.png b/images/renameListIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..ec8098dac2add4da8748c48fe900d380f1b6a435 GIT binary patch literal 315 zcmV-B0mS}^P)7)n&$(l z^FZ1FS)7qb%^*$Zq1+EZ><9!Gh;jkQ<~MKNY+tl!(H*Fe07Mw#9VQ~2oggA2BH`rZ zBmpzz=+UD;fG+rf*9$Ps$YM{PJo(bq)pg_Y<;!b;+)j`f3$dC(-~|u>HAe!OcW}l6 zF3mt^zbGv&orA0y!wdK{*VNQZfH@nh0ccT0lx7q!+`W5u^0aBwZjhoG#Q0!xN_ynC&*Dn&;VF4K