mirror of
https://github.com/YACReader/yacreader
synced 2025-12-09 10:42:53 -05:00
Format code using clang-format
This commit is contained in:
@ -5,43 +5,41 @@
|
||||
|
||||
//! [0]
|
||||
ComicItem::ComicItem(const QList<QVariant> &data)
|
||||
|
||||
|
||||
{
|
||||
itemData = data;
|
||||
itemData = data;
|
||||
}
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
ComicItem::~ComicItem()
|
||||
{
|
||||
|
||||
}
|
||||
//! [1]
|
||||
|
||||
|
||||
//! [5]
|
||||
int ComicItem::columnCount() const
|
||||
{
|
||||
return itemData.count();
|
||||
return itemData.count();
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
QVariant ComicItem::data(int column) const
|
||||
{
|
||||
return itemData.value(column);
|
||||
return itemData.value(column);
|
||||
}
|
||||
//! [6]
|
||||
|
||||
void ComicItem::setData(int column,const QVariant & value)
|
||||
void ComicItem::setData(int column, const QVariant &value)
|
||||
{
|
||||
itemData[column] = value;
|
||||
itemData[column] = value;
|
||||
}
|
||||
|
||||
//! [8]
|
||||
int ComicItem::row() const
|
||||
{
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
//! [8]
|
||||
|
||||
@ -7,20 +7,18 @@
|
||||
//! [0]
|
||||
class ComicItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ComicItem(const QList<QVariant> &data);
|
||||
~ComicItem();
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
void setData(int column,const QVariant & value);
|
||||
int row() const;
|
||||
//unsigned long long int id; //TODO sustituir por una clase adecuada
|
||||
//Comic comic;
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
void setData(int column, const QVariant &value);
|
||||
int row() const;
|
||||
//unsigned long long int id; //TODO sustituir por una clase adecuada
|
||||
//Comic comic;
|
||||
private:
|
||||
QList<QVariant> itemData;
|
||||
|
||||
|
||||
QList<QVariant> itemData;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ using namespace YACReader;
|
||||
//! [0]
|
||||
class ComicModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Columns {
|
||||
@ -64,59 +64,57 @@ public:
|
||||
ReadingList
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
ComicModel(QObject *parent = 0);
|
||||
ComicModel( QSqlQuery &sqlquery, QObject *parent = 0);
|
||||
ComicModel(QSqlQuery &sqlquery, QObject *parent = 0);
|
||||
~ComicModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
bool canBeResorted();
|
||||
QMimeData * mimeData(const QModelIndexList &indexes) const;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
QStringList mimeTypes() const;
|
||||
|
||||
void setupFolderModelData(unsigned long long int parentFolder,const QString & databasePath);
|
||||
void setupLabelModelData(unsigned long long int parentLabel, const QString & databasePath);
|
||||
void setupReadingListModelData(unsigned long long int parentReadingList, const QString & databasePath);
|
||||
void setupFavoritesModelData(const QString & databasePath);
|
||||
void setupReadingModelData(const QString & databasePath);
|
||||
void setupFolderModelData(unsigned long long int parentFolder, const QString &databasePath);
|
||||
void setupLabelModelData(unsigned long long int parentLabel, const QString &databasePath);
|
||||
void setupReadingListModelData(unsigned long long int parentReadingList, const QString &databasePath);
|
||||
void setupFavoritesModelData(const QString &databasePath);
|
||||
void setupReadingModelData(const QString &databasePath);
|
||||
//configures the model for showing the comics matching the filter criteria.
|
||||
void setupModelData(const SearchModifiers modifier, const QString & filter, const QString & databasePath);
|
||||
void setupModelData(const SearchModifiers modifier, const QString &filter, const QString &databasePath);
|
||||
|
||||
//Métodos de conveniencia
|
||||
QStringList getPaths(const QString & _source);
|
||||
QString getComicPath(QModelIndex mi);
|
||||
QString getCurrentPath(){return QString(_databasePath).remove("/.yacreaderlibrary");}
|
||||
ComicDB getComic(const QModelIndex & mi); //--> para la edición
|
||||
//Métodos de conveniencia
|
||||
QStringList getPaths(const QString &_source);
|
||||
QString getComicPath(QModelIndex mi);
|
||||
QString getCurrentPath() { return QString(_databasePath).remove("/.yacreaderlibrary"); }
|
||||
ComicDB getComic(const QModelIndex &mi); //--> para la edición
|
||||
//ComicDB getComic(int row);
|
||||
QVector<YACReaderComicReadStatus> getReadList();
|
||||
QVector<YACReaderComicReadStatus> setAllComicsRead(YACReaderComicReadStatus readStatus);
|
||||
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
|
||||
QList<ComicDB> getAllComics();
|
||||
QModelIndex getIndexFromId(quint64 id);
|
||||
QVector<YACReaderComicReadStatus> getReadList();
|
||||
QVector<YACReaderComicReadStatus> setAllComicsRead(YACReaderComicReadStatus readStatus);
|
||||
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
|
||||
QList<ComicDB> getAllComics();
|
||||
QModelIndex getIndexFromId(quint64 id);
|
||||
QList<QModelIndex> getIndexesFromIds(const QList<qulonglong> &comicIds);
|
||||
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
|
||||
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
|
||||
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados
|
||||
QVector<YACReaderComicReadStatus> setComicsRead(QList<QModelIndex> list,YACReaderComicReadStatus read);
|
||||
qint64 asignNumbers(QList<QModelIndex> list,int startingNumber);
|
||||
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
|
||||
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
|
||||
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados
|
||||
QVector<YACReaderComicReadStatus> setComicsRead(QList<QModelIndex> list, YACReaderComicReadStatus read);
|
||||
qint64 asignNumbers(QList<QModelIndex> list, int startingNumber);
|
||||
//void remove(ComicDB * comic, int row);
|
||||
void removeInTransaction(int row);
|
||||
void reload(const ComicDB & comic);
|
||||
void resetComicRating(const QModelIndex & mi);
|
||||
|
||||
Q_INVOKABLE QUrl getCoverUrlPathForComicHash(const QString& hash) const;
|
||||
void removeInTransaction(int row);
|
||||
void reload(const ComicDB &comic);
|
||||
void resetComicRating(const QModelIndex &mi);
|
||||
|
||||
Q_INVOKABLE QUrl getCoverUrlPathForComicHash(const QString &hash) const;
|
||||
|
||||
void addComicsToFavorites(const QList<QModelIndex> &comicsList);
|
||||
void addComicsToLabel(const QList<QModelIndex> &comicsList, qulonglong labelId);
|
||||
@ -130,39 +128,38 @@ public:
|
||||
|
||||
bool isFavorite(const QModelIndex &index);
|
||||
|
||||
ComicModel::Mode getMode() {return mode;}
|
||||
ComicModel::Mode getMode() { return mode; }
|
||||
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
public slots:
|
||||
void remove(int row);
|
||||
void startTransaction();
|
||||
void finishTransaction();
|
||||
void updateRating(int rating, QModelIndex mi);
|
||||
void remove(int row);
|
||||
void startTransaction();
|
||||
void finishTransaction();
|
||||
void updateRating(int rating, QModelIndex mi);
|
||||
|
||||
void addComicsToFavorites(const QList<qulonglong> &comicIds);
|
||||
void addComicsToLabel(const QList<qulonglong> &comicIds, qulonglong labelId);
|
||||
void addComicsToReadingList(const QList<qulonglong> &comicIds, qulonglong readingListId);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
void setupModelData( QSqlQuery &sqlquery);
|
||||
void setupModelData(QSqlQuery &sqlquery);
|
||||
void setupModelDataForList(QSqlQuery &sqlquery);
|
||||
ComicDB _getComic(const QModelIndex & mi);
|
||||
QList<ComicItem *> _data;
|
||||
ComicDB _getComic(const QModelIndex &mi);
|
||||
QList<ComicItem *> _data;
|
||||
|
||||
QString _databasePath;
|
||||
QString _databasePath;
|
||||
|
||||
QSqlDatabase dbTransaction;
|
||||
QSqlDatabase dbTransaction;
|
||||
|
||||
bool enableResorting;
|
||||
Mode mode;
|
||||
qulonglong sourceId;
|
||||
|
||||
signals:
|
||||
void beforeReset();
|
||||
void reset();
|
||||
void beforeReset();
|
||||
void reset();
|
||||
void isEmpty();
|
||||
void searchNumResults(int);
|
||||
void resortedIndexes(QList<int>);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -9,56 +9,57 @@
|
||||
|
||||
class ComicsInfoExporter : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ComicsInfoExporter();
|
||||
void exportComicsInfo(QSqlDatabase & source, QSqlDatabase & dest);
|
||||
ComicsInfoExporter();
|
||||
void exportComicsInfo(QSqlDatabase &source, QSqlDatabase &dest);
|
||||
|
||||
private:
|
||||
void run();
|
||||
void run();
|
||||
};
|
||||
|
||||
class ComicsInfoImporter : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ComicsInfoImporter();
|
||||
void importComicsInfo(QSqlDatabase & source, QSqlDatabase & dest);
|
||||
private:
|
||||
void run();
|
||||
ComicsInfoImporter();
|
||||
void importComicsInfo(QSqlDatabase &source, QSqlDatabase &dest);
|
||||
|
||||
private:
|
||||
void run();
|
||||
};
|
||||
|
||||
class DataBaseManagement : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<QString> dataBasesList;
|
||||
static void bindString(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
||||
static void bindInt(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
||||
static void bindDouble(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
||||
static void bindValuesFromRecord(const QSqlRecord & record, QSqlQuery & query);
|
||||
QList<QString> dataBasesList;
|
||||
static void bindString(const QString &name, const QSqlRecord &record, QSqlQuery &query);
|
||||
static void bindInt(const QString &name, const QSqlRecord &record, QSqlQuery &query);
|
||||
static void bindDouble(const QString &name, const QSqlRecord &record, QSqlQuery &query);
|
||||
static void bindValuesFromRecord(const QSqlRecord &record, QSqlQuery &query);
|
||||
|
||||
static bool addColumns(const QString & tableName, const QStringList & columnDefs, const QSqlDatabase & db);
|
||||
static bool addConstraint(const QString &tableName, const QString & constraint, const QSqlDatabase & db);
|
||||
static bool addColumns(const QString &tableName, const QStringList &columnDefs, const QSqlDatabase &db);
|
||||
static bool addConstraint(const QString &tableName, const QString &constraint, const QSqlDatabase &db);
|
||||
|
||||
public:
|
||||
DataBaseManagement();
|
||||
//TreeModel * newTreeModel(QString path);
|
||||
//crea una base de datos y todas sus tablas
|
||||
static QSqlDatabase createDatabase(QString name, QString path);
|
||||
static QSqlDatabase createDatabase(QString dest);
|
||||
//carga una base de datos desde la ruta path
|
||||
static QSqlDatabase loadDatabase(QString path);
|
||||
static QSqlDatabase loadDatabaseFromFile(QString path);
|
||||
static bool createTables(QSqlDatabase & database);
|
||||
static bool createV8Tables(QSqlDatabase & database);
|
||||
DataBaseManagement();
|
||||
//TreeModel * newTreeModel(QString path);
|
||||
//crea una base de datos y todas sus tablas
|
||||
static QSqlDatabase createDatabase(QString name, QString path);
|
||||
static QSqlDatabase createDatabase(QString dest);
|
||||
//carga una base de datos desde la ruta path
|
||||
static QSqlDatabase loadDatabase(QString path);
|
||||
static QSqlDatabase loadDatabaseFromFile(QString path);
|
||||
static bool createTables(QSqlDatabase &database);
|
||||
static bool createV8Tables(QSqlDatabase &database);
|
||||
|
||||
static void exportComicsInfo(QString source, QString dest);
|
||||
static bool importComicsInfo(QString source, QString dest);
|
||||
static void exportComicsInfo(QString source, QString dest);
|
||||
static bool importComicsInfo(QString source, QString dest);
|
||||
|
||||
static QString checkValidDB(const QString & fullPath); //retorna "" si la DB es inválida ó la versión si es válida.
|
||||
static int compareVersions(const QString & v1, const QString v2); //retorna <0 si v1 < v2, 0 si v1 = v2 y >0 si v1 > v2
|
||||
static bool updateToCurrentVersion(const QString & path);
|
||||
static QString checkValidDB(const QString &fullPath); //retorna "" si la DB es inválida ó la versión si es válida.
|
||||
static int compareVersions(const QString &v1, const QString v2); //retorna <0 si v1 < v2, 0 si v1 = v2 y >0 si v1 > v2
|
||||
static bool updateToCurrentVersion(const QString &path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,65 +5,62 @@
|
||||
|
||||
FolderItem::FolderItem(const QList<QVariant> &data, FolderItem *parent)
|
||||
{
|
||||
parentItem = parent;
|
||||
itemData = data;
|
||||
parentItem = parent;
|
||||
itemData = data;
|
||||
}
|
||||
|
||||
FolderItem::~FolderItem()
|
||||
{
|
||||
qDeleteAll(childItems);
|
||||
qDeleteAll(childItems);
|
||||
}
|
||||
|
||||
void FolderItem::appendChild(FolderItem *item)
|
||||
{
|
||||
item->parentItem = this;
|
||||
item->parentItem = this;
|
||||
|
||||
if(childItems.isEmpty())
|
||||
childItems.append(item);
|
||||
else
|
||||
{
|
||||
FolderItem * 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();
|
||||
if (childItems.isEmpty())
|
||||
childItems.append(item);
|
||||
else {
|
||||
FolderItem *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();
|
||||
QList<FolderItem *>::iterator i;
|
||||
i = childItems.end();
|
||||
i--;
|
||||
while (naturalSortLessThanCI(nameCurrent,nameLast) && i != childItems.begin())
|
||||
{
|
||||
i--;
|
||||
nameLast = (*i)->data(1).toString();
|
||||
}
|
||||
if(!naturalSortLessThanCI(nameCurrent,nameLast)) //si se ha encontrado un elemento menor que current, se inserta justo despu<70>s
|
||||
childItems.insert(++i,item);
|
||||
else
|
||||
childItems.insert(i,item);
|
||||
i = childItems.end();
|
||||
i--;
|
||||
while (naturalSortLessThanCI(nameCurrent, nameLast) && i != childItems.begin()) {
|
||||
i--;
|
||||
nameLast = (*i)->data(1).toString();
|
||||
}
|
||||
if (!naturalSortLessThanCI(nameCurrent, nameLast)) //si se ha encontrado un elemento menor que current, se inserta justo despu<70>s
|
||||
childItems.insert(++i, item);
|
||||
else
|
||||
childItems.insert(i, item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//childItems.append(item);
|
||||
//childItems.append(item);
|
||||
}
|
||||
|
||||
FolderItem *FolderItem::child(int row)
|
||||
{
|
||||
return childItems.value(row);
|
||||
return childItems.value(row);
|
||||
}
|
||||
|
||||
int FolderItem::childCount() const
|
||||
{
|
||||
return childItems.count();
|
||||
return childItems.count();
|
||||
}
|
||||
|
||||
int FolderItem::columnCount() const
|
||||
{
|
||||
return itemData.count();
|
||||
return itemData.count();
|
||||
}
|
||||
|
||||
QVariant FolderItem::data(int column) const
|
||||
{
|
||||
return itemData.value(column);
|
||||
return itemData.value(column);
|
||||
}
|
||||
|
||||
void FolderItem::setData(int column, const QVariant & value)
|
||||
void FolderItem::setData(int column, const QVariant &value)
|
||||
{
|
||||
itemData[column] = value;
|
||||
}
|
||||
@ -86,18 +83,18 @@ QList<FolderItem *> FolderItem::children()
|
||||
|
||||
FolderItem *FolderItem::parent()
|
||||
{
|
||||
return parentItem;
|
||||
return parentItem;
|
||||
}
|
||||
|
||||
int FolderItem::row() const
|
||||
{
|
||||
if (parentItem)
|
||||
return parentItem->childItems.indexOf(const_cast<FolderItem*>(this));
|
||||
if (parentItem)
|
||||
return parentItem->childItems.indexOf(const_cast<FolderItem *>(this));
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
QList<QVariant> FolderItem::getData() const
|
||||
{
|
||||
return itemData;
|
||||
return itemData;
|
||||
}
|
||||
|
||||
@ -54,23 +54,24 @@ public:
|
||||
void appendChild(FolderItem *child);
|
||||
|
||||
FolderItem *child(int row);
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
QList<QVariant> getData() const;
|
||||
int row() const;
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
QList<QVariant> getData() const;
|
||||
int row() const;
|
||||
FolderItem *parent();
|
||||
FolderItem *parentItem;
|
||||
unsigned long long int id;
|
||||
QList<QString> comicNames;
|
||||
FolderItem * originalItem;
|
||||
unsigned long long int id;
|
||||
QList<QString> comicNames;
|
||||
FolderItem *originalItem;
|
||||
void setData(int column, const QVariant &value);
|
||||
void removeChild(int childIndex);
|
||||
void clearChildren();
|
||||
QList<FolderItem*> children();
|
||||
QList<FolderItem *> children();
|
||||
|
||||
private:
|
||||
QList<FolderItem*> childItems;
|
||||
QList<QVariant> itemData;
|
||||
QList<FolderItem *> childItems;
|
||||
QList<QVariant> itemData;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
|
||||
@ -47,7 +47,6 @@
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
|
||||
#include "folder_item.h"
|
||||
#include "folder_model.h"
|
||||
#include "data_base_management.h"
|
||||
@ -63,34 +62,33 @@ QIcon finishedFolderIcon;
|
||||
void drawMacOSXFinishedFolderIcon()
|
||||
{
|
||||
QIcon ico = QFileIconProvider().icon(QFileIconProvider::Folder);
|
||||
QPixmap pixNormalOff = ico.pixmap(16,16, QIcon::Normal, QIcon::Off);
|
||||
QPixmap pixNormalOn = ico.pixmap(16,16, QIcon::Normal, QIcon::On);
|
||||
QPixmap pixSelectedOff = ico.pixmap(16,16, QIcon::Selected, QIcon::Off);
|
||||
QPixmap pixSelectedOn = ico.pixmap(16,16, QIcon::Selected, QIcon::On);
|
||||
QPixmap pixNormalOff = ico.pixmap(16, 16, QIcon::Normal, QIcon::Off);
|
||||
QPixmap pixNormalOn = ico.pixmap(16, 16, QIcon::Normal, QIcon::On);
|
||||
QPixmap pixSelectedOff = ico.pixmap(16, 16, QIcon::Selected, QIcon::Off);
|
||||
QPixmap pixSelectedOn = ico.pixmap(16, 16, QIcon::Selected, QIcon::On);
|
||||
QPixmap tick(":/images/folder_finished_macosx.png");
|
||||
|
||||
|
||||
{
|
||||
QPainter p(&pixNormalOff);
|
||||
p.drawPixmap(4,7,tick);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixNormalOff, QIcon::Normal, QIcon::Off);
|
||||
|
||||
{
|
||||
QPainter p(&pixNormalOn);
|
||||
p.drawPixmap(4,7,tick);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixNormalOn, QIcon::Normal, QIcon::On);
|
||||
|
||||
{
|
||||
QPainter p(&pixSelectedOff);
|
||||
p.drawPixmap(4,7,tick);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixSelectedOff, QIcon::Selected, QIcon::Off);
|
||||
|
||||
{
|
||||
QPainter p(&pixSelectedOn);
|
||||
p.drawPixmap(4,7,tick);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixSelectedOn, QIcon::Selected, QIcon::On);
|
||||
}
|
||||
@ -99,93 +97,89 @@ void drawMacOSXFinishedFolderIcon()
|
||||
#define ROOT 1
|
||||
|
||||
FolderModel::FolderModel(QObject *parent)
|
||||
: QAbstractItemModel(parent),rootItem(0)
|
||||
: QAbstractItemModel(parent), rootItem(0)
|
||||
{
|
||||
connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset()));
|
||||
connect(this,SIGNAL(reset()),this,SIGNAL(modelReset()));
|
||||
connect(this, SIGNAL(beforeReset()), this, SIGNAL(modelAboutToBeReset()));
|
||||
connect(this, SIGNAL(reset()), this, SIGNAL(modelReset()));
|
||||
}
|
||||
|
||||
//! [0]
|
||||
FolderModel::FolderModel( QSqlQuery &sqlquery, QObject *parent)
|
||||
: QAbstractItemModel(parent),rootItem(0)
|
||||
FolderModel::FolderModel(QSqlQuery &sqlquery, QObject *parent)
|
||||
: QAbstractItemModel(parent), rootItem(0)
|
||||
{
|
||||
//lo m<>s probable es que el nodo ra<72>z no necesite tener informaci<63>n
|
||||
QList<QVariant> rootData;
|
||||
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||
//lo m<>s probable es que el nodo ra<72>z no necesite tener informaci<63>n
|
||||
QList<QVariant> rootData;
|
||||
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||
rootItem = new FolderItem(rootData);
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
setupModelData(sqlquery, rootItem);
|
||||
//sqlquery.finish();
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
setupModelData(sqlquery, rootItem);
|
||||
//sqlquery.finish();
|
||||
}
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
FolderModel::~FolderModel()
|
||||
{
|
||||
if(rootItem != 0)
|
||||
delete rootItem;
|
||||
if (rootItem != 0)
|
||||
delete rootItem;
|
||||
}
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
int FolderModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return static_cast<FolderItem*>(parent.internalPointer())->columnCount();
|
||||
else
|
||||
return rootItem->columnCount();
|
||||
if (parent.isValid())
|
||||
return static_cast<FolderItem *>(parent.internalPointer())->columnCount();
|
||||
else
|
||||
return rootItem->columnCount();
|
||||
}
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
FolderItem *item = static_cast<FolderItem*>(index.internalPointer());
|
||||
FolderItem *item = static_cast<FolderItem *>(index.internalPointer());
|
||||
|
||||
if (role == Qt::ToolTipRole)
|
||||
{
|
||||
if (role == Qt::ToolTipRole) {
|
||||
QString toolTip = item->data(FolderModel::Name).toString();
|
||||
int totalNumOfChildren = item->childCount() + item->comicNames.size();
|
||||
if(totalNumOfChildren > 0)
|
||||
{
|
||||
toolTip = toolTip + " - " + QString::number(totalNumOfChildren);
|
||||
if (totalNumOfChildren > 0) {
|
||||
toolTip = toolTip + " - " + QString::number(totalNumOfChildren);
|
||||
}
|
||||
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
#ifdef Q_OS_MAC
|
||||
if(item->data(FolderModel::Finished).toBool()){
|
||||
if(finishedFolderIcon.isNull()){
|
||||
if (item->data(FolderModel::Finished).toBool()) {
|
||||
if (finishedFolderIcon.isNull()) {
|
||||
drawMacOSXFinishedFolderIcon();
|
||||
}
|
||||
|
||||
return QVariant(finishedFolderIcon);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return QVariant(QFileIconProvider().icon(QFileIconProvider::Folder));
|
||||
}
|
||||
#else
|
||||
if(item->data(FolderModel::Finished).toBool())
|
||||
if (item->data(FolderModel::Finished).toBool())
|
||||
return QVariant(YACReader::noHighlightedIcon(":/images/sidebar/folder_finished.png"));
|
||||
else
|
||||
return QVariant(YACReader::noHighlightedIcon(":/images/sidebar/folder.png"));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(role == FolderModel::CompletedRole)
|
||||
if (role == FolderModel::CompletedRole)
|
||||
return item->data(FolderModel::Completed);
|
||||
|
||||
if(role == FolderModel::FinishedRole)
|
||||
if (role == FolderModel::FinishedRole)
|
||||
return item->data(FolderModel::Finished);
|
||||
|
||||
if(role == FolderModel::IdRole)
|
||||
if (role == FolderModel::IdRole)
|
||||
return item->id;
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
@ -198,8 +192,8 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
//! [4]
|
||||
Qt::ItemFlags FolderModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
@ -207,48 +201,48 @@ Qt::ItemFlags FolderModel::flags(const QModelIndex &index) const
|
||||
|
||||
//! [5]
|
||||
QVariant FolderModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return rootItem->data(section);
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return rootItem->data(section);
|
||||
|
||||
return QVariant();
|
||||
return QVariant();
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
QModelIndex FolderModel::index(int row, int column, const QModelIndex &parent)
|
||||
const
|
||||
const
|
||||
{
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
FolderItem *parentItem;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<FolderItem*>(parent.internalPointer());
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<FolderItem *>(parent.internalPointer());
|
||||
|
||||
FolderItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
//! [6]
|
||||
|
||||
//! [7]
|
||||
QModelIndex FolderModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
FolderItem *childItem = static_cast<FolderItem*>(index.internalPointer());
|
||||
FolderItem *childItem = static_cast<FolderItem *>(index.internalPointer());
|
||||
FolderItem *parentItem = childItem->parent();
|
||||
|
||||
if (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
if (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
@ -264,62 +258,59 @@ QModelIndex FolderModel::indexFromItem(FolderItem * item,int column)
|
||||
return createIndex(item->row(), column, item);
|
||||
}*/
|
||||
|
||||
|
||||
//! [8]
|
||||
int FolderModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
FolderItem *parentItem;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<FolderItem*>(parent.internalPointer());
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<FolderItem *>(parent.internalPointer());
|
||||
|
||||
return parentItem->childCount();
|
||||
return parentItem->childCount();
|
||||
}
|
||||
//! [8]
|
||||
|
||||
void FolderModel::setupModelData(QString path)
|
||||
{
|
||||
beginResetModel();
|
||||
if(rootItem != 0)
|
||||
delete rootItem; //TODO comprobar que se libera bien la memoria
|
||||
beginResetModel();
|
||||
if (rootItem != 0)
|
||||
delete rootItem; //TODO comprobar que se libera bien la memoria
|
||||
|
||||
rootItem = 0;
|
||||
rootItem = 0;
|
||||
|
||||
//inicializar el nodo ra<72>z
|
||||
QList<QVariant> rootData;
|
||||
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||
//inicializar el nodo ra<72>z
|
||||
QList<QVariant> rootData;
|
||||
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||
rootItem = new FolderItem(rootData);
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
|
||||
//cargar la base de datos
|
||||
_databasePath = path;
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(path);
|
||||
//crear la consulta
|
||||
{
|
||||
QSqlQuery selectQuery("select * from folder where id <> 1 order by parentId,name",db);
|
||||
|
||||
setupModelData(selectQuery,rootItem);
|
||||
}
|
||||
//selectQuery.finish();
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
endResetModel();
|
||||
//cargar la base de datos
|
||||
_databasePath = path;
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(path);
|
||||
//crear la consulta
|
||||
{
|
||||
QSqlQuery selectQuery("select * from folder where id <> 1 order by parentId,name", db);
|
||||
|
||||
setupModelData(selectQuery, rootItem);
|
||||
}
|
||||
//selectQuery.finish();
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
void FolderModel::setupModelData(QSqlQuery &sqlquery, FolderItem *parent)
|
||||
{
|
||||
//64 bits para la primary key, es decir la misma precisi<73>n que soporta sqlit 2^64
|
||||
//el diccionario permitir<69> encontrar cualquier nodo del <20>rbol r<>pidamente, de forma que a<>adir un hijo a un padre sea O(1)
|
||||
items.clear();
|
||||
//se a<>ade el nodo 0
|
||||
items.insert(parent->id,parent);
|
||||
//64 bits para la primary key, es decir la misma precisi<73>n que soporta sqlit 2^64
|
||||
//el diccionario permitir<69> encontrar cualquier nodo del <20>rbol r<>pidamente, de forma que a<>adir un hijo a un padre sea O(1)
|
||||
items.clear();
|
||||
//se a<>ade el nodo 0
|
||||
items.insert(parent->id, parent);
|
||||
|
||||
QSqlRecord record = sqlquery.record();
|
||||
|
||||
@ -330,22 +321,22 @@ void FolderModel::setupModelData(QSqlQuery &sqlquery, FolderItem *parent)
|
||||
int id = record.indexOf("id");
|
||||
int parentId = record.indexOf("parentId");
|
||||
|
||||
while (sqlquery.next()) {
|
||||
QList<QVariant> data;
|
||||
while (sqlquery.next()) {
|
||||
QList<QVariant> data;
|
||||
|
||||
data << sqlquery.value(name).toString();
|
||||
data << sqlquery.value(path).toString();
|
||||
data << sqlquery.value(finished).toBool();
|
||||
data << sqlquery.value(completed).toBool();
|
||||
FolderItem * item = new FolderItem(data);
|
||||
FolderItem *item = new FolderItem(data);
|
||||
|
||||
item->id = sqlquery.value(id).toULongLong();
|
||||
//la inserci<63>n de hijos se hace de forma ordenada
|
||||
FolderItem * parent = items.value(sqlquery.value(parentId).toULongLong());
|
||||
//la inserci<63>n de hijos se hace de forma ordenada
|
||||
FolderItem *parent = items.value(sqlquery.value(parentId).toULongLong());
|
||||
//if(parent !=0) //TODO if parent==0 the parent of item was removed from the DB and delete on cascade didn't work, ERROR.
|
||||
parent->appendChild(item);
|
||||
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
||||
items.insert(item->id,item);
|
||||
parent->appendChild(item);
|
||||
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
||||
items.insert(item->id, item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,28 +360,28 @@ void FolderModel::updateFolderModelData(QSqlQuery &sqlquery, FolderItem *parent)
|
||||
data << sqlquery.value(path).toString();
|
||||
data << sqlquery.value(finished).toBool();
|
||||
data << sqlquery.value(completed).toBool();
|
||||
FolderItem * item = new FolderItem(data);
|
||||
FolderItem *item = new FolderItem(data);
|
||||
|
||||
item->id = sqlquery.value(id).toULongLong();
|
||||
//la inserci<63>n de hijos se hace de forma ordenada
|
||||
FolderItem * parent = items.value(sqlquery.value(parentId).toULongLong());
|
||||
if(parent !=0) //TODO if parent==0 the parent of item was removed from the DB and delete on cascade didn't work, ERROR.
|
||||
FolderItem *parent = items.value(sqlquery.value(parentId).toULongLong());
|
||||
if (parent != 0) //TODO if parent==0 the parent of item was removed from the DB and delete on cascade didn't work, ERROR.
|
||||
parent->appendChild(item);
|
||||
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
||||
items.insert(item->id,item);
|
||||
items.insert(item->id, item);
|
||||
}
|
||||
}
|
||||
|
||||
QString FolderModel::getDatabase()
|
||||
{
|
||||
return _databasePath;
|
||||
return _databasePath;
|
||||
}
|
||||
|
||||
QString FolderModel::getFolderPath(const QModelIndex &folder)
|
||||
{
|
||||
if(!folder.isValid()) //root folder
|
||||
if (!folder.isValid()) //root folder
|
||||
return "/";
|
||||
return static_cast<FolderItem*>(folder.internalPointer())->data(FolderModel::Path).toString();
|
||||
return static_cast<FolderItem *>(folder.internalPointer())->data(FolderModel::Path).toString();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -418,77 +409,74 @@ void FolderModel::updateFolderCompletedStatus(const QModelIndexList &list, bool
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
db.transaction();
|
||||
foreach (QModelIndex mi, list)
|
||||
{
|
||||
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||
item->setData(FolderModel::Completed,status);
|
||||
foreach (QModelIndex mi, list) {
|
||||
FolderItem *item = static_cast<FolderItem *>(mi.internalPointer());
|
||||
item->setData(FolderModel::Completed, status);
|
||||
|
||||
Folder f = DBHelper::loadFolder(item->id,db);
|
||||
Folder f = DBHelper::loadFolder(item->id, db);
|
||||
f.setCompleted(status);
|
||||
DBHelper::update(f,db);
|
||||
DBHelper::update(f, db);
|
||||
}
|
||||
db.commit();
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
|
||||
emit dataChanged(index(list.first().row(),FolderModel::Name),index(list.last().row(),FolderModel::Completed));
|
||||
emit dataChanged(index(list.first().row(), FolderModel::Name), index(list.last().row(), FolderModel::Completed));
|
||||
}
|
||||
|
||||
void FolderModel::updateFolderFinishedStatus(const QModelIndexList &list, bool status)
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
db.transaction();
|
||||
foreach (QModelIndex mi, list)
|
||||
{
|
||||
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||
item->setData(FolderModel::Finished,status);
|
||||
foreach (QModelIndex mi, list) {
|
||||
FolderItem *item = static_cast<FolderItem *>(mi.internalPointer());
|
||||
item->setData(FolderModel::Finished, status);
|
||||
|
||||
Folder f = DBHelper::loadFolder(item->id,db);
|
||||
Folder f = DBHelper::loadFolder(item->id, db);
|
||||
f.setFinished(status);
|
||||
DBHelper::update(f,db);
|
||||
DBHelper::update(f, db);
|
||||
}
|
||||
db.commit();
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
|
||||
emit dataChanged(index(list.first().row(),FolderModel::Name),index(list.last().row(),FolderModel::Completed));
|
||||
emit dataChanged(index(list.first().row(), FolderModel::Name), index(list.last().row(), FolderModel::Completed));
|
||||
}
|
||||
|
||||
QStringList FolderModel::getSubfoldersNames(const QModelIndex &mi)
|
||||
{
|
||||
QStringList result;
|
||||
qulonglong id = 1;
|
||||
if(mi.isValid()){
|
||||
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||
if (mi.isValid()) {
|
||||
FolderItem *item = static_cast<FolderItem *>(mi.internalPointer());
|
||||
id = item->id;
|
||||
}
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
db.transaction();
|
||||
|
||||
result = DBHelper::loadSubfoldersNames(id,db);
|
||||
result = DBHelper::loadSubfoldersNames(id, db);
|
||||
|
||||
db.commit();
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
|
||||
//TODO sort result))
|
||||
qSort(result.begin(),result.end(),naturalSortLessThanCI);
|
||||
qSort(result.begin(), result.end(), naturalSortLessThanCI);
|
||||
return result;
|
||||
}
|
||||
|
||||
void FolderModel::fetchMoreFromDB(const QModelIndex &parent)
|
||||
{
|
||||
FolderItem * item;
|
||||
if(parent.isValid())
|
||||
item = static_cast<FolderItem*>(parent.internalPointer());
|
||||
FolderItem *item;
|
||||
if (parent.isValid())
|
||||
item = static_cast<FolderItem *>(parent.internalPointer());
|
||||
else
|
||||
item = rootItem;
|
||||
|
||||
//Remove all children
|
||||
if(item->childCount() > 0)
|
||||
{
|
||||
beginRemoveRows(parent, 0, item->childCount()-1);
|
||||
if (item->childCount() > 0) {
|
||||
beginRemoveRows(parent, 0, item->childCount() - 1);
|
||||
item->clearChildren();
|
||||
endRemoveRows();
|
||||
}
|
||||
@ -503,48 +491,42 @@ void FolderModel::fetchMoreFromDB(const QModelIndex &parent)
|
||||
|
||||
items << item;
|
||||
bool firstLevelUpdated = false;
|
||||
while(items.size() > 0)
|
||||
{
|
||||
while (items.size() > 0) {
|
||||
nextLevelItems.clear();
|
||||
foreach(FolderItem * item, items)
|
||||
{
|
||||
foreach (FolderItem *item, items) {
|
||||
QLOG_DEBUG() << "ID " << item->id;
|
||||
selectQuery.bindValue(":parentId", item->id);
|
||||
|
||||
selectQuery.exec();
|
||||
|
||||
if(!firstLevelUpdated)
|
||||
{
|
||||
if (!firstLevelUpdated) {
|
||||
//NO size support
|
||||
int numResults = 0;
|
||||
while(selectQuery.next())
|
||||
while (selectQuery.next())
|
||||
numResults++;
|
||||
|
||||
if(!selectQuery.seek(-1))
|
||||
if (!selectQuery.seek(-1))
|
||||
selectQuery.exec();
|
||||
//END no size support
|
||||
|
||||
beginInsertRows(parent, 0, numResults-1);
|
||||
beginInsertRows(parent, 0, numResults - 1);
|
||||
}
|
||||
|
||||
updateFolderModelData(selectQuery,item);
|
||||
updateFolderModelData(selectQuery, item);
|
||||
|
||||
if(!firstLevelUpdated)
|
||||
{
|
||||
if (!firstLevelUpdated) {
|
||||
endInsertRows();
|
||||
firstLevelUpdated = true;
|
||||
}
|
||||
|
||||
nextLevelItems << item->children();
|
||||
|
||||
}
|
||||
|
||||
items.clear();
|
||||
items = nextLevelItems;
|
||||
}
|
||||
|
||||
QLOG_DEBUG() << "item->childCount()-1" << item->childCount()-1;
|
||||
|
||||
QLOG_DEBUG() << "item->childCount()-1" << item->childCount() - 1;
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
@ -552,10 +534,10 @@ void FolderModel::fetchMoreFromDB(const QModelIndex &parent)
|
||||
|
||||
QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QModelIndex &parent)
|
||||
{
|
||||
FolderItem * parentItem;
|
||||
FolderItem *parentItem;
|
||||
|
||||
if(parent.isValid())
|
||||
parentItem = static_cast<FolderItem*>(parent.internalPointer());
|
||||
if (parent.isValid())
|
||||
parentItem = static_cast<FolderItem *>(parent.internalPointer());
|
||||
else
|
||||
parentItem = rootItem;
|
||||
|
||||
@ -577,38 +559,38 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod
|
||||
data << false; //finished
|
||||
data << true; //completed
|
||||
|
||||
FolderItem * item = new FolderItem(data);
|
||||
FolderItem *item = new FolderItem(data);
|
||||
item->id = newFolder.id;
|
||||
|
||||
beginInsertRows(parent,0,0); //TODO calculate the destRow before inserting the new child
|
||||
beginInsertRows(parent, 0, 0); //TODO calculate the destRow before inserting the new child
|
||||
|
||||
parentItem->appendChild(item);
|
||||
destRow = parentItem->children().indexOf(item); //TODO optimize this, appendChild should return the index of the new item
|
||||
items.insert(item->id,item);
|
||||
items.insert(item->id, item);
|
||||
|
||||
endInsertRows();
|
||||
|
||||
return index(destRow,0,parent);
|
||||
return index(destRow, 0, parent);
|
||||
}
|
||||
|
||||
void FolderModel::deleteFolder(const QModelIndex &mi)
|
||||
{
|
||||
beginRemoveRows(mi.parent(),mi.row(),mi.row());
|
||||
beginRemoveRows(mi.parent(), mi.row(), mi.row());
|
||||
|
||||
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||
FolderItem *item = static_cast<FolderItem *>(mi.internalPointer());
|
||||
|
||||
FolderItem * parent = item->parent();
|
||||
parent->removeChild(mi.row());
|
||||
FolderItem *parent = item->parent();
|
||||
parent->removeChild(mi.row());
|
||||
|
||||
Folder f;
|
||||
f.setId(item->id);
|
||||
Folder f;
|
||||
f.setId(item->id);
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
DBHelper::removeFromDB(&f,db);
|
||||
DBHelper::updateChildrenInfo(item->parent()->id, db);
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
DBHelper::removeFromDB(&f, db);
|
||||
DBHelper::updateChildrenInfo(item->parent()->id, db);
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
|
||||
endRemoveRows();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void FolderModel::updateFolderChildrenInfo(qulonglong folderId)
|
||||
@ -621,27 +603,25 @@ void FolderModel::updateFolderChildrenInfo(qulonglong folderId)
|
||||
//PROXY
|
||||
|
||||
FolderModelProxy::FolderModelProxy(QObject *parent)
|
||||
:QSortFilterProxyModel(parent),rootItem(0),includeComics(true),filter(""),filterEnabled(false)
|
||||
: QSortFilterProxyModel(parent), rootItem(0), includeComics(true), filter(""), filterEnabled(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FolderModelProxy::~FolderModelProxy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool FolderModelProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||
{
|
||||
if(!filterEnabled)
|
||||
if (!filterEnabled)
|
||||
return true;
|
||||
|
||||
FolderItem * parent = static_cast<FolderItem *>(source_parent.internalPointer());
|
||||
FolderItem *parent = static_cast<FolderItem *>(source_parent.internalPointer());
|
||||
|
||||
if(parent == 0)
|
||||
if (parent == 0)
|
||||
parent = static_cast<FolderModel *>(sourceModel())->rootItem;
|
||||
|
||||
FolderItem * item = parent->children().at(source_row);
|
||||
FolderItem *item = parent->children().at(source_row);
|
||||
|
||||
return filteredItems.contains(item->id);
|
||||
}
|
||||
@ -664,7 +644,7 @@ void FolderModelProxy::setupFilteredModelData()
|
||||
|
||||
//inicializar el nodo ra<72>z
|
||||
|
||||
if(rootItem != 0)
|
||||
if (rootItem != 0)
|
||||
delete rootItem; //TODO comprobar que se libera bien la memoria
|
||||
|
||||
rootItem = 0;
|
||||
@ -676,57 +656,50 @@ void FolderModelProxy::setupFilteredModelData()
|
||||
rootItem->id = ROOT;
|
||||
rootItem->parentItem = 0;
|
||||
|
||||
FolderModel * model = static_cast<FolderModel *>(sourceModel());
|
||||
FolderModel *model = static_cast<FolderModel *>(sourceModel());
|
||||
|
||||
//cargar la base de datos
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(model->_databasePath);
|
||||
//crear la consulta
|
||||
{
|
||||
QSqlQuery selectQuery(db); //TODO check
|
||||
if(!includeComics)
|
||||
{
|
||||
selectQuery.prepare("select * from folder where id <> 1 and upper(name) like upper(:filter) order by parentId,name ");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(modifier)
|
||||
{
|
||||
case YACReader::NoModifiers:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN comic c ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) ORDER BY f.parentId,f.name");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":filter2", "%%"+filter+"%%");
|
||||
break;
|
||||
QSqlQuery selectQuery(db); //TODO check
|
||||
if (!includeComics) {
|
||||
selectQuery.prepare("select * from folder where id <> 1 and upper(name) like upper(:filter) order by parentId,name ");
|
||||
selectQuery.bindValue(":filter", "%%" + filter + "%%");
|
||||
} else {
|
||||
switch (modifier) {
|
||||
case YACReader::NoModifiers:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN comic c ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) ORDER BY f.parentId,f.name");
|
||||
selectQuery.bindValue(":filter", "%%" + filter + "%%");
|
||||
selectQuery.bindValue(":filter2", "%%" + filter + "%%");
|
||||
break;
|
||||
|
||||
case YACReader::OnlyRead:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 1 ORDER BY f.parentId,f.name;");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":filter2", "%%"+filter+"%%");
|
||||
break;
|
||||
case YACReader::OnlyRead:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 1 ORDER BY f.parentId,f.name;");
|
||||
selectQuery.bindValue(":filter", "%%" + filter + "%%");
|
||||
selectQuery.bindValue(":filter2", "%%" + filter + "%%");
|
||||
break;
|
||||
|
||||
case YACReader::OnlyUnread:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 0 ORDER BY f.parentId,f.name;");
|
||||
selectQuery.bindValue(":filter", "%%"+filter+"%%");
|
||||
selectQuery.bindValue(":filter2", "%%"+filter+"%%");
|
||||
break;
|
||||
|
||||
default:
|
||||
QLOG_ERROR() << "not implemented";
|
||||
break;
|
||||
case YACReader::OnlyUnread:
|
||||
selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed "
|
||||
"FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) "
|
||||
"WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 0 ORDER BY f.parentId,f.name;");
|
||||
selectQuery.bindValue(":filter", "%%" + filter + "%%");
|
||||
selectQuery.bindValue(":filter2", "%%" + filter + "%%");
|
||||
break;
|
||||
|
||||
default:
|
||||
QLOG_ERROR() << "not implemented";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
selectQuery.exec();
|
||||
|
||||
setupFilteredModelData(selectQuery,rootItem);
|
||||
setupFilteredModelData(selectQuery, rootItem);
|
||||
}
|
||||
//selectQuery.finish();
|
||||
db.close();
|
||||
@ -746,13 +719,13 @@ void FolderModelProxy::clear()
|
||||
|
||||
void FolderModelProxy::setupFilteredModelData(QSqlQuery &sqlquery, FolderItem *parent)
|
||||
{
|
||||
FolderModel * model = static_cast<FolderModel *>(sourceModel());
|
||||
FolderModel *model = static_cast<FolderModel *>(sourceModel());
|
||||
|
||||
//64 bits para la primary key, es decir la misma precisi<73>n que soporta sqlit 2^64
|
||||
filteredItems.clear();
|
||||
|
||||
//se a<>ade el nodo 0 al modelo que representa el arbol de elementos que cumplen con el filtro
|
||||
filteredItems.insert(parent->id,parent);
|
||||
filteredItems.insert(parent->id, parent);
|
||||
|
||||
QSqlRecord record = sqlquery.record();
|
||||
|
||||
@ -762,7 +735,7 @@ void FolderModelProxy::setupFilteredModelData(QSqlQuery &sqlquery, FolderItem *p
|
||||
int completed = record.indexOf("completed");
|
||||
int parentIdIndex = record.indexOf("parentId");
|
||||
|
||||
while (sqlquery.next()) { //se procesan todos los folders que cumplen con el filtro
|
||||
while (sqlquery.next()) { //se procesan todos los folders que cumplen con el filtro
|
||||
//datos de la base de datos
|
||||
QList<QVariant> data;
|
||||
|
||||
@ -771,49 +744,46 @@ void FolderModelProxy::setupFilteredModelData(QSqlQuery &sqlquery, FolderItem *p
|
||||
data << sqlquery.value(finished).toBool();
|
||||
data << sqlquery.value(completed).toBool();
|
||||
|
||||
FolderItem * item = new FolderItem(data);
|
||||
FolderItem *item = new FolderItem(data);
|
||||
item->id = sqlquery.value(0).toULongLong();
|
||||
|
||||
//id del padre
|
||||
quint64 parentId = sqlquery.value(parentIdIndex).toULongLong();
|
||||
|
||||
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
||||
if(!filteredItems.contains(item->id))
|
||||
filteredItems.insert(item->id,item);
|
||||
if (!filteredItems.contains(item->id))
|
||||
filteredItems.insert(item->id, item);
|
||||
|
||||
//es necesario conocer las coordenadas de origen para poder realizar scroll autom<6F>tico en la vista
|
||||
item->originalItem = model->items.value(item->id);
|
||||
|
||||
//si el padre ya existe en el modelo, el item se a<>ade como hijo
|
||||
if(filteredItems.contains(parentId))
|
||||
if (filteredItems.contains(parentId))
|
||||
filteredItems.value(parentId)->appendChild(item);
|
||||
else//si el padre a<>n no se ha a<>adido, hay que a<>adirlo a <20>l y todos los padres hasta el nodo ra<72>z
|
||||
else //si el padre a<>n no se ha a<>adido, hay que a<>adirlo a <20>l y todos los padres hasta el nodo ra<72>z
|
||||
{
|
||||
//comprobamos con esta variable si el <20>ltimo de los padres (antes del nodo ra<72>z) ya exist<73>a en el modelo
|
||||
bool parentPreviousInserted = false;
|
||||
|
||||
//mientras no se alcance el nodo ra<72>z se procesan todos los padres (de abajo a arriba)
|
||||
while(parentId != ROOT )
|
||||
{
|
||||
while (parentId != ROOT) {
|
||||
//el padre no estaba en el modelo filtrado, as<61> que se rescata del modelo original
|
||||
FolderItem * parentItem = model->items.value(parentId);
|
||||
FolderItem *parentItem = model->items.value(parentId);
|
||||
//se debe crear un nuevo nodo (para no compartir los hijos con el nodo original)
|
||||
FolderItem * newparentItem = new FolderItem(parentItem->getData()); //padre que se a<>adir<69> a la estructura de directorios filtrados
|
||||
FolderItem *newparentItem = new FolderItem(parentItem->getData()); //padre que se a<>adir<69> a la estructura de directorios filtrados
|
||||
newparentItem->id = parentId;
|
||||
|
||||
newparentItem->originalItem = parentItem;
|
||||
|
||||
//si el modelo contiene al padre, se a<>ade el item actual como hijo
|
||||
if(filteredItems.contains(parentId))
|
||||
{
|
||||
if (filteredItems.contains(parentId)) {
|
||||
filteredItems.value(parentId)->appendChild(item);
|
||||
parentPreviousInserted = true;
|
||||
}
|
||||
//sino se registra el nodo para poder encontrarlo con posterioridad y se a<>ade el item actual como hijo
|
||||
else
|
||||
{
|
||||
else {
|
||||
newparentItem->appendChild(item);
|
||||
filteredItems.insert(newparentItem->id,newparentItem);
|
||||
filteredItems.insert(newparentItem->id, newparentItem);
|
||||
parentPreviousInserted = false;
|
||||
}
|
||||
|
||||
@ -823,12 +793,9 @@ void FolderModelProxy::setupFilteredModelData(QSqlQuery &sqlquery, FolderItem *p
|
||||
}
|
||||
|
||||
//si el nodo es hijo de 1 y no hab<61>a sido previamente insertado como hijo, se a<>ade como tal
|
||||
if(!parentPreviousInserted)
|
||||
{
|
||||
if (!parentPreviousInserted) {
|
||||
filteredItems.value(ROOT)->appendChild(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public:
|
||||
~FolderModelProxy();
|
||||
|
||||
void setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics);
|
||||
void setupFilteredModelData( QSqlQuery &sqlquery, FolderItem *parent);
|
||||
void setupFilteredModelData(QSqlQuery &sqlquery, FolderItem *parent);
|
||||
void setupFilteredModelData();
|
||||
void clear();
|
||||
|
||||
@ -80,50 +80,49 @@ protected:
|
||||
class FolderModel : public QAbstractItemModel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
friend class FolderModelProxy;
|
||||
|
||||
public:
|
||||
FolderModel(QObject *parent = 0);
|
||||
FolderModel( QSqlQuery &sqlquery, QObject *parent = 0);
|
||||
FolderModel(QSqlQuery &sqlquery, QObject *parent = 0);
|
||||
~FolderModel();
|
||||
|
||||
//QAbstractItemModel methods
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
//Convenience methods
|
||||
void setupModelData(QString path);
|
||||
QString getDatabase();
|
||||
QString getFolderPath(const QModelIndex &folder);
|
||||
QString getFolderPath(const QModelIndex &folder);
|
||||
//QModelIndex indexFromItem(FolderItem * item, int column);
|
||||
|
||||
|
||||
//bool isFilterEnabled(){return filterEnabled;};
|
||||
|
||||
void updateFolderCompletedStatus(const QModelIndexList & list, bool status);
|
||||
void updateFolderFinishedStatus(const QModelIndexList & list, bool status);
|
||||
void updateFolderCompletedStatus(const QModelIndexList &list, bool status);
|
||||
void updateFolderFinishedStatus(const QModelIndexList &list, bool status);
|
||||
|
||||
QStringList getSubfoldersNames(const QModelIndex & mi);
|
||||
QStringList getSubfoldersNames(const QModelIndex &mi);
|
||||
|
||||
void fetchMoreFromDB(const QModelIndex & parent);
|
||||
void fetchMoreFromDB(const QModelIndex &parent);
|
||||
|
||||
QModelIndex addFolderAtParent(const QString & folderName, const QModelIndex & parent);
|
||||
QModelIndex addFolderAtParent(const QString &folderName, const QModelIndex &parent);
|
||||
|
||||
enum Columns {
|
||||
Name = 0,
|
||||
Path = 1,
|
||||
Finished = 2,
|
||||
Completed = 3
|
||||
};//id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL
|
||||
}; //id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL
|
||||
|
||||
enum Roles {
|
||||
FinishedRole = Qt::UserRole + 1,
|
||||
@ -132,21 +131,21 @@ public:
|
||||
};
|
||||
|
||||
public slots:
|
||||
void deleteFolder(const QModelIndex & mi);
|
||||
void deleteFolder(const QModelIndex &mi);
|
||||
void updateFolderChildrenInfo(qulonglong folderId);
|
||||
|
||||
private:
|
||||
void setupModelData( QSqlQuery &sqlquery, FolderItem *parent);
|
||||
void updateFolderModelData( QSqlQuery &sqlquery, FolderItem *parent);
|
||||
void setupModelData(QSqlQuery &sqlquery, FolderItem *parent);
|
||||
void updateFolderModelData(QSqlQuery &sqlquery, FolderItem *parent);
|
||||
|
||||
FolderItem *rootItem; //el árbol
|
||||
QMap<unsigned long long int, FolderItem *> items; //relación entre folders
|
||||
FolderItem *rootItem; //el árbol
|
||||
QMap<unsigned long long int, FolderItem *> items; //relación entre folders
|
||||
|
||||
QString _databasePath;
|
||||
QString _databasePath;
|
||||
|
||||
signals:
|
||||
void beforeReset();
|
||||
void reset();
|
||||
void beforeReset();
|
||||
void reset();
|
||||
};
|
||||
//! [0]
|
||||
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
#include "reading_list.h"
|
||||
|
||||
ReadingList::ReadingList(const QString &name, qulonglong id, int ordering)
|
||||
:name(name), id(id), ordering(ordering)
|
||||
: name(name), id(id), ordering(ordering)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
qulonglong ReadingList::getId() const
|
||||
@ -21,11 +20,9 @@ int ReadingList::getOrdering() const
|
||||
return ordering;
|
||||
}
|
||||
|
||||
|
||||
Label::Label(const QString &name, qulonglong id, YACReader::LabelColors colorid)
|
||||
:name(name), id(id), colorid(colorid)
|
||||
: name(name), id(id), colorid(colorid)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
YACReader::LabelColors Label::getColorID() const
|
||||
|
||||
@ -11,6 +11,7 @@ public:
|
||||
qulonglong getId() const;
|
||||
QString getName() const;
|
||||
int getOrdering() const;
|
||||
|
||||
private:
|
||||
QString name;
|
||||
qulonglong id;
|
||||
@ -30,7 +31,6 @@ private:
|
||||
QString name;
|
||||
qulonglong id;
|
||||
YACReader::LabelColors colorid;
|
||||
|
||||
};
|
||||
|
||||
#endif // READING_LIST_H
|
||||
|
||||
@ -6,9 +6,8 @@
|
||||
#include "QsLog.h"
|
||||
|
||||
ListItem::ListItem(const QList<QVariant> &data)
|
||||
:itemData(data)
|
||||
: itemData(data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ListItem::columnCount()
|
||||
@ -29,15 +28,13 @@ qulonglong ListItem::getId() const
|
||||
//------------------------------------------------------
|
||||
|
||||
SpecialListItem::SpecialListItem(const QList<QVariant> &data)
|
||||
:ListItem(data)
|
||||
: ListItem(data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QIcon SpecialListItem::getIcon() const
|
||||
{
|
||||
if(itemData.count()>Id)
|
||||
{
|
||||
if (itemData.count() > Id) {
|
||||
QString id = itemData.at(Id).toString();
|
||||
return YACReader::noHighlightedIcon(QString(":/images/lists/default_%1.png").arg(id));
|
||||
}
|
||||
@ -49,8 +46,7 @@ QIcon SpecialListItem::getIcon() const
|
||||
|
||||
ReadingListModel::TypeSpecialList SpecialListItem::getType() const
|
||||
{
|
||||
if(itemData.count()>Id)
|
||||
{
|
||||
if (itemData.count() > Id) {
|
||||
int id = itemData.at(Id).toInt();
|
||||
return (ReadingListModel::TypeSpecialList)id;
|
||||
}
|
||||
@ -63,15 +59,13 @@ ReadingListModel::TypeSpecialList SpecialListItem::getType() const
|
||||
//------------------------------------------------------
|
||||
|
||||
LabelItem::LabelItem(const QList<QVariant> &data)
|
||||
:ListItem(data)
|
||||
: ListItem(data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QIcon LabelItem::getIcon() const
|
||||
{
|
||||
if(itemData.count()>Color)
|
||||
{
|
||||
if (itemData.count() > Color) {
|
||||
QString color = itemData.at(Color).toString();
|
||||
return YACReader::noHighlightedIcon(QString(":/images/lists/label_%1.png").arg(color).toLower());
|
||||
}
|
||||
@ -83,8 +77,7 @@ QIcon LabelItem::getIcon() const
|
||||
|
||||
YACReader::LabelColors LabelItem::colorid() const
|
||||
{
|
||||
if(itemData.count()>Ordering)
|
||||
{
|
||||
if (itemData.count() > Ordering) {
|
||||
return YACReader::LabelColors(itemData.at(Ordering).toInt());
|
||||
}
|
||||
|
||||
@ -95,8 +88,7 @@ YACReader::LabelColors LabelItem::colorid() const
|
||||
|
||||
QString LabelItem::name() const
|
||||
{
|
||||
if(itemData.count()>Name)
|
||||
{
|
||||
if (itemData.count() > Name) {
|
||||
return itemData.at(Name).toString();
|
||||
}
|
||||
|
||||
@ -107,16 +99,14 @@ QString LabelItem::name() const
|
||||
|
||||
void LabelItem::setName(const QString &name)
|
||||
{
|
||||
if(itemData.count()>Name)
|
||||
{
|
||||
if (itemData.count() > Name) {
|
||||
itemData[Name] = name;
|
||||
}
|
||||
}
|
||||
|
||||
qulonglong LabelItem::getId() const
|
||||
{
|
||||
if(itemData.count()>Id)
|
||||
{
|
||||
if (itemData.count() > Id) {
|
||||
return YACReader::LabelColors(itemData.at(Id).toULongLong());
|
||||
}
|
||||
|
||||
@ -128,14 +118,13 @@ qulonglong LabelItem::getId() const
|
||||
//------------------------------------------------------
|
||||
|
||||
ReadingListItem::ReadingListItem(const QList<QVariant> &data, ReadingListItem *p)
|
||||
:ListItem(data), parent(p)
|
||||
: ListItem(data), parent(p)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QIcon ReadingListItem::getIcon() const
|
||||
{
|
||||
if(parent->getId() == 0)
|
||||
if (parent->getId() == 0)
|
||||
return YACReader::noHighlightedIcon(":/images/lists/list.png"); //top level list
|
||||
else
|
||||
#ifdef Q_OS_MAC
|
||||
@ -160,23 +149,20 @@ void ReadingListItem::appendChild(ReadingListItem *item)
|
||||
{
|
||||
item->parent = this;
|
||||
|
||||
if(childItems.isEmpty())
|
||||
if (childItems.isEmpty())
|
||||
childItems.append(item);
|
||||
else
|
||||
{
|
||||
if(item->parent->getId()==0) //sort by name, top level child
|
||||
else {
|
||||
if (item->parent->getId() == 0) //sort by name, top level child
|
||||
{
|
||||
int i= 0;
|
||||
while(i<childItems.length() && naturalSortLessThanCI(childItems.at(i)->name(),item->name()))
|
||||
int i = 0;
|
||||
while (i < childItems.length() && naturalSortLessThanCI(childItems.at(i)->name(), item->name()))
|
||||
i++;
|
||||
childItems.insert(i,item);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i= 0;
|
||||
while(i<childItems.length() && (childItems.at(i)->getOrdering()<item->getOrdering()))
|
||||
childItems.insert(i, item);
|
||||
} else {
|
||||
int i = 0;
|
||||
while (i < childItems.length() && (childItems.at(i)->getOrdering() < item->getOrdering()))
|
||||
i++;
|
||||
childItems.insert(i,item);
|
||||
childItems.insert(i, item);
|
||||
}
|
||||
|
||||
/*ReadingListItem * last = childItems.back();
|
||||
@ -194,9 +180,7 @@ void ReadingListItem::appendChild(ReadingListItem *item)
|
||||
childItems.insert(++i,item);
|
||||
else
|
||||
childItems.insert(i,item);*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ReadingListItem::appendChild(ReadingListItem *item, int pos)
|
||||
@ -211,7 +195,7 @@ void ReadingListItem::removeChild(ReadingListItem *item)
|
||||
|
||||
qulonglong ReadingListItem::getId() const
|
||||
{
|
||||
if(itemData.count()>Id)
|
||||
if (itemData.count() > Id)
|
||||
return itemData.at(Id).toULongLong();
|
||||
|
||||
QLOG_WARN() << "Name for reading list item not available";
|
||||
@ -221,7 +205,7 @@ qulonglong ReadingListItem::getId() const
|
||||
|
||||
QString ReadingListItem::name() const
|
||||
{
|
||||
if(itemData.count()>Name)
|
||||
if (itemData.count() > Name)
|
||||
return itemData.at(Name).toString();
|
||||
|
||||
QLOG_WARN() << "Name for reading list item not available";
|
||||
@ -231,13 +215,13 @@ QString ReadingListItem::name() const
|
||||
|
||||
void ReadingListItem::setName(const QString &name)
|
||||
{
|
||||
if(itemData.count()>Name)
|
||||
if (itemData.count() > Name)
|
||||
itemData[Name] = name;
|
||||
}
|
||||
|
||||
int ReadingListItem::getOrdering() const
|
||||
{
|
||||
if(itemData.count()>Ordering)
|
||||
if (itemData.count() > Ordering)
|
||||
return itemData[Ordering].toInt();
|
||||
|
||||
QLOG_WARN() << "Ordering for Item not available";
|
||||
@ -246,7 +230,7 @@ int ReadingListItem::getOrdering() const
|
||||
|
||||
void ReadingListItem::setOrdering(const int ordering)
|
||||
{
|
||||
if(itemData.count()>Ordering)
|
||||
if (itemData.count() > Ordering)
|
||||
itemData[Ordering] = ordering;
|
||||
}
|
||||
|
||||
@ -258,16 +242,14 @@ QList<ReadingListItem *> ReadingListItem::children()
|
||||
int ReadingListItem::row() const
|
||||
{
|
||||
if (parent)
|
||||
return parent->childItems.indexOf(const_cast<ReadingListItem*>(this));
|
||||
return parent->childItems.indexOf(const_cast<ReadingListItem *>(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ReadingListSeparatorItem::ReadingListSeparatorItem()
|
||||
:ListItem(QList<QVariant>())
|
||||
: ListItem(QList<QVariant>())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QIcon ReadingListSeparatorItem::getIcon() const
|
||||
|
||||
@ -28,12 +28,12 @@ public:
|
||||
SpecialListItem(const QList<QVariant> &data);
|
||||
QIcon getIcon() const;
|
||||
ReadingListModel::TypeSpecialList getType() const;
|
||||
|
||||
private:
|
||||
enum DataIndexes {
|
||||
Name,
|
||||
Id
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
@ -45,10 +45,9 @@ public:
|
||||
QIcon getIcon() const;
|
||||
YACReader::LabelColors colorid() const;
|
||||
QString name() const;
|
||||
void setName(const QString & name);
|
||||
void setName(const QString &name);
|
||||
qulonglong getId() const;
|
||||
|
||||
|
||||
private:
|
||||
enum DataIndexes {
|
||||
Name,
|
||||
@ -63,24 +62,24 @@ private:
|
||||
class ReadingListItem : public ListItem
|
||||
{
|
||||
public:
|
||||
ReadingListItem(const QList<QVariant> &data, ReadingListItem * parent = 0);
|
||||
ReadingListItem(const QList<QVariant> &data, ReadingListItem *parent = 0);
|
||||
QIcon getIcon() const;
|
||||
ReadingListItem * parent;
|
||||
ReadingListItem *parent;
|
||||
int childCount() const;
|
||||
int row() const;
|
||||
ReadingListItem * child(int row);
|
||||
ReadingListItem *child(int row);
|
||||
void appendChild(ReadingListItem *item);
|
||||
void appendChild(ReadingListItem *item, int pos);
|
||||
void removeChild(ReadingListItem *item);
|
||||
qulonglong getId() const;
|
||||
QString name() const;
|
||||
void setName(const QString & name);
|
||||
void setName(const QString &name);
|
||||
int getOrdering() const;
|
||||
void setOrdering(const int ordering);
|
||||
QList<ReadingListItem*> children();
|
||||
QList<ReadingListItem *> children();
|
||||
|
||||
private:
|
||||
QList<ReadingListItem*> childItems;
|
||||
QList<ReadingListItem *> childItems;
|
||||
|
||||
enum DataIndexes {
|
||||
Name,
|
||||
@ -89,7 +88,6 @@ private:
|
||||
Completed,
|
||||
Ordering
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
ReadingListModel::ReadingListModel(QObject *parent) :
|
||||
QAbstractItemModel(parent),rootItem(0)
|
||||
ReadingListModel::ReadingListModel(QObject *parent)
|
||||
: QAbstractItemModel(parent), rootItem(0)
|
||||
{
|
||||
separator1 = new ReadingListSeparatorItem;
|
||||
separator2 = new ReadingListSeparatorItem;
|
||||
@ -19,18 +19,15 @@ ReadingListModel::ReadingListModel(QObject *parent) :
|
||||
|
||||
int ReadingListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if(!parent.isValid()) //TOP
|
||||
if (!parent.isValid()) //TOP
|
||||
{
|
||||
int separatorsCount = 2;//labels.isEmpty()?1:2;
|
||||
int separatorsCount = 2; //labels.isEmpty()?1:2;
|
||||
return specialLists.count() + labels.count() + rootItem->childCount() + separatorsCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
||||
} else {
|
||||
ListItem *item = static_cast<ListItem *>(parent.internalPointer());
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * item = static_cast<ReadingListItem*>(parent.internalPointer());
|
||||
if (typeid(*item) == typeid(ReadingListItem)) {
|
||||
ReadingListItem *item = static_cast<ReadingListItem *>(parent.internalPointer());
|
||||
return item->childCount();
|
||||
}
|
||||
}
|
||||
@ -40,10 +37,9 @@ int ReadingListModel::rowCount(const QModelIndex &parent) const
|
||||
|
||||
int ReadingListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
{
|
||||
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
||||
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
if (parent.isValid()) {
|
||||
ListItem *item = static_cast<ListItem *>(parent.internalPointer());
|
||||
if (typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -55,49 +51,44 @@ int ReadingListModel::columnCount(const QModelIndex &parent) const
|
||||
|
||||
QVariant ReadingListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(!index.isValid())
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||
ListItem *item = static_cast<ListItem *>(index.internalPointer());
|
||||
|
||||
if (role == ReadingListModel::TypeListsRole)
|
||||
{
|
||||
if(typeid(*item) == typeid(SpecialListItem))
|
||||
if (role == ReadingListModel::TypeListsRole) {
|
||||
if (typeid(*item) == typeid(SpecialListItem))
|
||||
return QVariant(ReadingListModel::SpecialList);
|
||||
|
||||
if(typeid(*item) == typeid(LabelItem))
|
||||
if (typeid(*item) == typeid(LabelItem))
|
||||
return QVariant(ReadingListModel::Label);
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
if (typeid(*item) == typeid(ReadingListItem))
|
||||
return QVariant(ReadingListModel::ReadingList);
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
if (typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
return QVariant(ReadingListModel::Separator);
|
||||
}
|
||||
|
||||
if (role == ReadingListModel::LabelColorRole && typeid(*item) == typeid(LabelItem) )
|
||||
{
|
||||
LabelItem * labelItem = static_cast<LabelItem*>(item);
|
||||
if (role == ReadingListModel::LabelColorRole && typeid(*item) == typeid(LabelItem)) {
|
||||
LabelItem *labelItem = static_cast<LabelItem *>(item);
|
||||
return QVariant(labelItem->colorid());
|
||||
}
|
||||
|
||||
if (role == ReadingListModel::IDRole)
|
||||
{
|
||||
if (role == ReadingListModel::IDRole) {
|
||||
QLOG_DEBUG() << "getting role";
|
||||
return item->getId();
|
||||
}
|
||||
}
|
||||
|
||||
if (role == ReadingListModel::SpecialListTypeRole && typeid(*item) == typeid(SpecialListItem))
|
||||
{
|
||||
SpecialListItem * specialListItem = static_cast<SpecialListItem*>(item);
|
||||
if (role == ReadingListModel::SpecialListTypeRole && typeid(*item) == typeid(SpecialListItem)) {
|
||||
SpecialListItem *specialListItem = static_cast<SpecialListItem *>(item);
|
||||
return QVariant(specialListItem->getType());
|
||||
}
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
if (typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
return QVariant(item->getIcon());
|
||||
}
|
||||
|
||||
@ -112,14 +103,14 @@ Qt::ItemFlags ReadingListModel::flags(const QModelIndex &index) const
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
ListItem *item = static_cast<ListItem *>(index.internalPointer());
|
||||
if (typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
return 0;
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem) && static_cast<ReadingListItem *>(item)->parent->getId()!=0)
|
||||
if (typeid(*item) == typeid(ReadingListItem) && static_cast<ReadingListItem *>(item)->parent->getId() != 0)
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled; //only sublists are dragable
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
QVariant ReadingListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
@ -135,25 +126,24 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
if(!parent.isValid())
|
||||
{
|
||||
int separatorsCount = 2;//labels.isEmpty()?1:2;
|
||||
if (!parent.isValid()) {
|
||||
int separatorsCount = 2; //labels.isEmpty()?1:2;
|
||||
|
||||
if(rowIsSpecialList(row,parent))
|
||||
if (rowIsSpecialList(row, parent))
|
||||
return createIndex(row, column, specialLists.at(row));
|
||||
|
||||
if(row == specialLists.count())
|
||||
return createIndex(row,column,separator1);
|
||||
if (row == specialLists.count())
|
||||
return createIndex(row, column, separator1);
|
||||
|
||||
if(rowIsLabel(row,parent))
|
||||
return createIndex(row,column,labels.at(row-specialLists.count()-1));
|
||||
if (rowIsLabel(row, parent))
|
||||
return createIndex(row, column, labels.at(row - specialLists.count() - 1));
|
||||
|
||||
if(separatorsCount == 2)
|
||||
if(row == specialLists.count() + labels.count() + 1)
|
||||
return createIndex(row,column,separator2);
|
||||
if (separatorsCount == 2)
|
||||
if (row == specialLists.count() + labels.count() + 1)
|
||||
return createIndex(row, column, separator2);
|
||||
|
||||
if(rowIsReadingList(row,parent))
|
||||
return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count() + separatorsCount)));
|
||||
if (rowIsReadingList(row, parent))
|
||||
return createIndex(row, column, rootItem->child(row - (specialLists.count() + labels.count() + separatorsCount)));
|
||||
|
||||
} else //sublist
|
||||
{
|
||||
@ -162,33 +152,31 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem; //this should be impossible
|
||||
else
|
||||
parentItem = static_cast<ReadingListItem*>(parent.internalPointer());
|
||||
parentItem = static_cast<ReadingListItem *>(parent.internalPointer());
|
||||
|
||||
ReadingListItem *childItem = parentItem->child(row);
|
||||
return createIndex(row,column,childItem);
|
||||
return createIndex(row, column, childItem);
|
||||
}
|
||||
/*FolderItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else*/
|
||||
return QModelIndex();
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex ReadingListModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
|
||||
if(!index.isValid())
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||
ListItem *item = static_cast<ListItem *>(index.internalPointer());
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * childItem = static_cast<ReadingListItem*>(index.internalPointer());
|
||||
ReadingListItem * parent = childItem->parent;
|
||||
if(parent->getId() != 0)
|
||||
return createIndex(parent->row()+specialLists.count()+labels.count()+2, 0, parent);
|
||||
if (typeid(*item) == typeid(ReadingListItem)) {
|
||||
ReadingListItem *childItem = static_cast<ReadingListItem *>(index.internalPointer());
|
||||
ReadingListItem *parent = childItem->parent;
|
||||
if (parent->getId() != 0)
|
||||
return createIndex(parent->row() + specialLists.count() + labels.count() + 2, 0, parent);
|
||||
}
|
||||
|
||||
return QModelIndex();
|
||||
@ -200,38 +188,36 @@ bool ReadingListModel::canDropMimeData(const QMimeData *data, Qt::DropAction act
|
||||
|
||||
QLOG_DEBUG() << "trying to drop into row = " << row << "column column = " << column << "parent" << parent;
|
||||
|
||||
if(row == -1)
|
||||
if (row == -1)
|
||||
return false;
|
||||
|
||||
if(!parent.isValid()) //top level items
|
||||
if (!parent.isValid()) //top level items
|
||||
{
|
||||
if(row == -1) //no list
|
||||
if (row == -1) //no list
|
||||
return false;
|
||||
|
||||
if(row == 1) //reading is just an smart list
|
||||
if (row == 1) //reading is just an smart list
|
||||
return false;
|
||||
|
||||
if(rowIsSeparator(row,parent))
|
||||
if (rowIsSeparator(row, parent))
|
||||
return false;
|
||||
}
|
||||
|
||||
if(data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat))
|
||||
if (data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat))
|
||||
return true;
|
||||
|
||||
if(rowIsReadingList(row,parent))// TODO avoid droping in a different parent
|
||||
if (rowIsReadingList(row, parent)) // TODO avoid droping in a different parent
|
||||
{
|
||||
if(!parent.isValid())
|
||||
if (!parent.isValid())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
QList<QPair<int,int> > sublistsRows;
|
||||
else {
|
||||
QList<QPair<int, int>> sublistsRows;
|
||||
QByteArray rawData = data->data(YACReader::YACReaderLibrarSubReadingListMimeDataFormat);
|
||||
QDataStream in(&rawData,QIODevice::ReadOnly);
|
||||
in >> sublistsRows; //deserialize the list of indentifiers
|
||||
if(parent.row()!= sublistsRows.at(0).second)
|
||||
QDataStream in(&rawData, QIODevice::ReadOnly);
|
||||
in >> sublistsRows; //deserialize the list of indentifiers
|
||||
if (parent.row() != sublistsRows.at(0).second)
|
||||
return false;
|
||||
return data->formats().contains(YACReader::YACReaderLibrarSubReadingListMimeDataFormat);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,10 +227,10 @@ bool ReadingListModel::canDropMimeData(const QMimeData *data, Qt::DropAction act
|
||||
bool ReadingListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||
{
|
||||
QLOG_DEBUG() << "drop mimedata into row = " << row << " column = " << column << "parent" << parent;
|
||||
if(data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat))
|
||||
if (data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat))
|
||||
return dropComics(data, action, row, column, parent);
|
||||
|
||||
if(data->formats().contains(YACReader::YACReaderLibrarSubReadingListMimeDataFormat))
|
||||
if (data->formats().contains(YACReader::YACReaderLibrarSubReadingListMimeDataFormat))
|
||||
return dropSublist(data, action, row, column, parent);
|
||||
|
||||
return false;
|
||||
@ -261,17 +247,15 @@ bool ReadingListModel::dropComics(const QMimeData *data, Qt::DropAction action,
|
||||
QModelIndex dest;
|
||||
QModelIndex parentDest;
|
||||
|
||||
if(row == -1)
|
||||
{
|
||||
if (row == -1) {
|
||||
dest = parent;
|
||||
}
|
||||
else
|
||||
dest = index(row,column,parent);
|
||||
} else
|
||||
dest = index(row, column, parent);
|
||||
|
||||
parentDest = dest.parent();
|
||||
|
||||
if(rowIsSpecialList(dest.row(),parentDest)) {
|
||||
if(dest.row() == 0) //add to favorites
|
||||
if (rowIsSpecialList(dest.row(), parentDest)) {
|
||||
if (dest.row() == 0) //add to favorites
|
||||
{
|
||||
QLOG_DEBUG() << "-------addComicsToFavorites : " << comicIds << " to " << dest.data(IDRole).toULongLong();
|
||||
emit addComicsToFavorites(comicIds);
|
||||
@ -279,15 +263,15 @@ bool ReadingListModel::dropComics(const QMimeData *data, Qt::DropAction action,
|
||||
}
|
||||
}
|
||||
|
||||
if(rowIsLabel(dest.row(),parentDest)) {
|
||||
if (rowIsLabel(dest.row(), parentDest)) {
|
||||
QLOG_DEBUG() << "+++++++++++addComicsToLabel : " << comicIds << " to " << dest.data(IDRole).toULongLong();
|
||||
emit addComicsToLabel(comicIds, dest.data(IDRole).toULongLong());
|
||||
emit addComicsToLabel(comicIds, dest.data(IDRole).toULongLong());
|
||||
return true;
|
||||
}
|
||||
|
||||
if(rowIsReadingList(dest.row(),parentDest)) {
|
||||
if (rowIsReadingList(dest.row(), parentDest)) {
|
||||
QLOG_DEBUG() << "///////////addComicsToReadingList : " << comicIds << " to " << dest.data(IDRole).toULongLong();
|
||||
emit addComicsToReadingList(comicIds, dest.data(IDRole).toULongLong());
|
||||
emit addComicsToReadingList(comicIds, dest.data(IDRole).toULongLong());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -299,33 +283,32 @@ bool ReadingListModel::dropSublist(const QMimeData *data, Qt::DropAction action,
|
||||
Q_UNUSED(action);
|
||||
Q_UNUSED(column);
|
||||
|
||||
QList<QPair<int,int> > sublistsRows;
|
||||
QList<QPair<int, int>> sublistsRows;
|
||||
QByteArray rawData = data->data(YACReader::YACReaderLibrarSubReadingListMimeDataFormat);
|
||||
QDataStream in(&rawData,QIODevice::ReadOnly);
|
||||
in >> sublistsRows; //deserialize the list of indentifiers
|
||||
QDataStream in(&rawData, QIODevice::ReadOnly);
|
||||
in >> sublistsRows; //deserialize the list of indentifiers
|
||||
|
||||
QLOG_DEBUG() << "dropped : " << sublistsRows;
|
||||
|
||||
int sourceRow = sublistsRows.at(0).first;
|
||||
int destRow = row;
|
||||
QModelIndex destParent = parent;
|
||||
if(row == -1)
|
||||
{
|
||||
if (row == -1) {
|
||||
QLOG_DEBUG() << "droping inside parent";
|
||||
destRow = parent.row();
|
||||
destParent = parent.parent();
|
||||
}
|
||||
QLOG_DEBUG() << "move " << sourceRow << "-" << destRow;
|
||||
|
||||
if(sourceRow == destRow)
|
||||
if (sourceRow == destRow)
|
||||
return false;
|
||||
|
||||
//beginMoveRows(destParent,sourceRow,sourceRow,destParent,destRow);
|
||||
|
||||
ReadingListItem * parentItem = static_cast<ReadingListItem *>(destParent.internalPointer());
|
||||
ReadingListItem * child = parentItem->child(sourceRow);
|
||||
ReadingListItem *parentItem = static_cast<ReadingListItem *>(destParent.internalPointer());
|
||||
ReadingListItem *child = parentItem->child(sourceRow);
|
||||
parentItem->removeChild(child);
|
||||
parentItem->appendChild(child,destRow);
|
||||
parentItem->appendChild(child, destRow);
|
||||
|
||||
reorderingChildren(parentItem->children());
|
||||
//endMoveRows();
|
||||
@ -337,28 +320,26 @@ QMimeData *ReadingListModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
QLOG_DEBUG() << "mimeData requested" << indexes;
|
||||
|
||||
if(indexes.length() == 0)
|
||||
{
|
||||
if (indexes.length() == 0) {
|
||||
QLOG_ERROR() << "mimeData requested: indexes is empty";
|
||||
return new QMimeData();//TODO what happens if 0 is returned?
|
||||
return new QMimeData(); //TODO what happens if 0 is returned?
|
||||
}
|
||||
|
||||
if(indexes.length() > 1)
|
||||
{
|
||||
if (indexes.length() > 1) {
|
||||
QLOG_DEBUG() << "mimeData requested for more than one index, this shouldn't be possible";
|
||||
}
|
||||
|
||||
QModelIndex modelIndex = indexes.at(0);
|
||||
|
||||
QList<QPair<int,int> > rows;
|
||||
rows << QPair<int,int>(modelIndex.row(),modelIndex.parent().row());
|
||||
QList<QPair<int, int>> rows;
|
||||
rows << QPair<int, int>(modelIndex.row(), modelIndex.parent().row());
|
||||
QLOG_DEBUG() << "mimeData requested for row : " << modelIndex.row();
|
||||
|
||||
QByteArray data;
|
||||
QDataStream out(&data,QIODevice::WriteOnly);
|
||||
QDataStream out(&data, QIODevice::WriteOnly);
|
||||
out << rows; //serialize the list of identifiers
|
||||
|
||||
QMimeData * mimeData = new QMimeData();
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
mimeData->setData(YACReader::YACReaderLibrarSubReadingListMimeDataFormat, data);
|
||||
|
||||
return mimeData;
|
||||
@ -395,8 +376,7 @@ void ReadingListModel::addNewLabel(const QString &name, YACReader::LabelColors c
|
||||
qulonglong id = DBHelper::insertLabel(name, color, db);
|
||||
|
||||
int newPos = addLabelIntoList(new LabelItem(QList<QVariant>() << name << YACReader::colorToName(color) << id << color));
|
||||
beginInsertRows(QModelIndex(),specialLists.count()+1+newPos+1, specialLists.count()+1+newPos+1);
|
||||
|
||||
beginInsertRows(QModelIndex(), specialLists.count() + 1 + newPos + 1, specialLists.count() + 1 + newPos + 1);
|
||||
|
||||
endInsertRows();
|
||||
|
||||
@ -409,14 +389,14 @@ void ReadingListModel::addReadingList(const QString &name)
|
||||
|
||||
beginInsertRows(QModelIndex(), 0, 0); //TODO calculate the right coordinates before inserting
|
||||
|
||||
qulonglong id = DBHelper::insertReadingList(name,db);
|
||||
ReadingListItem * newItem;
|
||||
qulonglong id = DBHelper::insertReadingList(name, db);
|
||||
ReadingListItem *newItem;
|
||||
rootItem->appendChild(newItem = new ReadingListItem(QList<QVariant>()
|
||||
<< name
|
||||
<< id
|
||||
<< false
|
||||
<< true
|
||||
<< 0));
|
||||
<< name
|
||||
<< id
|
||||
<< false
|
||||
<< true
|
||||
<< 0));
|
||||
|
||||
items.insert(id, newItem);
|
||||
|
||||
@ -424,7 +404,6 @@ void ReadingListModel::addReadingList(const QString &name)
|
||||
|
||||
pos += specialLists.count()+1+labels.count()+labels.count()>0?1:0;*/
|
||||
|
||||
|
||||
endInsertRows();
|
||||
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
@ -436,16 +415,16 @@ void ReadingListModel::addReadingListAt(const QString &name, const QModelIndex &
|
||||
|
||||
beginInsertRows(mi, 0, 0); //TODO calculate the right coordinates before inserting
|
||||
|
||||
ReadingListItem * readingListParent = static_cast<ReadingListItem*>(mi.internalPointer());
|
||||
qulonglong id = DBHelper::insertReadingSubList(name,mi.data(IDRole).toULongLong(),readingListParent->childCount(),db);
|
||||
ReadingListItem * newItem;
|
||||
ReadingListItem *readingListParent = static_cast<ReadingListItem *>(mi.internalPointer());
|
||||
qulonglong id = DBHelper::insertReadingSubList(name, mi.data(IDRole).toULongLong(), readingListParent->childCount(), db);
|
||||
ReadingListItem *newItem;
|
||||
|
||||
readingListParent->appendChild(newItem = new ReadingListItem(QList<QVariant>()
|
||||
<< name
|
||||
<< id
|
||||
<< false
|
||||
<< true
|
||||
<< readingListParent->childCount()));
|
||||
<< name
|
||||
<< id
|
||||
<< false
|
||||
<< true
|
||||
<< readingListParent->childCount()));
|
||||
|
||||
items.insert(id, newItem);
|
||||
|
||||
@ -453,7 +432,6 @@ void ReadingListModel::addReadingListAt(const QString &name, const QModelIndex &
|
||||
|
||||
pos += specialLists.count()+1+labels.count()+labels.count()>0?1:0;*/
|
||||
|
||||
|
||||
endInsertRows();
|
||||
|
||||
QSqlDatabase::removeDatabase(db.connectionName());
|
||||
@ -461,67 +439,61 @@ void ReadingListModel::addReadingListAt(const QString &name, const QModelIndex &
|
||||
|
||||
bool ReadingListModel::isEditable(const QModelIndex &mi)
|
||||
{
|
||||
if(!mi.isValid())
|
||||
if (!mi.isValid())
|
||||
return false;
|
||||
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||
ListItem *item = static_cast<ListItem *>(mi.internalPointer());
|
||||
return typeid(*item) != typeid(SpecialListItem);
|
||||
}
|
||||
|
||||
bool ReadingListModel::isReadingList(const QModelIndex &mi)
|
||||
{
|
||||
if(!mi.isValid())
|
||||
if (!mi.isValid())
|
||||
return false;
|
||||
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||
ListItem *item = static_cast<ListItem *>(mi.internalPointer());
|
||||
return typeid(*item) == typeid(ReadingListItem);
|
||||
}
|
||||
|
||||
bool ReadingListModel::isReadingSubList(const QModelIndex &mi)
|
||||
{
|
||||
if(!mi.isValid())
|
||||
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)
|
||||
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
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ReadingListModel::name(const QModelIndex &mi)
|
||||
{
|
||||
return data(mi,Qt::DisplayRole).toString();
|
||||
return data(mi, Qt::DisplayRole).toString();
|
||||
}
|
||||
|
||||
void ReadingListModel::rename(const QModelIndex &mi, const QString &name)
|
||||
{
|
||||
if(!isEditable(mi))
|
||||
if (!isEditable(mi))
|
||||
return;
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
|
||||
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||
ListItem *item = static_cast<ListItem *>(mi.internalPointer());
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * rli = static_cast<ReadingListItem*>(item);
|
||||
if (typeid(*item) == typeid(ReadingListItem)) {
|
||||
ReadingListItem *rli = static_cast<ReadingListItem *>(item);
|
||||
rli->setName(name);
|
||||
DBHelper::renameList(item->getId(), name, db);
|
||||
|
||||
if(rli->parent->getId()!=0)
|
||||
{
|
||||
if (rli->parent->getId() != 0) {
|
||||
//TODO
|
||||
//move row depending on the name
|
||||
}else
|
||||
} else
|
||||
emit dataChanged(index(mi.row(), 0), index(mi.row(), 0));
|
||||
}
|
||||
else if(typeid(*item) == typeid(LabelItem))
|
||||
{
|
||||
LabelItem * li = static_cast<LabelItem*>(item);
|
||||
} 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));
|
||||
@ -532,31 +504,26 @@ void ReadingListModel::rename(const QModelIndex &mi, const QString &name)
|
||||
|
||||
void ReadingListModel::deleteItem(const QModelIndex &mi)
|
||||
{
|
||||
if(isEditable(mi))
|
||||
{
|
||||
if (isEditable(mi)) {
|
||||
QLOG_DEBUG() << "parent row :" << mi.parent().data() << "-" << mi.row();
|
||||
beginRemoveRows(mi.parent(),mi.row(),mi.row());
|
||||
beginRemoveRows(mi.parent(), mi.row(), mi.row());
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
|
||||
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||
ListItem *item = static_cast<ListItem *>(mi.internalPointer());
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * rli = static_cast<ReadingListItem*>(item);
|
||||
if (typeid(*item) == typeid(ReadingListItem)) {
|
||||
ReadingListItem *rli = static_cast<ReadingListItem *>(item);
|
||||
QLOG_DEBUG() << "num children : " << rli->parent->childCount();
|
||||
rli->parent->removeChild(rli);
|
||||
QLOG_DEBUG() << "num children : " << rli->parent->childCount();
|
||||
DBHelper::removeListFromDB(item->getId(), db);
|
||||
if(rli->parent->getId()!=0)
|
||||
{
|
||||
if (rli->parent->getId() != 0) {
|
||||
reorderingChildren(rli->parent->children());
|
||||
}
|
||||
QLOG_DEBUG() << "num children : " << rli->parent->childCount();
|
||||
}
|
||||
else if(typeid(*item) == typeid(LabelItem))
|
||||
{
|
||||
LabelItem * li = static_cast<LabelItem*>(item);
|
||||
} else if (typeid(*item) == typeid(LabelItem)) {
|
||||
LabelItem *li = static_cast<LabelItem *>(item);
|
||||
labels.removeOne(li);
|
||||
DBHelper::removeLabelFromDB(item->getId(), db);
|
||||
}
|
||||
@ -574,8 +541,7 @@ const QList<LabelItem *> ReadingListModel::getLabels()
|
||||
|
||||
void ReadingListModel::cleanAll()
|
||||
{
|
||||
if(rootItem != 0)
|
||||
{
|
||||
if (rootItem != 0) {
|
||||
delete rootItem;
|
||||
|
||||
qDeleteAll(specialLists);
|
||||
@ -592,7 +558,7 @@ void ReadingListModel::cleanAll()
|
||||
|
||||
void ReadingListModel::setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent)
|
||||
{
|
||||
items.insert(parent->getId(),parent);
|
||||
items.insert(parent->getId(), parent);
|
||||
|
||||
QSqlRecord record = sqlquery.record();
|
||||
|
||||
@ -603,53 +569,52 @@ void ReadingListModel::setupReadingListsData(QSqlQuery &sqlquery, ReadingListIte
|
||||
int ordering = record.indexOf("ordering");
|
||||
int parentId = record.indexOf("parentId");
|
||||
|
||||
while (sqlquery.next())
|
||||
{
|
||||
ReadingListItem * rli = new ReadingListItem(QList<QVariant>()
|
||||
<< sqlquery.value(name)
|
||||
<< sqlquery.value(id)
|
||||
<< sqlquery.value(finished)
|
||||
<< sqlquery.value(completed)
|
||||
<< sqlquery.value(ordering));
|
||||
while (sqlquery.next()) {
|
||||
ReadingListItem *rli = new ReadingListItem(QList<QVariant>()
|
||||
<< sqlquery.value(name)
|
||||
<< sqlquery.value(id)
|
||||
<< sqlquery.value(finished)
|
||||
<< sqlquery.value(completed)
|
||||
<< sqlquery.value(ordering));
|
||||
|
||||
ReadingListItem * currentParent;
|
||||
if(sqlquery.value(parentId).isNull())
|
||||
ReadingListItem *currentParent;
|
||||
if (sqlquery.value(parentId).isNull())
|
||||
currentParent = rootItem;
|
||||
else
|
||||
currentParent = items.value(sqlquery.value(parentId).toULongLong());
|
||||
|
||||
currentParent->appendChild(rli);
|
||||
|
||||
items.insert(rli->getId(),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,name",db);
|
||||
QSqlQuery selectQuery("SELECT * FROM default_reading_list ORDER BY id,name", db);
|
||||
|
||||
QSqlRecord record = selectQuery.record();
|
||||
|
||||
int name = record.indexOf("name");
|
||||
int id = record.indexOf("id");
|
||||
|
||||
while(selectQuery.next()) {
|
||||
while (selectQuery.next()) {
|
||||
list << new SpecialListItem(QList<QVariant>()
|
||||
<< selectQuery.value(name)
|
||||
<< selectQuery.value(id));
|
||||
}
|
||||
|
||||
//Reading after Favorites, Why? Because I want to :P
|
||||
list.insert(1,new SpecialListItem(QList<QVariant>() << "Reading" << 0));
|
||||
list.insert(1, new SpecialListItem(QList<QVariant>() << "Reading" << 0));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void ReadingListModel::setupLabels(QSqlDatabase & db)
|
||||
void ReadingListModel::setupLabels(QSqlDatabase &db)
|
||||
{
|
||||
QSqlQuery selectQuery("SELECT * FROM label ORDER BY ordering,name",db);
|
||||
QSqlQuery selectQuery("SELECT * FROM label ORDER BY ordering,name", db);
|
||||
|
||||
QSqlRecord record = selectQuery.record();
|
||||
|
||||
@ -658,7 +623,7 @@ void ReadingListModel::setupLabels(QSqlDatabase & db)
|
||||
int id = record.indexOf("id");
|
||||
int ordering = record.indexOf("ordering");
|
||||
|
||||
while(selectQuery.next()) {
|
||||
while (selectQuery.next()) {
|
||||
addLabelIntoList(new LabelItem(QList<QVariant>()
|
||||
<< selectQuery.value(name)
|
||||
<< selectQuery.value(color)
|
||||
@ -668,69 +633,62 @@ void ReadingListModel::setupLabels(QSqlDatabase & db)
|
||||
|
||||
//TEST
|
||||
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("Oh Oh", "red", 1);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("lalala", "orange", 2);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("we are not sorry", "yellow", 3);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("there we go", "green", 4);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("oklabunga", "cyan", 5);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("hailer mailer", "blue", 6);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("lol", "violet", 7);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("problems", "purple", 8);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("me gussssta", "pink", 9);
|
||||
// INSERT INTO label (name, color, ordering) VALUES (":D", "white", 10);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("ainsss", "light", 11);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("put a smile on my face", "dark", 12);
|
||||
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("Oh Oh", "red", 1);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("lalala", "orange", 2);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("we are not sorry", "yellow", 3);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("there we go", "green", 4);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("oklabunga", "cyan", 5);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("hailer mailer", "blue", 6);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("lol", "violet", 7);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("problems", "purple", 8);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("me gussssta", "pink", 9);
|
||||
// INSERT INTO label (name, color, ordering) VALUES (":D", "white", 10);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("ainsss", "light", 11);
|
||||
// INSERT INTO label (name, color, ordering) VALUES ("put a smile on my face", "dark", 12);
|
||||
}
|
||||
|
||||
void ReadingListModel::setupReadingLists(QSqlDatabase & db)
|
||||
void ReadingListModel::setupReadingLists(QSqlDatabase &db)
|
||||
{
|
||||
//setup root item
|
||||
rootItem = new ReadingListItem(QList<QVariant>() << "ROOT" << 0 << true << false);
|
||||
|
||||
QSqlQuery selectQuery("select * from reading_list order by parentId IS NULL DESC",db);
|
||||
QSqlQuery selectQuery("select * from reading_list order by parentId IS NULL DESC", db);
|
||||
|
||||
//setup reading lists
|
||||
setupReadingListsData(selectQuery,rootItem);
|
||||
setupReadingListsData(selectQuery, rootItem);
|
||||
|
||||
//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"));
|
||||
// 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));
|
||||
// node1->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "sublist" << "atr",node1));
|
||||
}
|
||||
|
||||
int ReadingListModel::addLabelIntoList(LabelItem *item)
|
||||
{
|
||||
if(labels.isEmpty())
|
||||
if (labels.isEmpty())
|
||||
labels << item;
|
||||
else
|
||||
{
|
||||
else {
|
||||
int i = 0;
|
||||
|
||||
while (i < labels.count() && (labels.at(i)->colorid() < item->colorid()) )
|
||||
while (i < labels.count() && (labels.at(i)->colorid() < item->colorid()))
|
||||
i++;
|
||||
|
||||
if(i < labels.count())
|
||||
{
|
||||
if(labels.at(i)->colorid() == item->colorid()) //sort by name
|
||||
if (i < labels.count()) {
|
||||
if (labels.at(i)->colorid() == item->colorid()) //sort by name
|
||||
{
|
||||
while( i < labels.count() && labels.at(i)->colorid() == item->colorid() && naturalSortLessThanCI(labels.at(i)->name(),item->name()))
|
||||
while (i < labels.count() && labels.at(i)->colorid() == item->colorid() && naturalSortLessThanCI(labels.at(i)->name(), item->name()))
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(i >= labels.count())
|
||||
{
|
||||
if (i >= labels.count()) {
|
||||
QLOG_DEBUG() << "insertando label al final " << item->name();
|
||||
labels << item;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QLOG_DEBUG() << "insertando label en " << i << "-" << item->name();
|
||||
labels.insert(i,item);
|
||||
labels.insert(i, item);
|
||||
}
|
||||
|
||||
return i;
|
||||
@ -743,7 +701,7 @@ void ReadingListModel::reorderingChildren(QList<ReadingListItem *> children)
|
||||
{
|
||||
QList<qulonglong> childrenIds;
|
||||
int i = 0;
|
||||
foreach (ReadingListItem * item, children) {
|
||||
foreach (ReadingListItem *item, children) {
|
||||
item->setOrdering(i++);
|
||||
childrenIds << item->getId();
|
||||
}
|
||||
@ -755,10 +713,10 @@ void ReadingListModel::reorderingChildren(QList<ReadingListItem *> children)
|
||||
|
||||
bool ReadingListModel::rowIsSpecialList(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
if (parent.isValid())
|
||||
return false; //by now no sublists in special list
|
||||
|
||||
if(row >=0 && row < specialLists.count())
|
||||
if (row >= 0 && row < specialLists.count())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -766,10 +724,10 @@ bool ReadingListModel::rowIsSpecialList(int row, const QModelIndex &parent) cons
|
||||
|
||||
bool ReadingListModel::rowIsLabel(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
if (parent.isValid())
|
||||
return false; //by now no sublists in labels
|
||||
|
||||
if(row > specialLists.count() && row <= specialLists.count() + labels.count())
|
||||
if (row > specialLists.count() && row <= specialLists.count() + labels.count())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -777,12 +735,12 @@ bool ReadingListModel::rowIsLabel(int row, const QModelIndex &parent) const
|
||||
|
||||
bool ReadingListModel::rowIsReadingList(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
if (parent.isValid())
|
||||
return true; //only lists with sublists
|
||||
|
||||
int separatorsCount = labels.isEmpty()?1:2;
|
||||
int separatorsCount = labels.isEmpty() ? 1 : 2;
|
||||
|
||||
if(row >= specialLists.count() + labels.count() + separatorsCount)
|
||||
if (row >= specialLists.count() + labels.count() + separatorsCount)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -790,21 +748,20 @@ bool ReadingListModel::rowIsReadingList(int row, const QModelIndex &parent) cons
|
||||
|
||||
bool ReadingListModel::rowIsSeparator(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
if (parent.isValid())
|
||||
return false; //only separators at top level
|
||||
|
||||
if(row == specialLists.count())
|
||||
if (row == specialLists.count())
|
||||
return true;
|
||||
|
||||
int separatorsCount = labels.isEmpty()?1:2;
|
||||
if(separatorsCount == 2 && row == specialLists.count() + labels.count() + 1)
|
||||
return true;
|
||||
int separatorsCount = labels.isEmpty() ? 1 : 2;
|
||||
if (separatorsCount == 2 && row == specialLists.count() + labels.count() + 1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
ReadingListModelProxy::ReadingListModelProxy(QObject *parent)
|
||||
:QSortFilterProxyModel(parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -44,15 +44,15 @@ public:
|
||||
|
||||
//Convenience methods
|
||||
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);
|
||||
bool isReadingSubList(const QModelIndex & mi);
|
||||
QString name(const QModelIndex & mi);
|
||||
void rename(const QModelIndex & mi, const QString & name);
|
||||
void deleteItem(const QModelIndex & mi);
|
||||
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);
|
||||
bool isReadingSubList(const QModelIndex &mi);
|
||||
QString name(const QModelIndex &mi);
|
||||
void rename(const QModelIndex &mi, const QString &name);
|
||||
void deleteItem(const QModelIndex &mi);
|
||||
const QList<LabelItem *> getLabels();
|
||||
|
||||
enum Roles {
|
||||
@ -76,9 +76,9 @@ public:
|
||||
|
||||
signals:
|
||||
|
||||
void addComicsToFavorites(const QList<qulonglong> & comicIds);
|
||||
void addComicsToLabel(const QList<qulonglong> & comicIds, qulonglong labelId);
|
||||
void addComicsToReadingList(const QList<qulonglong> & comicIds, qulonglong readingListId);
|
||||
void addComicsToFavorites(const QList<qulonglong> &comicIds);
|
||||
void addComicsToLabel(const QList<qulonglong> &comicIds, qulonglong labelId);
|
||||
void addComicsToReadingList(const QList<qulonglong> &comicIds, qulonglong readingListId);
|
||||
|
||||
private:
|
||||
void cleanAll();
|
||||
@ -89,10 +89,10 @@ private:
|
||||
int addLabelIntoList(LabelItem *item);
|
||||
void reorderingChildren(QList<ReadingListItem *> children);
|
||||
|
||||
bool rowIsSpecialList(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
bool rowIsLabel(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
bool rowIsReadingList(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
bool rowIsSeparator(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
bool rowIsSpecialList(int row, const QModelIndex &parent = QModelIndex()) const;
|
||||
bool rowIsLabel(int row, const QModelIndex &parent = QModelIndex()) const;
|
||||
bool rowIsReadingList(int row, const QModelIndex &parent = QModelIndex()) const;
|
||||
bool rowIsSeparator(int row, const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
bool dropComics(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
bool dropSublist(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
@ -103,15 +103,14 @@ private:
|
||||
QList<LabelItem *> labels;
|
||||
|
||||
//Reading lists
|
||||
ReadingListItem * rootItem; //
|
||||
ReadingListItem *rootItem; //
|
||||
QMap<unsigned long long int, ReadingListItem *> items; //lists relationship
|
||||
|
||||
//separators
|
||||
ReadingListSeparatorItem * separator1;
|
||||
ReadingListSeparatorItem * separator2;
|
||||
ReadingListSeparatorItem *separator1;
|
||||
ReadingListSeparatorItem *separator2;
|
||||
|
||||
QString _databasePath;
|
||||
|
||||
};
|
||||
|
||||
#endif // READING_LIST_MODEL_H
|
||||
|
||||
Reference in New Issue
Block a user