mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 00:58:32 -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 ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"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, "
|
||||
"finished BOOLEAN DEFAULT 0, "
|
||||
"completed BOOLEAN DEFAULT 1, "
|
||||
|
@ -122,6 +122,15 @@ void ReadingListItem::appendChild(ReadingListItem *item)
|
||||
childItems.append(item);
|
||||
else
|
||||
{
|
||||
if(item->parent->getId()==0) //sort by name, top level child
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*ReadingListItem * last = childItems.back();
|
||||
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();
|
||||
@ -163,6 +172,11 @@ void ReadingListItem::setName(const QString &name)
|
||||
itemData[0] = name;
|
||||
}
|
||||
|
||||
QList<ReadingListItem *> ReadingListItem::children()
|
||||
{
|
||||
return childItems;
|
||||
}
|
||||
|
||||
int ReadingListItem::row() const
|
||||
{
|
||||
if (parent)
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
qulonglong getId() const;
|
||||
QString name() const;
|
||||
void setName(const QString & name);
|
||||
QList<ReadingListItem*> children();
|
||||
|
||||
private:
|
||||
QList<ReadingListItem*> childItems;
|
||||
|
@ -156,7 +156,7 @@ QModelIndex ReadingListModel::parent(const QModelIndex &index) const
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void ReadingListModel::setupModelData(QString path)
|
||||
void ReadingListModel::setupReadingListsData(QString path)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
@ -194,12 +194,48 @@ void ReadingListModel::addNewLabel(const QString &name, YACReader::LabelColors c
|
||||
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)
|
||||
{
|
||||
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||
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)
|
||||
{
|
||||
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);
|
||||
rli->setName(name);
|
||||
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))
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
emit dataChanged(index(mi.row(), 0), index(mi.row(), 0));
|
||||
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
@ -255,19 +297,42 @@ void ReadingListModel::cleanAll()
|
||||
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 *> 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()) {
|
||||
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
|
||||
@ -307,14 +372,19 @@ QList<LabelItem *> ReadingListModel::setupLabels(QSqlDatabase & db)
|
||||
void ReadingListModel::setupReadingLists(QSqlDatabase & db)
|
||||
{
|
||||
//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
|
||||
ReadingListItem * node1;
|
||||
rootItem->appendChild(node1 = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "My reading list" << "atr"));
|
||||
rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "X timeline" << "atr"));
|
||||
setupReadingListsData(selectQuery,rootItem);
|
||||
|
||||
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)
|
||||
|
@ -32,9 +32,12 @@ public:
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
|
||||
//Convenience methods
|
||||
void setupModelData(QString path);
|
||||
void setupReadingListsData(QString path);
|
||||
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 isReadingList(const QModelIndex & mi);
|
||||
QString name(const QModelIndex & mi);
|
||||
void rename(const QModelIndex & mi, const QString & name);
|
||||
|
||||
@ -45,7 +48,7 @@ public slots:
|
||||
|
||||
private:
|
||||
void cleanAll();
|
||||
void setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
||||
void setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
||||
QList<SpecialListItem *> setupSpecialLists(QSqlDatabase &db);
|
||||
QList<LabelItem *> setupLabels(QSqlDatabase &db);
|
||||
void setupReadingLists(QSqlDatabase &db);
|
||||
|
@ -389,6 +389,16 @@ qulonglong DBHelper::insertLabel(const QString &name, YACReader::LabelColors col
|
||||
query.exec();
|
||||
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
|
||||
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(ComicDB * comic, QSqlDatabase & db);
|
||||
static qulonglong insertLabel(const QString & name, YACReader::LabelColors color , QSqlDatabase & db);
|
||||
static qulonglong insertReadingList(const QString & name, QSqlDatabase & db);
|
||||
//updates
|
||||
static void update(qulonglong libraryId, ComicInfo & comicInfo);
|
||||
static void update(ComicDB * comics, QSqlDatabase & db);
|
||||
|
@ -1212,7 +1212,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
||||
foldersModel->setupModelData(path);
|
||||
foldersView->setModel(foldersModel);
|
||||
|
||||
listsModel->setupModelData(path);
|
||||
listsModel->setupReadingListsData(path);
|
||||
listsView->setModel(listsModel);
|
||||
|
||||
if(foldersModel->rowCount(QModelIndex())>0)
|
||||
@ -1628,7 +1628,20 @@ void LibraryWindow::errorDeletingFolder()
|
||||
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user