renaming lists working for labels

This commit is contained in:
Luis Ángel San Martín 2014-11-11 22:57:54 +01:00
parent 32c275621d
commit 73ac56d0b5
8 changed files with 91 additions and 9 deletions

View File

@ -16,6 +16,11 @@ QVariant ListItem::data(int column) const
return itemData.at(column);
}
qulonglong ListItem::getId() const
{
return 0;
}
//------------------------------------------------------
SpecialListItem::SpecialListItem(const QList<QVariant> &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<QVariant> &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)

View File

@ -14,7 +14,7 @@ public:
int columnCount();
virtual QIcon getIcon() const = 0;
QVariant data(int column) const;
virtual qulonglong getId() const;
QList<QVariant> itemData;
};
@ -34,8 +34,11 @@ class LabelItem : public ListItem
public:
LabelItem(const QList<QVariant> &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<ReadingListItem*> childItems;

View File

@ -26,8 +26,6 @@ int ReadingListModel::rowCount(const QModelIndex &parent) const
{
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
QLOG_DEBUG() << item->itemData;
if(typeid(*item) == typeid(ReadingListItem))
{
ReadingListItem * item = static_cast<ReadingListItem*>(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<ListItem*>(mi.internalPointer());
if(typeid(*item) == typeid(ReadingListItem))
{
ReadingListItem * rli = static_cast<ReadingListItem*>(item);
rli->setName(name);
DBHelper::renameList(item->getId(), name, db);
}
else if(typeid(*item) == typeid(LabelItem))
{
LabelItem * li = static_cast<LabelItem*>(item);
li->setName(name);
DBHelper::renameLabel(item->getId(), name, db);
}
emit dataChanged(index(mi.row(), 0), index(mi.row(), 0));

View File

@ -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)
{

View File

@ -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<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
static QList<ComicDB> getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db);

View File

@ -25,6 +25,7 @@
<file alias="images/iconSearch.png">../images/iconSearchNew.png</file>
<file alias="images/clearSearch.png">../images/clearSearchNew.png</file>
<file>../images/addLabelIcon.png</file>
<file>../images/renameListIcon.png</file>
<!--reading lists-->
<file>../images/lists/default_0.png</file>
<file>../images/lists/default_1.png</file>

View File

@ -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();

BIN
images/renameListIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B