mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
merged
This commit is contained in:
commit
a4cea98589
@ -340,14 +340,30 @@ void ComicModel::setupReadingListModelData(unsigned long long parentReadingList,
|
||||
_databasePath = databasePath;
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||
{
|
||||
QSqlQuery selectQuery(db);
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"INNER JOIN comic_reading_list crl ON (c.id == crl.comic_id) "
|
||||
"WHERE crl.reading_list_id = :parentReadingList");
|
||||
selectQuery.bindValue(":parentReadingList", parentReadingList);
|
||||
selectQuery.exec();
|
||||
setupModelData(selectQuery);
|
||||
QList<qulonglong> ids;
|
||||
ids << parentReadingList;
|
||||
|
||||
QSqlQuery subfolders(db);
|
||||
subfolders.prepare("SELECT id "
|
||||
"FROM reading_list "
|
||||
"WHERE parentId = :parentId");
|
||||
subfolders.bindValue(":parentId", parentReadingList);
|
||||
subfolders.exec();
|
||||
while(subfolders.next())
|
||||
ids << subfolders.record().value(0).toULongLong();
|
||||
|
||||
foreach(qulonglong id, ids)
|
||||
{
|
||||
QSqlQuery selectQuery(db);
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"INNER JOIN comic_reading_list crl ON (c.id == crl.comic_id) "
|
||||
"WHERE crl.reading_list_id = :parentReadingList");
|
||||
selectQuery.bindValue(":parentReadingList", id);
|
||||
selectQuery.exec();
|
||||
setupModelData(selectQuery);
|
||||
}
|
||||
|
||||
}
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
@ -228,7 +228,10 @@ bool DataBaseManagement::createV8Tables(QSqlDatabase &database)
|
||||
//8.0> tables
|
||||
//LABEL
|
||||
QSqlQuery queryLabel(database);
|
||||
queryLabel.prepare("CREATE TABLE label (id INTEGER PRIMARY KEY, name TEXT NOT NULL, color TEXT NOT NULL, ordering INTEGER NOT NULL)"); //order depends on the color
|
||||
queryLabel.prepare("CREATE TABLE label (id INTEGER PRIMARY KEY, "
|
||||
"name TEXT NOT NULL, "
|
||||
"color TEXT NOT NULL, "
|
||||
"ordering INTEGER NOT NULL)"); //order depends on the color
|
||||
success = success && queryLabel.exec();
|
||||
|
||||
//COMIC LABEL
|
||||
|
@ -31,18 +31,18 @@ SpecialListItem::SpecialListItem(const QList<QVariant> &data)
|
||||
|
||||
QIcon SpecialListItem::getIcon() const
|
||||
{
|
||||
if(itemData.count()>1)
|
||||
if(itemData.count()>Id)
|
||||
{
|
||||
QString id = itemData.at(1).toString();
|
||||
QString id = itemData.at(Id).toString();
|
||||
return YACReader::noHighlightedIcon(QString(":/images/lists/default_%1.png").arg(id));
|
||||
}
|
||||
}
|
||||
|
||||
ReadingListModel::TypeSpecialList SpecialListItem::getType() const
|
||||
{
|
||||
if(itemData.count()>1)
|
||||
if(itemData.count()>Id)
|
||||
{
|
||||
int id = itemData.at(1).toInt();
|
||||
int id = itemData.at(Id).toInt();
|
||||
return (ReadingListModel::TypeSpecialList)id;
|
||||
}
|
||||
}
|
||||
@ -57,39 +57,42 @@ LabelItem::LabelItem(const QList<QVariant> &data)
|
||||
|
||||
QIcon LabelItem::getIcon() const
|
||||
{
|
||||
if(itemData.count()>1)
|
||||
if(itemData.count()>Color)
|
||||
{
|
||||
QString color = itemData.at(1).toString();
|
||||
QString color = itemData.at(Color).toString();
|
||||
return YACReader::noHighlightedIcon(QString(":/images/lists/label_%1.png").arg(color).toLower());
|
||||
}
|
||||
}
|
||||
|
||||
YACReader::LabelColors LabelItem::colorid() const
|
||||
{
|
||||
if(itemData.count()>3)
|
||||
if(itemData.count()>Ordering)
|
||||
{
|
||||
return YACReader::LabelColors(itemData.at(3).toInt());
|
||||
return YACReader::LabelColors(itemData.at(Ordering).toInt());
|
||||
}
|
||||
}
|
||||
|
||||
QString LabelItem::name() const
|
||||
{
|
||||
if(itemData.count()>0)
|
||||
if(itemData.count()>Name)
|
||||
{
|
||||
return itemData.at(0).toString();
|
||||
return itemData.at(Name).toString();
|
||||
}
|
||||
}
|
||||
|
||||
void LabelItem::setName(const QString &name)
|
||||
{
|
||||
itemData[0] = name;
|
||||
if(itemData.count()>Name)
|
||||
{
|
||||
itemData[Name] = name;
|
||||
}
|
||||
}
|
||||
|
||||
qulonglong LabelItem::getId() const
|
||||
{
|
||||
if(itemData.count()>2)
|
||||
if(itemData.count()>Id)
|
||||
{
|
||||
return YACReader::LabelColors(itemData.at(2).toULongLong());
|
||||
return YACReader::LabelColors(itemData.at(Id).toULongLong());
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,9 +107,9 @@ ReadingListItem::ReadingListItem(const QList<QVariant> &data, ReadingListItem *p
|
||||
QIcon ReadingListItem::getIcon() const
|
||||
{
|
||||
if(parent->getId() == 0)
|
||||
return YACReader::noHighlightedIcon(":/images/lists/list.png");
|
||||
return YACReader::noHighlightedIcon(":/images/lists/list.png"); //top level list
|
||||
else
|
||||
return YACReader::noHighlightedIcon(":/images/folder.png");
|
||||
return YACReader::noHighlightedIcon(":/images/folder.png"); //sublist
|
||||
}
|
||||
|
||||
int ReadingListItem::childCount() const
|
||||
@ -168,23 +171,32 @@ void ReadingListItem::removeChild(ReadingListItem *item)
|
||||
|
||||
qulonglong ReadingListItem::getId() const
|
||||
{
|
||||
if(itemData.count()>1)
|
||||
{
|
||||
return itemData.at(1).toULongLong();
|
||||
}
|
||||
if(itemData.count()>Id)
|
||||
return itemData.at(Id).toULongLong();
|
||||
}
|
||||
|
||||
QString ReadingListItem::name() const
|
||||
{
|
||||
if(itemData.count()>0)
|
||||
{
|
||||
return itemData.at(0).toString();
|
||||
}
|
||||
if(itemData.count()>Name)
|
||||
return itemData.at(Name).toString();
|
||||
}
|
||||
|
||||
void ReadingListItem::setName(const QString &name)
|
||||
{
|
||||
itemData[0] = name;
|
||||
if(itemData.count()>Name)
|
||||
itemData[Name] = name;
|
||||
}
|
||||
|
||||
int ReadingListItem::getOrdering() const
|
||||
{
|
||||
if(itemData.count()>Ordering)
|
||||
return itemData[Ordering].toInt();
|
||||
}
|
||||
|
||||
void ReadingListItem::setOrdering(const int ordering)
|
||||
{
|
||||
if(itemData.count()>Ordering)
|
||||
itemData[Ordering] = ordering;
|
||||
}
|
||||
|
||||
QList<ReadingListItem *> ReadingListItem::children()
|
||||
|
@ -27,6 +27,12 @@ public:
|
||||
SpecialListItem(const QList<QVariant> &data);
|
||||
QIcon getIcon() const;
|
||||
ReadingListModel::TypeSpecialList getType() const;
|
||||
private:
|
||||
enum DataIndexes {
|
||||
Name,
|
||||
Id
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
@ -41,6 +47,14 @@ public:
|
||||
void setName(const QString & name);
|
||||
qulonglong getId() const;
|
||||
|
||||
|
||||
private:
|
||||
enum DataIndexes {
|
||||
Name,
|
||||
Color,
|
||||
Id,
|
||||
Ordering
|
||||
};
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
@ -59,12 +73,21 @@ public:
|
||||
qulonglong getId() const;
|
||||
QString name() const;
|
||||
void setName(const QString & name);
|
||||
|
||||
int getOrdering() const;
|
||||
void setOrdering(const int ordering);
|
||||
QList<ReadingListItem*> children();
|
||||
|
||||
private:
|
||||
QList<ReadingListItem*> childItems;
|
||||
|
||||
enum DataIndexes {
|
||||
Name,
|
||||
Id,
|
||||
Finished,
|
||||
Completed,
|
||||
Ordering
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
|
@ -369,6 +369,23 @@ bool ReadingListModel::isReadingList(const QModelIndex &mi)
|
||||
return typeid(*item) == typeid(ReadingListItem);
|
||||
}
|
||||
|
||||
bool ReadingListModel::isReadingSubList(const QModelIndex &mi)
|
||||
{
|
||||
if(!mi.isValid())
|
||||
return false;
|
||||
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * readingListItem = static_cast<ReadingListItem *>(item);
|
||||
if(readingListItem->parent == rootItem)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ReadingListModel::name(const QModelIndex &mi)
|
||||
{
|
||||
return data(mi,Qt::DisplayRole).toString();
|
||||
@ -497,7 +514,7 @@ QList<SpecialListItem *> ReadingListModel::setupSpecialLists(QSqlDatabase & db)
|
||||
<< record.value("id"));
|
||||
}
|
||||
|
||||
//Reading after Favorites, Why? Because I want :P
|
||||
//Reading after Favorites, Why? Because I want to :P
|
||||
list.insert(1,new SpecialListItem(QList<QVariant>() << "Reading" << 0));
|
||||
|
||||
return list;
|
||||
@ -508,7 +525,11 @@ void ReadingListModel::setupLabels(QSqlDatabase & db)
|
||||
QSqlQuery selectQuery("SELECT * FROM label ORDER BY ordering,name",db); //TODO add some kind of
|
||||
while(selectQuery.next()) {
|
||||
QSqlRecord record = selectQuery.record();
|
||||
addLabelIntoList(new LabelItem(QList<QVariant>() << record.value("name") << record.value("color") << record.value("id") << record.value("ordering")));
|
||||
addLabelIntoList(new LabelItem(QList<QVariant>()
|
||||
<< record.value("name")
|
||||
<< record.value("color")
|
||||
<< record.value("id")
|
||||
<< record.value("ordering")));
|
||||
}
|
||||
|
||||
//TEST
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
void addReadingListAt(const QString & name, const QModelIndex & mi);
|
||||
bool isEditable(const QModelIndex & mi);
|
||||
bool isReadingList(const QModelIndex & mi);
|
||||
bool isReadingSubList(const QModelIndex & mi);
|
||||
QString name(const QModelIndex & mi);
|
||||
void rename(const QModelIndex & mi, const QString & name);
|
||||
void deleteItem(const QModelIndex & mi);
|
||||
|
@ -1560,21 +1560,24 @@ void LibraryWindow::errorDeletingFolder()
|
||||
|
||||
void LibraryWindow::addNewReadingList()
|
||||
{
|
||||
bool ok;
|
||||
QString newListName = QInputDialog::getText(this, tr("Add new reading lists"),
|
||||
tr("List name:"), QLineEdit::Normal,
|
||||
"", &ok);
|
||||
QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes();
|
||||
QModelIndex sourceMI;
|
||||
if(!selectedLists.isEmpty())
|
||||
sourceMI = listsModelProxy->mapToSource(selectedLists.at(0));
|
||||
|
||||
if (ok) {
|
||||
QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes();
|
||||
QModelIndex sourceMI;
|
||||
if(!selectedLists.isEmpty())
|
||||
sourceMI = listsModelProxy->mapToSource(selectedLists.at(0));
|
||||
if(selectedLists.isEmpty() || !listsModel->isReadingList(sourceMI))
|
||||
listsModel->addReadingList(newListName); //top level
|
||||
else
|
||||
{
|
||||
listsModel->addReadingListAt(newListName,sourceMI); //sublist
|
||||
if(selectedLists.isEmpty() || !listsModel->isReadingSubList(sourceMI) )
|
||||
{
|
||||
bool ok;
|
||||
QString newListName = QInputDialog::getText(this, tr("Add new reading lists"),
|
||||
tr("List name:"), QLineEdit::Normal,
|
||||
"", &ok);
|
||||
if (ok) {
|
||||
if(selectedLists.isEmpty() || !listsModel->isReadingList(sourceMI))
|
||||
listsModel->addReadingList(newListName); //top level
|
||||
else
|
||||
{
|
||||
listsModel->addReadingListAt(newListName,sourceMI); //sublist
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user