diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index f389c213..81f8d6b2 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -127,7 +127,8 @@ HEADERS += comic_flow.h \ yacreader_reading_lists_view.h \ add_label_dialog.h \ yacreader_history_controller.h \ - yacreader_navigation_controller.h + yacreader_navigation_controller.h \ + empty_label_widget.h SOURCES += comic_flow.cpp \ @@ -183,7 +184,8 @@ SOURCES += comic_flow.cpp \ yacreader_reading_lists_view.cpp \ add_label_dialog.cpp \ yacreader_history_controller.cpp \ - yacreader_navigation_controller.cpp + yacreader_navigation_controller.cpp \ + empty_label_widget.cpp include(./server/server.pri) diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index a2027c46..07c56c1a 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -274,36 +274,50 @@ QStringList ComicModel::getPaths(const QString & _source) return paths; } -void ComicModel::setupModelData(unsigned long long int folderId,const QString & databasePath) +void ComicModel::setupFolderModelData(unsigned long long int folderId,const QString & databasePath) { - //QFile f(QCoreApplication::applicationDirPath()+"/performance.txt"); - //f.open(QIODevice::Append); - beginResetModel(); - //QElapsedTimer timer; - //timer.start(); - qDeleteAll(_data); - _data.clear(); + beginResetModel(); + qDeleteAll(_data); + _data.clear(); - //QTextStream txtS(&f); - //txtS << "TABLEMODEL: Tiempo de borrado: " << timer.elapsed() << "ms\r\n"; - _databasePath = databasePath; - QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); - { - //crear la consulta - //timer.restart(); - QSqlQuery selectQuery(db); - selectQuery.prepare("select ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); - selectQuery.bindValue(":parentId", folderId); - selectQuery.exec(); - //txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n"; - //timer.restart(); - setupModelData(selectQuery); - //txtS << "TABLEMODEL: Tiempo de creaci�n del modelo: " << timer.elapsed() << "ms\r\n"; - //selectQuery.finish(); - } - db.close(); - QSqlDatabase::removeDatabase(_databasePath); - endResetModel(); + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("select ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); + selectQuery.bindValue(":parentId", folderId); + selectQuery.exec(); + setupModelData(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); + + if(_data.length()==0) + emit isEmpty(); +} + +void ComicModel::setupLabelModelData(unsigned long long parentLabel, const QString &databasePath) +{ + beginResetModel(); + qDeleteAll(_data); + _data.clear(); + + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "INNER JOIN comic_label cl ON (c.id == cl.comic_id) " + "WHERE cl.label_id = :parentLabelId"); + selectQuery.bindValue(":parentLabelId", parentLabel); + selectQuery.exec(); + setupModelData(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); if(_data.length()==0) emit isEmpty(); diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h index 48d9ac65..3e808c3f 100644 --- a/YACReaderLibrary/db/comic_model.h +++ b/YACReaderLibrary/db/comic_model.h @@ -34,7 +34,8 @@ public: QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; - void setupModelData(unsigned long long int parentFolder,const QString & databasePath); + void setupFolderModelData(unsigned long long int parentFolder,const QString & databasePath); + void setupLabelModelData(unsigned long long int parentLabel, 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); diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index 6057a106..9f7185be 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -73,6 +73,9 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const return QVariant(ReadingListModel::Separator); } + if (role == ReadingListModel::IDRole) + return item->getId(); + if(typeid(*item) == typeid(ReadingListSeparatorItem)) return QVariant(); diff --git a/YACReaderLibrary/db/reading_list_model.h b/YACReaderLibrary/db/reading_list_model.h index ee50bef7..fb801d3c 100644 --- a/YACReaderLibrary/db/reading_list_model.h +++ b/YACReaderLibrary/db/reading_list_model.h @@ -52,6 +52,7 @@ public: enum Roles { TypeListsRole = Qt::UserRole + 1, + IDRole }; enum TypeList { diff --git a/YACReaderLibrary/empty_label_widget.cpp b/YACReaderLibrary/empty_label_widget.cpp new file mode 100644 index 00000000..35d2fe9d --- /dev/null +++ b/YACReaderLibrary/empty_label_widget.cpp @@ -0,0 +1,49 @@ +#include "empty_label_widget.h" + +EmptyLabelWidget::EmptyLabelWidget(QWidget *parent) : + QWidget(parent) +{ +#ifdef Q_OS_MAC + backgroundColor = "#FFFFFF"; +#else + backgroundColor = "#2A2A2A"; +#endif + + QVBoxLayout * layout = new QVBoxLayout; + + iconLabel = new QLabel(); + iconLabel->setPixmap(QPixmap(":/images/empty_label.png")); + iconLabel->setAlignment(Qt::AlignCenter); + + //titleLabel->setText(tr("This label doesn't contain comics yet") + QString("
%1
").arg(tr("Drag and drop folders and comics here"))); + titleLabel = new QLabel(("This label doesn't contain comics yet")); + titleLabel->setAlignment(Qt::AlignCenter); + +#ifdef Q_OS_MAC + titleLabel->setStyleSheet("QLabel {color:#888888; font-size:24px;font-family:Arial;font-weight:bold;}"); +#else + titleLabel->setStyleSheet("QLabel {color:#CCCCCC; font-size:24px;font-family:Arial;font-weight:bold;}"); +#endif + + layout->addSpacing(100); + layout->addWidget(iconLabel); + layout->addSpacing(30); + layout->addWidget(titleLabel); + layout->addStretch(); + + setLayout(layout); +} + +void EmptyLabelWidget::setColor(YACReader::LabelColors color) +{ + //TODO tint the widget depending on color + //backgroundColor = "#FF0000"; + + //repaint(); +} + +void EmptyLabelWidget::paintEvent(QPaintEvent * event) +{ + QPainter painter (this); + painter.fillRect(0,0,width(),height(),QColor(backgroundColor)); +} diff --git a/YACReaderLibrary/empty_label_widget.h b/YACReaderLibrary/empty_label_widget.h new file mode 100644 index 00000000..ac76f722 --- /dev/null +++ b/YACReaderLibrary/empty_label_widget.h @@ -0,0 +1,26 @@ +#ifndef EMPTY_LABEL_WIDGET_H +#define EMPTY_LABEL_WIDGET_H + +#include