mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
implemented 'add reading list'
This commit is contained in:
parent
3be1e5d0d1
commit
fdf0a2d047
@ -246,7 +246,7 @@ bool DataBaseManagement::createV8Tables(QSqlDatabase &database)
|
|||||||
queryReadingList.prepare("CREATE TABLE reading_list ("
|
queryReadingList.prepare("CREATE TABLE reading_list ("
|
||||||
"id INTEGER PRIMARY KEY, "
|
"id INTEGER PRIMARY KEY, "
|
||||||
"parentId INTEGER, "
|
"parentId INTEGER, "
|
||||||
"ordering INTEGER, " //only use it if the parentId is NULL
|
"ordering INTEGER DEFAULT 0, " //only use it if the parentId is NULL
|
||||||
"name TEXT NOT NULL, "
|
"name TEXT NOT NULL, "
|
||||||
"finished BOOLEAN DEFAULT 0, "
|
"finished BOOLEAN DEFAULT 0, "
|
||||||
"completed BOOLEAN DEFAULT 1, "
|
"completed BOOLEAN DEFAULT 1, "
|
||||||
|
@ -122,6 +122,15 @@ void ReadingListItem::appendChild(ReadingListItem *item)
|
|||||||
childItems.append(item);
|
childItems.append(item);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(item->parent->getId()==0) //sort by name, top level child
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*ReadingListItem * last = childItems.back();
|
/*ReadingListItem * last = childItems.back();
|
||||||
QString nameLast = last->data(1).toString(); //TODO usar info name si est<73> disponible, sino el nombre del fichero.....
|
QString nameLast = last->data(1).toString(); //TODO usar info name si est<73> disponible, sino el nombre del fichero.....
|
||||||
QString nameCurrent = item->data(1).toString();
|
QString nameCurrent = item->data(1).toString();
|
||||||
@ -163,6 +172,11 @@ void ReadingListItem::setName(const QString &name)
|
|||||||
itemData[0] = name;
|
itemData[0] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ReadingListItem *> ReadingListItem::children()
|
||||||
|
{
|
||||||
|
return childItems;
|
||||||
|
}
|
||||||
|
|
||||||
int ReadingListItem::row() const
|
int ReadingListItem::row() const
|
||||||
{
|
{
|
||||||
if (parent)
|
if (parent)
|
||||||
|
@ -56,6 +56,7 @@ public:
|
|||||||
qulonglong getId() const;
|
qulonglong getId() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString & name);
|
void setName(const QString & name);
|
||||||
|
QList<ReadingListItem*> children();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ReadingListItem*> childItems;
|
QList<ReadingListItem*> childItems;
|
||||||
|
@ -156,7 +156,7 @@ QModelIndex ReadingListModel::parent(const QModelIndex &index) const
|
|||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadingListModel::setupModelData(QString path)
|
void ReadingListModel::setupReadingListsData(QString path)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
@ -194,12 +194,48 @@ void ReadingListModel::addNewLabel(const QString &name, YACReader::LabelColors c
|
|||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadingListModel::addReadingList(const QString &name)
|
||||||
|
{
|
||||||
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
|
|
||||||
|
qulonglong id = DBHelper::insertReadingList(name,db);
|
||||||
|
ReadingListItem * newItem;
|
||||||
|
rootItem->appendChild(newItem = new ReadingListItem(QList<QVariant>()
|
||||||
|
<< name
|
||||||
|
<< id
|
||||||
|
<< false
|
||||||
|
<< true
|
||||||
|
<< 0));
|
||||||
|
|
||||||
|
items.insert(id, newItem);
|
||||||
|
|
||||||
|
int pos = rootItem->children().indexOf(newItem);
|
||||||
|
|
||||||
|
pos += specialLists.count()+1+labels.count()+labels.count()>0?1:0;
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(), pos, pos);
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReadingListModel::addReadingListAt(const QString &name, const QModelIndex &mi)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool ReadingListModel::isEditable(const QModelIndex &mi)
|
bool ReadingListModel::isEditable(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||||
return typeid(*item) != typeid(SpecialListItem);
|
return typeid(*item) != typeid(SpecialListItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ReadingListModel::isReadingList(const QModelIndex &mi)
|
||||||
|
{
|
||||||
|
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||||
|
return typeid(*item) == typeid(ReadingListItem);
|
||||||
|
}
|
||||||
|
|
||||||
QString ReadingListModel::name(const QModelIndex &mi)
|
QString ReadingListModel::name(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
return data(mi,Qt::DisplayRole).toString();
|
return data(mi,Qt::DisplayRole).toString();
|
||||||
@ -219,16 +255,22 @@ void ReadingListModel::rename(const QModelIndex &mi, const QString &name)
|
|||||||
ReadingListItem * rli = static_cast<ReadingListItem*>(item);
|
ReadingListItem * rli = static_cast<ReadingListItem*>(item);
|
||||||
rli->setName(name);
|
rli->setName(name);
|
||||||
DBHelper::renameList(item->getId(), name, db);
|
DBHelper::renameList(item->getId(), name, db);
|
||||||
|
|
||||||
|
if(rli->parent->getId()!=0)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//move row depending on the name
|
||||||
|
}else
|
||||||
|
emit dataChanged(index(mi.row(), 0), index(mi.row(), 0));
|
||||||
}
|
}
|
||||||
else if(typeid(*item) == typeid(LabelItem))
|
else if(typeid(*item) == typeid(LabelItem))
|
||||||
{
|
{
|
||||||
LabelItem * li = static_cast<LabelItem*>(item);
|
LabelItem * li = static_cast<LabelItem*>(item);
|
||||||
li->setName(name);
|
li->setName(name);
|
||||||
DBHelper::renameLabel(item->getId(), name, db);
|
DBHelper::renameLabel(item->getId(), name, db);
|
||||||
|
emit dataChanged(index(mi.row(), 0), index(mi.row(), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index(mi.row(), 0), index(mi.row(), 0));
|
|
||||||
|
|
||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,19 +297,42 @@ void ReadingListModel::cleanAll()
|
|||||||
rootItem = 0;
|
rootItem = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadingListModel::setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent)
|
void ReadingListModel::setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent)
|
||||||
{
|
{
|
||||||
|
items.insert(parent->getId(),parent);
|
||||||
|
|
||||||
|
while (sqlquery.next())
|
||||||
|
{
|
||||||
|
QSqlRecord record = sqlquery.record();
|
||||||
|
ReadingListItem * rli = new ReadingListItem(QList<QVariant>()
|
||||||
|
<< record.value("name")
|
||||||
|
<< record.value("id")
|
||||||
|
<< record.value("finished")
|
||||||
|
<< record.value("completed")
|
||||||
|
<< record.value("ordering"));
|
||||||
|
|
||||||
|
ReadingListItem * currentParent;
|
||||||
|
if(record.value("parentId").isNull())
|
||||||
|
currentParent = rootItem;
|
||||||
|
else
|
||||||
|
currentParent = items.value(record.value("parentId").toULongLong());
|
||||||
|
|
||||||
|
parent->appendChild(rli);
|
||||||
|
|
||||||
|
items.insert(rli->getId(),rli);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<SpecialListItem *> ReadingListModel::setupSpecialLists(QSqlDatabase & db)
|
QList<SpecialListItem *> ReadingListModel::setupSpecialLists(QSqlDatabase & db)
|
||||||
{
|
{
|
||||||
QList<SpecialListItem *> list;
|
QList<SpecialListItem *> list;
|
||||||
|
|
||||||
QSqlQuery selectQuery("SELECT * FROM default_reading_list ORDER BY id",db);
|
QSqlQuery selectQuery("SELECT * FROM default_reading_list ORDER BY id,name",db);
|
||||||
while(selectQuery.next()) {
|
while(selectQuery.next()) {
|
||||||
QSqlRecord record = selectQuery.record();
|
QSqlRecord record = selectQuery.record();
|
||||||
list << new SpecialListItem(QList<QVariant>() << record.value("name") << record.value("id"));
|
list << new SpecialListItem(QList<QVariant>()
|
||||||
|
<< record.value("name")
|
||||||
|
<< record.value("id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reading after Favorites, Why? Because I want :P
|
//Reading after Favorites, Why? Because I want :P
|
||||||
@ -307,14 +372,19 @@ QList<LabelItem *> ReadingListModel::setupLabels(QSqlDatabase & db)
|
|||||||
void ReadingListModel::setupReadingLists(QSqlDatabase & db)
|
void ReadingListModel::setupReadingLists(QSqlDatabase & db)
|
||||||
{
|
{
|
||||||
//setup root item
|
//setup root item
|
||||||
rootItem = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "ROOT" << "atr");
|
rootItem = new ReadingListItem(QList<QVariant>() << "ROOT" << 0 << true << false);
|
||||||
|
|
||||||
|
QSqlQuery selectQuery("select * from reading_list order by parentId,name",db);
|
||||||
|
|
||||||
//setup reading lists
|
//setup reading lists
|
||||||
ReadingListItem * node1;
|
setupReadingListsData(selectQuery,rootItem);
|
||||||
rootItem->appendChild(node1 = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "My reading list" << "atr"));
|
|
||||||
rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "X timeline" << "atr"));
|
|
||||||
|
|
||||||
node1->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "sublist" << "atr",node1));
|
//TEST
|
||||||
|
// ReadingListItem * node1;
|
||||||
|
// rootItem->appendChild(node1 = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "My reading list" << "atr"));
|
||||||
|
// rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "X timeline" << "atr"));
|
||||||
|
|
||||||
|
// node1->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "sublist" << "atr",node1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReadingListModel::addLabelIntoList(LabelItem *item)
|
int ReadingListModel::addLabelIntoList(LabelItem *item)
|
||||||
|
@ -32,9 +32,12 @@ public:
|
|||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
|
|
||||||
//Convenience methods
|
//Convenience methods
|
||||||
void setupModelData(QString path);
|
void setupReadingListsData(QString path);
|
||||||
void addNewLabel(const QString & name, YACReader::LabelColors color);
|
void addNewLabel(const QString & name, YACReader::LabelColors color);
|
||||||
|
void addReadingList(const QString & name);//top level reading list
|
||||||
|
void addReadingListAt(const QString & name, const QModelIndex & mi);
|
||||||
bool isEditable(const QModelIndex & mi);
|
bool isEditable(const QModelIndex & mi);
|
||||||
|
bool isReadingList(const QModelIndex & mi);
|
||||||
QString name(const QModelIndex & mi);
|
QString name(const QModelIndex & mi);
|
||||||
void rename(const QModelIndex & mi, const QString & name);
|
void rename(const QModelIndex & mi, const QString & name);
|
||||||
|
|
||||||
@ -45,7 +48,7 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void cleanAll();
|
void cleanAll();
|
||||||
void setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
void setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
||||||
QList<SpecialListItem *> setupSpecialLists(QSqlDatabase &db);
|
QList<SpecialListItem *> setupSpecialLists(QSqlDatabase &db);
|
||||||
QList<LabelItem *> setupLabels(QSqlDatabase &db);
|
QList<LabelItem *> setupLabels(QSqlDatabase &db);
|
||||||
void setupReadingLists(QSqlDatabase &db);
|
void setupReadingLists(QSqlDatabase &db);
|
||||||
|
@ -389,6 +389,16 @@ qulonglong DBHelper::insertLabel(const QString &name, YACReader::LabelColors col
|
|||||||
query.exec();
|
query.exec();
|
||||||
return query.lastInsertId().toULongLong();
|
return query.lastInsertId().toULongLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qulonglong DBHelper::insertReadingList(const QString &name, QSqlDatabase &db)
|
||||||
|
{
|
||||||
|
QSqlQuery query(db);
|
||||||
|
query.prepare("INSERT INTO reading_list (name) "
|
||||||
|
"VALUES (:name)");
|
||||||
|
query.bindValue(":name", name);
|
||||||
|
query.exec();
|
||||||
|
return query.lastInsertId().toULongLong();
|
||||||
|
}
|
||||||
//queries
|
//queries
|
||||||
QList<LibraryItem *> DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort)
|
QList<LibraryItem *> DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
static qulonglong insert(Folder * folder, QSqlDatabase & db);
|
static qulonglong insert(Folder * folder, QSqlDatabase & db);
|
||||||
static qulonglong insert(ComicDB * comic, QSqlDatabase & db);
|
static qulonglong insert(ComicDB * comic, QSqlDatabase & db);
|
||||||
static qulonglong insertLabel(const QString & name, YACReader::LabelColors color , QSqlDatabase & db);
|
static qulonglong insertLabel(const QString & name, YACReader::LabelColors color , QSqlDatabase & db);
|
||||||
|
static qulonglong insertReadingList(const QString & name, QSqlDatabase & db);
|
||||||
//updates
|
//updates
|
||||||
static void update(qulonglong libraryId, ComicInfo & comicInfo);
|
static void update(qulonglong libraryId, ComicInfo & comicInfo);
|
||||||
static void update(ComicDB * comics, QSqlDatabase & db);
|
static void update(ComicDB * comics, QSqlDatabase & db);
|
||||||
|
@ -1212,7 +1212,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
foldersModel->setupModelData(path);
|
foldersModel->setupModelData(path);
|
||||||
foldersView->setModel(foldersModel);
|
foldersView->setModel(foldersModel);
|
||||||
|
|
||||||
listsModel->setupModelData(path);
|
listsModel->setupReadingListsData(path);
|
||||||
listsView->setModel(listsModel);
|
listsView->setModel(listsModel);
|
||||||
|
|
||||||
if(foldersModel->rowCount(QModelIndex())>0)
|
if(foldersModel->rowCount(QModelIndex())>0)
|
||||||
@ -1628,7 +1628,20 @@ void LibraryWindow::errorDeletingFolder()
|
|||||||
|
|
||||||
void LibraryWindow::addNewReadingList()
|
void LibraryWindow::addNewReadingList()
|
||||||
{
|
{
|
||||||
|
bool ok;
|
||||||
|
QString newListName = QInputDialog::getText(this, tr("Add new reading lists"),
|
||||||
|
tr("List name:"), QLineEdit::Normal,
|
||||||
|
"", &ok);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes();
|
||||||
|
if(selectedLists.isEmpty() || listsModel->isReadingList(selectedLists.at(0)))
|
||||||
|
listsModel->addReadingList(newListName); //top level
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listsModel->addReadingListAt(newListName,selectedLists.at(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryWindow::deleteSelectedReadingList()
|
void LibraryWindow::deleteSelectedReadingList()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user