mirror of
https://github.com/YACReader/yacreader
synced 2026-02-15 11:33:00 -05:00
models renaming
This commit is contained in:
@ -28,8 +28,8 @@ LIBS += -lpoppler-qt4
|
|||||||
INCLUDEPATH += ../dependencies/poppler/include/qt4
|
INCLUDEPATH += ../dependencies/poppler/include/qt4
|
||||||
}
|
}
|
||||||
|
|
||||||
#QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL
|
QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL
|
||||||
#QMAKE_LFLAGS_RELEASE += /LTCG
|
QMAKE_LFLAGS_RELEASE += /LTCG
|
||||||
CONFIG -= embed_manifest_exe
|
CONFIG -= embed_manifest_exe
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,47 +80,49 @@ HEADERS += comic_flow.h \
|
|||||||
library_creator.h \
|
library_creator.h \
|
||||||
library_window.h \
|
library_window.h \
|
||||||
add_library_dialog.h \
|
add_library_dialog.h \
|
||||||
rename_library_dialog.h \
|
rename_library_dialog.h \
|
||||||
properties_dialog.h \
|
properties_dialog.h \
|
||||||
options_dialog.h \
|
options_dialog.h \
|
||||||
export_library_dialog.h \
|
export_library_dialog.h \
|
||||||
import_library_dialog.h \
|
import_library_dialog.h \
|
||||||
package_manager.h \
|
package_manager.h \
|
||||||
bundle_creator.h \
|
bundle_creator.h \
|
||||||
export_comics_info_dialog.h \
|
export_comics_info_dialog.h \
|
||||||
import_comics_info_dialog.h \
|
import_comics_info_dialog.h \
|
||||||
server_config_dialog.h \
|
server_config_dialog.h \
|
||||||
comic_flow_widget.h \
|
comic_flow_widget.h \
|
||||||
db_helper.h \
|
db_helper.h \
|
||||||
./db/data_base_management.h \
|
./db/data_base_management.h \
|
||||||
./db/treeitem.h \
|
./db/folder_item.h \
|
||||||
./db/treemodel.h \
|
./db/folder_model.h \
|
||||||
./db/tablemodel.h \
|
./db/comic_model.h \
|
||||||
./db/tableitem.h \
|
./db/comic_item.h \
|
||||||
../common/comic_db.h \
|
../common/comic_db.h \
|
||||||
../common/folder.h \
|
../common/folder.h \
|
||||||
../common/library_item.h \
|
../common/library_item.h \
|
||||||
../common/comic.h \
|
../common/comic.h \
|
||||||
../common/bookmarks.h \
|
../common/bookmarks.h \
|
||||||
../common/pictureflow.h \
|
../common/pictureflow.h \
|
||||||
../common/custom_widgets.h \
|
../common/custom_widgets.h \
|
||||||
../common/qnaturalsorting.h \
|
../common/qnaturalsorting.h \
|
||||||
../common/yacreader_flow_gl.h \
|
../common/yacreader_flow_gl.h \
|
||||||
../common/yacreader_global.h \
|
../common/yacreader_global.h \
|
||||||
../common/onstart_flow_selection_dialog.h \
|
../common/onstart_flow_selection_dialog.h \
|
||||||
no_libraries_widget.h \
|
no_libraries_widget.h \
|
||||||
import_widget.h \
|
import_widget.h \
|
||||||
yacreader_local_server.h \
|
yacreader_local_server.h \
|
||||||
yacreader_main_toolbar.h \
|
yacreader_main_toolbar.h \
|
||||||
comics_remover.h \
|
comics_remover.h \
|
||||||
../common/http_worker.h \
|
../common/http_worker.h \
|
||||||
yacreader_libraries.h \
|
yacreader_libraries.h \
|
||||||
../common/exit_check.h \
|
../common/exit_check.h \
|
||||||
comics_view.h \
|
comics_view.h \
|
||||||
classic_comics_view.h \
|
classic_comics_view.h \
|
||||||
empty_folder_widget.h \
|
empty_folder_widget.h \
|
||||||
no_search_results_widget.h \
|
no_search_results_widget.h \
|
||||||
comic_files_manager.h
|
comic_files_manager.h \
|
||||||
|
db/reading_list_model.h \
|
||||||
|
db/reading_list_item.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += comic_flow.cpp \
|
SOURCES += comic_flow.cpp \
|
||||||
@ -129,50 +131,51 @@ SOURCES += comic_flow.cpp \
|
|||||||
library_window.cpp \
|
library_window.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
add_library_dialog.cpp \
|
add_library_dialog.cpp \
|
||||||
rename_library_dialog.cpp \
|
rename_library_dialog.cpp \
|
||||||
properties_dialog.cpp \
|
properties_dialog.cpp \
|
||||||
options_dialog.cpp \
|
options_dialog.cpp \
|
||||||
export_library_dialog.cpp \
|
export_library_dialog.cpp \
|
||||||
import_library_dialog.cpp \
|
import_library_dialog.cpp \
|
||||||
package_manager.cpp \
|
package_manager.cpp \
|
||||||
bundle_creator.cpp \
|
bundle_creator.cpp \
|
||||||
export_comics_info_dialog.cpp \
|
export_comics_info_dialog.cpp \
|
||||||
import_comics_info_dialog.cpp \
|
import_comics_info_dialog.cpp \
|
||||||
server_config_dialog.cpp \
|
server_config_dialog.cpp \
|
||||||
comic_flow_widget.cpp \
|
comic_flow_widget.cpp \
|
||||||
db_helper.cpp \
|
db_helper.cpp \
|
||||||
./db/data_base_management.cpp \
|
./db/data_base_management.cpp \
|
||||||
./db/treeitem.cpp \
|
./db/folder_item.cpp \
|
||||||
./db/treemodel.cpp \
|
./db/folder_model.cpp \
|
||||||
./db/tablemodel.cpp \
|
./db/comic_model.cpp \
|
||||||
./db/tableitem.cpp \
|
./db/comic_item.cpp \
|
||||||
../common/comic_db.cpp \
|
../common/comic_db.cpp \
|
||||||
../common/folder.cpp \
|
../common/folder.cpp \
|
||||||
../common/library_item.cpp \
|
../common/library_item.cpp \
|
||||||
../common/comic.cpp \
|
../common/comic.cpp \
|
||||||
../common/bookmarks.cpp \
|
../common/bookmarks.cpp \
|
||||||
../common/pictureflow.cpp \
|
../common/pictureflow.cpp \
|
||||||
../common/custom_widgets.cpp \
|
../common/custom_widgets.cpp \
|
||||||
../common/qnaturalsorting.cpp \
|
../common/qnaturalsorting.cpp \
|
||||||
../common/yacreader_flow_gl.cpp \
|
../common/yacreader_flow_gl.cpp \
|
||||||
../common/onstart_flow_selection_dialog.cpp \
|
../common/onstart_flow_selection_dialog.cpp \
|
||||||
no_libraries_widget.cpp \
|
no_libraries_widget.cpp \
|
||||||
import_widget.cpp \
|
import_widget.cpp \
|
||||||
yacreader_local_server.cpp \
|
yacreader_local_server.cpp \
|
||||||
yacreader_main_toolbar.cpp \
|
yacreader_main_toolbar.cpp \
|
||||||
comics_remover.cpp \
|
comics_remover.cpp \
|
||||||
../common/http_worker.cpp \
|
../common/http_worker.cpp \
|
||||||
../common/yacreader_global.cpp \
|
../common/yacreader_global.cpp \
|
||||||
yacreader_libraries.cpp \
|
yacreader_libraries.cpp \
|
||||||
../common/exit_check.cpp \
|
../common/exit_check.cpp \
|
||||||
comics_view.cpp \
|
comics_view.cpp \
|
||||||
classic_comics_view.cpp \
|
classic_comics_view.cpp \
|
||||||
empty_folder_widget.cpp \
|
empty_folder_widget.cpp \
|
||||||
no_search_results_widget.cpp \
|
no_search_results_widget.cpp \
|
||||||
comic_files_manager.cpp
|
comic_files_manager.cpp \
|
||||||
|
db/reading_list_model.cpp \
|
||||||
|
db/reading_list_item.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include(./server/server.pri)
|
include(./server/server.pri)
|
||||||
include(../custom_widgets/custom_widgets_yacreaderlibrary.pri)
|
include(../custom_widgets/custom_widgets_yacreaderlibrary.pri)
|
||||||
include(../compressed_archive/wrapper.pri)
|
include(../compressed_archive/wrapper.pri)
|
||||||
|
|||||||
@ -92,7 +92,7 @@ void ClassicComicsView::setToolBar(QToolBar *toolBar)
|
|||||||
static_cast<QVBoxLayout *>(comics->layout())->insertWidget(0,toolBar);
|
static_cast<QVBoxLayout *>(comics->layout())->insertWidget(0,toolBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassicComicsView::setModel(TableModel *model)
|
void ClassicComicsView::setModel(ComicModel *model)
|
||||||
{
|
{
|
||||||
|
|
||||||
ComicsView::setModel(model);
|
ComicsView::setModel(model);
|
||||||
@ -118,14 +118,14 @@ void ClassicComicsView::setModel(TableModel *model)
|
|||||||
for(int i = 0;i<tableView->horizontalHeader()->count();i++)
|
for(int i = 0;i<tableView->horizontalHeader()->count();i++)
|
||||||
tableView->horizontalHeader()->hideSection(i);
|
tableView->horizontalHeader()->hideSection(i);
|
||||||
|
|
||||||
tableView->horizontalHeader()->showSection(TableModel::Number);
|
tableView->horizontalHeader()->showSection(ComicModel::Number);
|
||||||
tableView->horizontalHeader()->showSection(TableModel::Title);
|
tableView->horizontalHeader()->showSection(ComicModel::Title);
|
||||||
tableView->horizontalHeader()->showSection(TableModel::FileName);
|
tableView->horizontalHeader()->showSection(ComicModel::FileName);
|
||||||
tableView->horizontalHeader()->showSection(TableModel::NumPages);
|
tableView->horizontalHeader()->showSection(ComicModel::NumPages);
|
||||||
tableView->horizontalHeader()->showSection(TableModel::Hash); //Size is part of the Hash...TODO add Columns::Size to Columns
|
tableView->horizontalHeader()->showSection(ComicModel::Hash); //Size is part of the Hash...TODO add Columns::Size to Columns
|
||||||
tableView->horizontalHeader()->showSection(TableModel::ReadColumn);
|
tableView->horizontalHeader()->showSection(ComicModel::ReadColumn);
|
||||||
tableView->horizontalHeader()->showSection(TableModel::CurrentPage);
|
tableView->horizontalHeader()->showSection(ComicModel::CurrentPage);
|
||||||
tableView->horizontalHeader()->showSection(TableModel::Rating);
|
tableView->horizontalHeader()->showSection(ComicModel::Rating);
|
||||||
|
|
||||||
//debido a un bug, qt4 no es capaz de ajustar el ancho teniendo en cuenta todas la filas (no sólo las visibles)
|
//debido a un bug, qt4 no es capaz de ajustar el ancho teniendo en cuenta todas la filas (no sólo las visibles)
|
||||||
//así que se ecala la primera vez y después se deja el control al usuario.
|
//así que se ecala la primera vez y después se deja el control al usuario.
|
||||||
@ -265,7 +265,7 @@ void ClassicComicsView::applyModelChanges(const QModelIndex &topLeft, const QMod
|
|||||||
{
|
{
|
||||||
Q_UNUSED(topLeft);
|
Q_UNUSED(topLeft);
|
||||||
Q_UNUSED(bottomRight);
|
Q_UNUSED(bottomRight);
|
||||||
if(roles.contains(TableModel::ReadColumnRole))
|
if(roles.contains(ComicModel::ReadColumnRole))
|
||||||
{
|
{
|
||||||
comicFlow->setMarks(model->getReadList());
|
comicFlow->setMarks(model->getReadList());
|
||||||
comicFlow->updateMarks();
|
comicFlow->updateMarks();
|
||||||
|
|||||||
@ -10,7 +10,7 @@ class YACReaderTableView;
|
|||||||
class QSplitter;
|
class QSplitter;
|
||||||
class ComicFlowWidget;
|
class ComicFlowWidget;
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
class TableModel;
|
class ComicModel;
|
||||||
class QStackedWidget;
|
class QStackedWidget;
|
||||||
|
|
||||||
class ClassicComicsView : public ComicsView
|
class ClassicComicsView : public ComicsView
|
||||||
@ -19,7 +19,7 @@ class ClassicComicsView : public ComicsView
|
|||||||
public:
|
public:
|
||||||
ClassicComicsView(QWidget *parent = 0);
|
ClassicComicsView(QWidget *parent = 0);
|
||||||
void setToolBar(QToolBar * toolBar);
|
void setToolBar(QToolBar * toolBar);
|
||||||
void setModel(TableModel *model);
|
void setModel(ComicModel *model);
|
||||||
void setCurrentIndex(const QModelIndex &index);
|
void setCurrentIndex(const QModelIndex &index);
|
||||||
QModelIndex currentIndex();
|
QModelIndex currentIndex();
|
||||||
QItemSelectionModel * selectionModel();
|
QItemSelectionModel * selectionModel();
|
||||||
|
|||||||
@ -10,7 +10,7 @@ ComicsView::ComicsView(QWidget *parent) :
|
|||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComicsView::setModel(TableModel *m)
|
void ComicsView::setModel(ComicModel *m)
|
||||||
{
|
{
|
||||||
model = m;
|
model = m;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,20 +3,20 @@
|
|||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
#include "tablemodel.h"
|
#include "comic_model.h"
|
||||||
|
|
||||||
class YACReaderTableView;
|
class YACReaderTableView;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
class ComicFlowWidget;
|
class ComicFlowWidget;
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
class TableModel;
|
class ComicModel;
|
||||||
class ComicsView : public QWidget
|
class ComicsView : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ComicsView(QWidget *parent = 0);
|
explicit ComicsView(QWidget *parent = 0);
|
||||||
virtual void setToolBar(QToolBar * toolBar) = 0;
|
virtual void setToolBar(QToolBar * toolBar) = 0;
|
||||||
virtual void setModel(TableModel *model);
|
virtual void setModel(ComicModel *model);
|
||||||
virtual void setCurrentIndex(const QModelIndex &index) = 0;
|
virtual void setCurrentIndex(const QModelIndex &index) = 0;
|
||||||
virtual QModelIndex currentIndex() = 0;
|
virtual QModelIndex currentIndex() = 0;
|
||||||
virtual QItemSelectionModel * selectionModel() = 0;
|
virtual QItemSelectionModel * selectionModel() = 0;
|
||||||
@ -42,7 +42,7 @@ public slots:
|
|||||||
virtual void setShowMarks(bool show) = 0;
|
virtual void setShowMarks(bool show) = 0;
|
||||||
virtual void selectAll() = 0;
|
virtual void selectAll() = 0;
|
||||||
protected:
|
protected:
|
||||||
TableModel * model;
|
ComicModel * model;
|
||||||
|
|
||||||
//Drop to import
|
//Drop to import
|
||||||
void dragEnterEvent(QDragEnterEvent *event);
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
|||||||
47
YACReaderLibrary/db/comic_item.cpp
Normal file
47
YACReaderLibrary/db/comic_item.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include "comic_item.h"
|
||||||
|
|
||||||
|
//! [0]
|
||||||
|
ComicItem::ComicItem(const QList<QVariant> &data)
|
||||||
|
|
||||||
|
{
|
||||||
|
itemData = data;
|
||||||
|
}
|
||||||
|
//! [0]
|
||||||
|
|
||||||
|
//! [1]
|
||||||
|
ComicItem::~ComicItem()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//! [1]
|
||||||
|
|
||||||
|
|
||||||
|
//! [5]
|
||||||
|
int ComicItem::columnCount() const
|
||||||
|
{
|
||||||
|
return itemData.count();
|
||||||
|
}
|
||||||
|
//! [5]
|
||||||
|
|
||||||
|
//! [6]
|
||||||
|
QVariant ComicItem::data(int column) const
|
||||||
|
{
|
||||||
|
return itemData.value(column);
|
||||||
|
}
|
||||||
|
//! [6]
|
||||||
|
|
||||||
|
void ComicItem::setData(int column,const QVariant & value)
|
||||||
|
{
|
||||||
|
itemData[column] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [8]
|
||||||
|
int ComicItem::row() const
|
||||||
|
{
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//! [8]
|
||||||
@ -5,12 +5,12 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class TableItem : public QObject
|
class ComicItem : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TableItem(const QList<QVariant> &data);
|
ComicItem(const QList<QVariant> &data);
|
||||||
~TableItem();
|
~ComicItem();
|
||||||
int columnCount() const;
|
int columnCount() const;
|
||||||
QVariant data(int column) const;
|
QVariant data(int column) const;
|
||||||
void setData(int column,const QVariant & value);
|
void setData(int column,const QVariant & value);
|
||||||
@ -24,4 +24,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -3,8 +3,8 @@
|
|||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "tableitem.h"
|
#include "comic_item.h"
|
||||||
#include "tablemodel.h"
|
#include "comic_model.h"
|
||||||
#include "data_base_management.h"
|
#include "data_base_management.h"
|
||||||
#include "qnaturalsorting.h"
|
#include "qnaturalsorting.h"
|
||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
@ -14,7 +14,7 @@
|
|||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
|
|
||||||
|
|
||||||
TableModel::TableModel(QObject *parent)
|
ComicModel::ComicModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset()));
|
connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset()));
|
||||||
@ -22,7 +22,7 @@ TableModel::TableModel(QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
TableModel::TableModel( QSqlQuery &sqlquery, QObject *parent)
|
ComicModel::ComicModel( QSqlQuery &sqlquery, QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
setupModelData(sqlquery);
|
setupModelData(sqlquery);
|
||||||
@ -30,14 +30,14 @@ TableModel::TableModel( QSqlQuery &sqlquery, QObject *parent)
|
|||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
TableModel::~TableModel()
|
ComicModel::~ComicModel()
|
||||||
{
|
{
|
||||||
qDeleteAll(_data);
|
qDeleteAll(_data);
|
||||||
}
|
}
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
int TableModel::columnCount(const QModelIndex &parent) const
|
int ComicModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
if(_data.isEmpty())
|
if(_data.isEmpty())
|
||||||
@ -46,7 +46,7 @@ int TableModel::columnCount(const QModelIndex &parent) const
|
|||||||
}
|
}
|
||||||
//! [2]
|
//! [2]
|
||||||
|
|
||||||
QHash<int, QByteArray> TableModel::roleNames() const {
|
QHash<int, QByteArray> ComicModel::roleNames() const {
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
|
|
||||||
roles[NumberRole] = "number";
|
roles[NumberRole] = "number";
|
||||||
@ -68,7 +68,7 @@ QHash<int, QByteArray> TableModel::roleNames() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
QVariant TableModel::data(const QModelIndex &index, int role) const
|
QVariant ComicModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -88,13 +88,13 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
|
|||||||
{
|
{
|
||||||
switch(index.column())//TODO obtener esto de la query
|
switch(index.column())//TODO obtener esto de la query
|
||||||
{
|
{
|
||||||
case TableModel::Number:
|
case ComicModel::Number:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
case TableModel::NumPages:
|
case ComicModel::NumPages:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
case TableModel::Hash:
|
case ComicModel::Hash:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
case TableModel::CurrentPage:
|
case ComicModel::CurrentPage:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
default:
|
default:
|
||||||
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
|
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
@ -105,7 +105,7 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
|
|||||||
//TODO check here if any view is asking for TableModel::Roles
|
//TODO check here if any view is asking for TableModel::Roles
|
||||||
//these roles will be used from QML/GridView
|
//these roles will be used from QML/GridView
|
||||||
|
|
||||||
TableItem *item = static_cast<TableItem*>(index.internalPointer());
|
ComicItem *item = static_cast<ComicItem*>(index.internalPointer());
|
||||||
|
|
||||||
if (role == NumberRole)
|
if (role == NumberRole)
|
||||||
return item->data(Number);
|
return item->data(Number);
|
||||||
@ -122,19 +122,19 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
|
|||||||
else if (role == ReadColumnRole)
|
else if (role == ReadColumnRole)
|
||||||
return item->data(ReadColumn).toBool();
|
return item->data(ReadColumn).toBool();
|
||||||
else if (role == HasBeenOpenedRole)
|
else if (role == HasBeenOpenedRole)
|
||||||
return item->data(TableModel::HasBeenOpened);
|
return item->data(ComicModel::HasBeenOpened);
|
||||||
|
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if(index.column() == TableModel::Hash)
|
if(index.column() == ComicModel::Hash)
|
||||||
return QString::number(item->data(index.column()).toString().right(item->data(index.column()).toString().length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb";
|
return QString::number(item->data(index.column()).toString().right(item->data(index.column()).toString().length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb";
|
||||||
if(index.column() == TableModel::ReadColumn)
|
if(index.column() == ComicModel::ReadColumn)
|
||||||
return (item->data(TableModel::CurrentPage).toInt()==item->data(TableModel::NumPages).toInt() || item->data(TableModel::ReadColumn).toBool())?QVariant(tr("yes")):QVariant(tr("no"));
|
return (item->data(ComicModel::CurrentPage).toInt()==item->data(ComicModel::NumPages).toInt() || item->data(ComicModel::ReadColumn).toBool())?QVariant(tr("yes")):QVariant(tr("no"));
|
||||||
if(index.column() == TableModel::CurrentPage)
|
if(index.column() == ComicModel::CurrentPage)
|
||||||
return item->data(TableModel::HasBeenOpened).toBool()?item->data(index.column()):QVariant("-");
|
return item->data(ComicModel::HasBeenOpened).toBool()?item->data(index.column()):QVariant("-");
|
||||||
|
|
||||||
if (index.column() == TableModel::Rating)
|
if (index.column() == ComicModel::Rating)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
return item->data(index.column());
|
return item->data(index.column());
|
||||||
@ -142,39 +142,39 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
|
|||||||
//! [3]
|
//! [3]
|
||||||
|
|
||||||
//! [4]
|
//! [4]
|
||||||
Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags ComicModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
if(index.column() == TableModel::Rating)
|
if(index.column() == ComicModel::Rating)
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
//! [4]
|
//! [4]
|
||||||
|
|
||||||
//! [5]
|
//! [5]
|
||||||
QVariant TableModel::headerData(int section, Qt::Orientation orientation,
|
QVariant ComicModel::headerData(int section, Qt::Orientation orientation,
|
||||||
int role) const
|
int role) const
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
{
|
{
|
||||||
switch(section)//TODO obtener esto de la query
|
switch(section)//TODO obtener esto de la query
|
||||||
{
|
{
|
||||||
case TableModel::Number:
|
case ComicModel::Number:
|
||||||
return QVariant(QString("#"));
|
return QVariant(QString("#"));
|
||||||
case TableModel::Title:
|
case ComicModel::Title:
|
||||||
return QVariant(QString(tr("Title")));
|
return QVariant(QString(tr("Title")));
|
||||||
case TableModel::FileName:
|
case ComicModel::FileName:
|
||||||
return QVariant(QString(tr("File Name")));
|
return QVariant(QString(tr("File Name")));
|
||||||
case TableModel::NumPages:
|
case ComicModel::NumPages:
|
||||||
return QVariant(QString(tr("Pages")));
|
return QVariant(QString(tr("Pages")));
|
||||||
case TableModel::Hash:
|
case ComicModel::Hash:
|
||||||
return QVariant(QString(tr("Size")));
|
return QVariant(QString(tr("Size")));
|
||||||
case TableModel::ReadColumn:
|
case ComicModel::ReadColumn:
|
||||||
return QVariant(QString(tr("Read")));
|
return QVariant(QString(tr("Read")));
|
||||||
case TableModel::CurrentPage:
|
case ComicModel::CurrentPage:
|
||||||
return QVariant(QString(tr("Current Page")));
|
return QVariant(QString(tr("Current Page")));
|
||||||
case TableModel::Rating:
|
case ComicModel::Rating:
|
||||||
return QVariant(QString(tr("Rating")));
|
return QVariant(QString(tr("Rating")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,13 +183,13 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
{
|
{
|
||||||
switch(section)//TODO obtener esto de la query
|
switch(section)//TODO obtener esto de la query
|
||||||
{
|
{
|
||||||
case TableModel::Number:
|
case ComicModel::Number:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
case TableModel::NumPages:
|
case ComicModel::NumPages:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
case TableModel::Hash:
|
case ComicModel::Hash:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
case TableModel::CurrentPage:
|
case ComicModel::CurrentPage:
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
default:
|
default:
|
||||||
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
|
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
@ -199,7 +199,7 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
|
|
||||||
if(orientation == Qt::Vertical && role == Qt::DecorationRole)
|
if(orientation == Qt::Vertical && role == Qt::DecorationRole)
|
||||||
{
|
{
|
||||||
QString fileName = _data.value(section)->data(TableModel::FileName).toString();
|
QString fileName = _data.value(section)->data(ComicModel::FileName).toString();
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QString ext = fi.suffix();
|
QString ext = fi.suffix();
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
//! [5]
|
//! [5]
|
||||||
|
|
||||||
//! [6]
|
//! [6]
|
||||||
QModelIndex TableModel::index(int row, int column, const QModelIndex &parent)
|
QModelIndex ComicModel::index(int row, int column, const QModelIndex &parent)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
if (!hasIndex(row, column, parent))
|
if (!hasIndex(row, column, parent))
|
||||||
@ -240,7 +240,7 @@ QModelIndex TableModel::index(int row, int column, const QModelIndex &parent)
|
|||||||
//! [6]
|
//! [6]
|
||||||
|
|
||||||
//! [7]
|
//! [7]
|
||||||
QModelIndex TableModel::parent(const QModelIndex &index) const
|
QModelIndex ComicModel::parent(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(index)
|
Q_UNUSED(index)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
@ -248,7 +248,7 @@ QModelIndex TableModel::parent(const QModelIndex &index) const
|
|||||||
//! [7]
|
//! [7]
|
||||||
|
|
||||||
//! [8]
|
//! [8]
|
||||||
int TableModel::rowCount(const QModelIndex &parent) const
|
int ComicModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.column() > 0)
|
if (parent.column() > 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -260,21 +260,21 @@ int TableModel::rowCount(const QModelIndex &parent) const
|
|||||||
}
|
}
|
||||||
//! [8]
|
//! [8]
|
||||||
|
|
||||||
QStringList TableModel::getPaths(const QString & _source)
|
QStringList ComicModel::getPaths(const QString & _source)
|
||||||
{
|
{
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
QString source = _source + "/.yacreaderlibrary/covers/";
|
QString source = _source + "/.yacreaderlibrary/covers/";
|
||||||
QList<TableItem *>::ConstIterator itr;
|
QList<ComicItem *>::ConstIterator itr;
|
||||||
for(itr = _data.constBegin();itr != _data.constEnd();itr++)
|
for(itr = _data.constBegin();itr != _data.constEnd();itr++)
|
||||||
{
|
{
|
||||||
QString hash = (*itr)->data(TableModel::Hash).toString();
|
QString hash = (*itr)->data(ComicModel::Hash).toString();
|
||||||
paths << source+ hash +".jpg";
|
paths << source+ hash +".jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::setupModelData(unsigned long long int folderId,const QString & databasePath)
|
void ComicModel::setupModelData(unsigned long long int folderId,const QString & databasePath)
|
||||||
{
|
{
|
||||||
//QFile f(QCoreApplication::applicationDirPath()+"/performance.txt");
|
//QFile f(QCoreApplication::applicationDirPath()+"/performance.txt");
|
||||||
//f.open(QIODevice::Append);
|
//f.open(QIODevice::Append);
|
||||||
@ -309,7 +309,7 @@ void TableModel::setupModelData(unsigned long long int folderId,const QString &
|
|||||||
emit isEmpty();
|
emit isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::setupModelData(const SearchModifiers modifier, const QString &filter, const QString &databasePath)
|
void ComicModel::setupModelData(const SearchModifiers modifier, const QString &filter, const QString &databasePath)
|
||||||
{
|
{
|
||||||
//QFile f(QCoreApplication::applicationDirPath()+"/performance.txt");
|
//QFile f(QCoreApplication::applicationDirPath()+"/performance.txt");
|
||||||
//f.open(QIODevice::Append);
|
//f.open(QIODevice::Append);
|
||||||
@ -376,16 +376,16 @@ void TableModel::setupModelData(const SearchModifiers modifier, const QString &f
|
|||||||
emit searchNumResults(_data.length());
|
emit searchNumResults(_data.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TableModel::getComicPath(QModelIndex mi)
|
QString ComicModel::getComicPath(QModelIndex mi)
|
||||||
{
|
{
|
||||||
if(mi.isValid())
|
if(mi.isValid())
|
||||||
return _data.at(mi.row())->data(TableModel::Path).toString();
|
return _data.at(mi.row())->data(ComicModel::Path).toString();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::setupModelData(QSqlQuery &sqlquery)
|
void ComicModel::setupModelData(QSqlQuery &sqlquery)
|
||||||
{
|
{
|
||||||
TableItem * currentItem;
|
ComicItem * currentItem;
|
||||||
while (sqlquery.next())
|
while (sqlquery.next())
|
||||||
{
|
{
|
||||||
QList<QVariant> data;
|
QList<QVariant> data;
|
||||||
@ -393,26 +393,26 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
|
|||||||
for(int i=0;i<record.count();i++)
|
for(int i=0;i<record.count();i++)
|
||||||
data << record.value(i);
|
data << record.value(i);
|
||||||
|
|
||||||
currentItem = new TableItem(data);
|
currentItem = new ComicItem(data);
|
||||||
bool lessThan = false;
|
bool lessThan = false;
|
||||||
if(_data.isEmpty())
|
if(_data.isEmpty())
|
||||||
_data.append(currentItem);
|
_data.append(currentItem);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TableItem * last = _data.back();
|
ComicItem * last = _data.back();
|
||||||
QString nameLast = last->data(TableModel::FileName).toString();
|
QString nameLast = last->data(ComicModel::FileName).toString();
|
||||||
QString nameCurrent = currentItem->data(TableModel::FileName).toString();
|
QString nameCurrent = currentItem->data(ComicModel::FileName).toString();
|
||||||
int numberLast,numberCurrent;
|
int numberLast,numberCurrent;
|
||||||
int max = (std::numeric_limits<int>::max)();
|
int max = (std::numeric_limits<int>::max)();
|
||||||
numberLast = numberCurrent = max;
|
numberLast = numberCurrent = max;
|
||||||
|
|
||||||
if(!last->data(TableModel::Number).isNull())
|
if(!last->data(ComicModel::Number).isNull())
|
||||||
numberLast = last->data(TableModel::Number).toInt();
|
numberLast = last->data(ComicModel::Number).toInt();
|
||||||
|
|
||||||
if(!currentItem->data(TableModel::Number).isNull())
|
if(!currentItem->data(ComicModel::Number).isNull())
|
||||||
numberCurrent = currentItem->data(TableModel::Number).toInt();
|
numberCurrent = currentItem->data(ComicModel::Number).toInt();
|
||||||
|
|
||||||
QList<TableItem *>::iterator i;
|
QList<ComicItem *>::iterator i;
|
||||||
i = _data.end();
|
i = _data.end();
|
||||||
i--;
|
i--;
|
||||||
|
|
||||||
@ -423,8 +423,8 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
|
|||||||
i--;
|
i--;
|
||||||
numberLast = max;
|
numberLast = max;
|
||||||
|
|
||||||
if(!(*i)->data(TableModel::Number).isNull())
|
if(!(*i)->data(ComicModel::Number).isNull())
|
||||||
numberLast = (*i)->data(TableModel::Number).toInt();
|
numberLast = (*i)->data(ComicModel::Number).toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -432,11 +432,11 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
|
|||||||
while ((lessThan = naturalSortLessThanCI(nameCurrent,nameLast)) && i != _data.begin() && numberLast == max)
|
while ((lessThan = naturalSortLessThanCI(nameCurrent,nameLast)) && i != _data.begin() && numberLast == max)
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
nameLast = (*i)->data(TableModel::FileName).toString();
|
nameLast = (*i)->data(ComicModel::FileName).toString();
|
||||||
numberLast = max;
|
numberLast = max;
|
||||||
|
|
||||||
if(!(*i)->data(TableModel::Number).isNull())
|
if(!(*i)->data(ComicModel::Number).isNull())
|
||||||
numberLast = (*i)->data(TableModel::Number).toInt();
|
numberLast = (*i)->data(ComicModel::Number).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -445,7 +445,7 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
|
|||||||
if(numberCurrent != max)
|
if(numberCurrent != max)
|
||||||
{
|
{
|
||||||
if(numberCurrent == numberLast)
|
if(numberCurrent == numberLast)
|
||||||
if(currentItem->data(TableModel::IsBis).toBool())
|
if(currentItem->data(ComicModel::IsBis).toBool())
|
||||||
{
|
{
|
||||||
_data.insert(++i,currentItem);
|
_data.insert(++i,currentItem);
|
||||||
}
|
}
|
||||||
@ -466,20 +466,20 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ComicDB TableModel::getComic(const QModelIndex & mi)
|
ComicDB ComicModel::getComic(const QModelIndex & mi)
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
ComicDB c = DBHelper::loadComic(_data.at(mi.row())->data(TableModel::Id).toULongLong(),db);
|
ComicDB c = DBHelper::loadComic(_data.at(mi.row())->data(ComicModel::Id).toULongLong(),db);
|
||||||
db.close();
|
db.close();
|
||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComicDB TableModel::_getComic(const QModelIndex & mi)
|
ComicDB ComicModel::_getComic(const QModelIndex & mi)
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
ComicDB c = DBHelper::loadComic(_data.at(mi.row())->data(TableModel::Id).toULongLong(),db);
|
ComicDB c = DBHelper::loadComic(_data.at(mi.row())->data(ComicModel::Id).toULongLong(),db);
|
||||||
db.close();
|
db.close();
|
||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
|
||||||
@ -487,17 +487,17 @@ ComicDB TableModel::_getComic(const QModelIndex & mi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVector<YACReaderComicReadStatus> TableModel::getReadList()
|
QVector<YACReaderComicReadStatus> ComicModel::getReadList()
|
||||||
{
|
{
|
||||||
int numComics = _data.count();
|
int numComics = _data.count();
|
||||||
QVector<YACReaderComicReadStatus> readList(numComics);
|
QVector<YACReaderComicReadStatus> readList(numComics);
|
||||||
for(int i=0;i<numComics;i++)
|
for(int i=0;i<numComics;i++)
|
||||||
{
|
{
|
||||||
if(_data.value(i)->data(TableModel::ReadColumn).toBool())
|
if(_data.value(i)->data(ComicModel::ReadColumn).toBool())
|
||||||
readList[i] = YACReader::Read;
|
readList[i] = YACReader::Read;
|
||||||
else if (_data.value(i)->data(TableModel::CurrentPage).toInt() == _data.value(i)->data(TableModel::NumPages).toInt())
|
else if (_data.value(i)->data(ComicModel::CurrentPage).toInt() == _data.value(i)->data(ComicModel::NumPages).toInt())
|
||||||
readList[i] = YACReader::Read;
|
readList[i] = YACReader::Read;
|
||||||
else if (_data.value(i)->data(TableModel::HasBeenOpened).toBool())
|
else if (_data.value(i)->data(ComicModel::HasBeenOpened).toBool())
|
||||||
readList[i] = YACReader::Opened;
|
readList[i] = YACReader::Opened;
|
||||||
else
|
else
|
||||||
readList[i] = YACReader::Unread;
|
readList[i] = YACReader::Unread;
|
||||||
@ -505,12 +505,12 @@ QVector<YACReaderComicReadStatus> TableModel::getReadList()
|
|||||||
return readList;
|
return readList;
|
||||||
}
|
}
|
||||||
//TODO untested, this method is no longer used
|
//TODO untested, this method is no longer used
|
||||||
QVector<YACReaderComicReadStatus> TableModel::setAllComicsRead(YACReaderComicReadStatus read)
|
QVector<YACReaderComicReadStatus> ComicModel::setAllComicsRead(YACReaderComicReadStatus read)
|
||||||
{
|
{
|
||||||
return setComicsRead(persistentIndexList(),read);
|
return setComicsRead(persistentIndexList(),read);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ComicDB> TableModel::getAllComics()
|
QList<ComicDB> ComicModel::getAllComics()
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
db.transaction();
|
db.transaction();
|
||||||
@ -519,7 +519,7 @@ QList<ComicDB> TableModel::getAllComics()
|
|||||||
int numComics = _data.count();
|
int numComics = _data.count();
|
||||||
for(int i=0;i<numComics;i++)
|
for(int i=0;i<numComics;i++)
|
||||||
{
|
{
|
||||||
comics.append(DBHelper::loadComic(_data.value(i)->data(TableModel::Id).toULongLong(),db));
|
comics.append(DBHelper::loadComic(_data.value(i)->data(ComicModel::Id).toULongLong(),db));
|
||||||
}
|
}
|
||||||
|
|
||||||
db.commit();
|
db.commit();
|
||||||
@ -529,7 +529,7 @@ QList<ComicDB> TableModel::getAllComics()
|
|||||||
return comics;
|
return comics;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ComicDB> TableModel::getComics(QList<QModelIndex> list)
|
QList<ComicDB> ComicModel::getComics(QList<QModelIndex> list)
|
||||||
{
|
{
|
||||||
QList<ComicDB> comics;
|
QList<ComicDB> comics;
|
||||||
|
|
||||||
@ -546,7 +546,7 @@ QList<ComicDB> TableModel::getComics(QList<QModelIndex> list)
|
|||||||
return comics;
|
return comics;
|
||||||
}
|
}
|
||||||
//TODO
|
//TODO
|
||||||
QVector<YACReaderComicReadStatus> TableModel::setComicsRead(QList<QModelIndex> list,YACReaderComicReadStatus read)
|
QVector<YACReaderComicReadStatus> ComicModel::setComicsRead(QList<QModelIndex> list,YACReaderComicReadStatus read)
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
db.transaction();
|
db.transaction();
|
||||||
@ -554,17 +554,17 @@ QVector<YACReaderComicReadStatus> TableModel::setComicsRead(QList<QModelIndex> l
|
|||||||
{
|
{
|
||||||
if(read == YACReader::Read)
|
if(read == YACReader::Read)
|
||||||
{
|
{
|
||||||
_data.value(mi.row())->setData(TableModel::ReadColumn, QVariant(true));
|
_data.value(mi.row())->setData(ComicModel::ReadColumn, QVariant(true));
|
||||||
ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(TableModel::Id).toULongLong(),db);
|
ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(ComicModel::Id).toULongLong(),db);
|
||||||
c.info.read = true;
|
c.info.read = true;
|
||||||
DBHelper::update(&(c.info),db);
|
DBHelper::update(&(c.info),db);
|
||||||
}
|
}
|
||||||
if(read == YACReader::Unread)
|
if(read == YACReader::Unread)
|
||||||
{
|
{
|
||||||
_data.value(mi.row())->setData(TableModel::ReadColumn, QVariant(false));
|
_data.value(mi.row())->setData(ComicModel::ReadColumn, QVariant(false));
|
||||||
_data.value(mi.row())->setData(TableModel::CurrentPage, QVariant(1));
|
_data.value(mi.row())->setData(ComicModel::CurrentPage, QVariant(1));
|
||||||
_data.value(mi.row())->setData(TableModel::HasBeenOpened, QVariant(false));
|
_data.value(mi.row())->setData(ComicModel::HasBeenOpened, QVariant(false));
|
||||||
ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(TableModel::Id).toULongLong(),db);
|
ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(ComicModel::Id).toULongLong(),db);
|
||||||
c.info.read = false;
|
c.info.read = false;
|
||||||
c.info.currentPage = 1;
|
c.info.currentPage = 1;
|
||||||
c.info.hasBeenOpened = false;
|
c.info.hasBeenOpened = false;
|
||||||
@ -575,19 +575,19 @@ QVector<YACReaderComicReadStatus> TableModel::setComicsRead(QList<QModelIndex> l
|
|||||||
db.close();
|
db.close();
|
||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
|
||||||
emit dataChanged(index(list.first().row(),TableModel::ReadColumn),index(list.last().row(),TableModel::HasBeenOpened),QVector<int>() << ReadColumnRole << CurrentPageRole << HasBeenOpenedRole);
|
emit dataChanged(index(list.first().row(),ComicModel::ReadColumn),index(list.last().row(),ComicModel::HasBeenOpened),QVector<int>() << ReadColumnRole << CurrentPageRole << HasBeenOpenedRole);
|
||||||
|
|
||||||
return getReadList();
|
return getReadList();
|
||||||
}
|
}
|
||||||
qint64 TableModel::asignNumbers(QList<QModelIndex> list,int startingNumber)
|
qint64 ComicModel::asignNumbers(QList<QModelIndex> list,int startingNumber)
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
db.transaction();
|
db.transaction();
|
||||||
qint64 idFirst = _data.value(list[0].row())->data(TableModel::Id).toULongLong();
|
qint64 idFirst = _data.value(list[0].row())->data(ComicModel::Id).toULongLong();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (QModelIndex mi, list)
|
foreach (QModelIndex mi, list)
|
||||||
{
|
{
|
||||||
ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(TableModel::Id).toULongLong(),db);
|
ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(ComicModel::Id).toULongLong(),db);
|
||||||
c.info.number = startingNumber+i;
|
c.info.number = startingNumber+i;
|
||||||
c.info.edited = true;
|
c.info.edited = true;
|
||||||
DBHelper::update(&(c.info),db);
|
DBHelper::update(&(c.info),db);
|
||||||
@ -602,13 +602,13 @@ qint64 TableModel::asignNumbers(QList<QModelIndex> list,int startingNumber)
|
|||||||
|
|
||||||
return idFirst;
|
return idFirst;
|
||||||
}
|
}
|
||||||
QModelIndex TableModel::getIndexFromId(quint64 id)
|
QModelIndex ComicModel::getIndexFromId(quint64 id)
|
||||||
{
|
{
|
||||||
QList<TableItem *>::ConstIterator itr;
|
QList<ComicItem *>::ConstIterator itr;
|
||||||
int i=0;
|
int i=0;
|
||||||
for(itr = _data.constBegin();itr != _data.constEnd();itr++)
|
for(itr = _data.constBegin();itr != _data.constEnd();itr++)
|
||||||
{
|
{
|
||||||
if((*itr)->data(TableModel::Id).toULongLong() == id)
|
if((*itr)->data(ComicModel::Id).toULongLong() == id)
|
||||||
break;
|
break;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -616,14 +616,14 @@ QModelIndex TableModel::getIndexFromId(quint64 id)
|
|||||||
return index(i,0);
|
return index(i,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::startTransaction()
|
void ComicModel::startTransaction()
|
||||||
{
|
{
|
||||||
|
|
||||||
dbTransaction = DataBaseManagement::loadDatabase(_databasePath);
|
dbTransaction = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
dbTransaction.transaction();
|
dbTransaction.transaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::finishTransaction()
|
void ComicModel::finishTransaction()
|
||||||
{
|
{
|
||||||
dbTransaction.commit();
|
dbTransaction.commit();
|
||||||
dbTransaction.close();
|
dbTransaction.close();
|
||||||
@ -632,9 +632,9 @@ void TableModel::finishTransaction()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::removeInTransaction(int row)
|
void ComicModel::removeInTransaction(int row)
|
||||||
{
|
{
|
||||||
ComicDB c = DBHelper::loadComic(_data.at(row)->data(TableModel::Id).toULongLong(),dbTransaction);
|
ComicDB c = DBHelper::loadComic(_data.at(row)->data(ComicModel::Id).toULongLong(),dbTransaction);
|
||||||
|
|
||||||
DBHelper::removeFromDB(&c,dbTransaction);
|
DBHelper::removeFromDB(&c,dbTransaction);
|
||||||
beginRemoveRows(QModelIndex(),row,row);
|
beginRemoveRows(QModelIndex(),row,row);
|
||||||
@ -645,7 +645,7 @@ void TableModel::removeInTransaction(int row)
|
|||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::remove(ComicDB * comic, int row)
|
void ComicModel::remove(ComicDB * comic, int row)
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(),row,row);
|
beginRemoveRows(QModelIndex(),row,row);
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
@ -666,23 +666,23 @@ void TableModel::remove(ComicDB * comic, int row)
|
|||||||
return getComic(index(row,0));
|
return getComic(index(row,0));
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void TableModel::remove(int row)
|
void ComicModel::remove(int row)
|
||||||
{
|
{
|
||||||
removeInTransaction(row);
|
removeInTransaction(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::reload(const ComicDB & comic)
|
void ComicModel::reload(const ComicDB & comic)
|
||||||
{
|
{
|
||||||
int row = 0;
|
int row = 0;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach(TableItem * item,_data)
|
foreach(ComicItem * item,_data)
|
||||||
{
|
{
|
||||||
if(item->data(TableModel::Id).toULongLong() == comic.id)
|
if(item->data(ComicModel::Id).toULongLong() == comic.id)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
item->setData(TableModel::ReadColumn,comic.info.read);
|
item->setData(ComicModel::ReadColumn,comic.info.read);
|
||||||
item->setData(TableModel::CurrentPage,comic.info.currentPage);
|
item->setData(ComicModel::CurrentPage,comic.info.currentPage);
|
||||||
item->setData(TableModel::HasBeenOpened,true);
|
item->setData(ComicModel::HasBeenOpened,true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -692,14 +692,14 @@ void TableModel::reload(const ComicDB & comic)
|
|||||||
emit dataChanged(index(row,ReadColumn),index(row,HasBeenOpened), QVector<int>() << ReadColumnRole << CurrentPageRole << HasBeenOpenedRole);
|
emit dataChanged(index(row,ReadColumn),index(row,HasBeenOpened), QVector<int>() << ReadColumnRole << CurrentPageRole << HasBeenOpenedRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::resetComicRating(const QModelIndex &mi)
|
void ComicModel::resetComicRating(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
ComicDB comic = getComic(mi);
|
ComicDB comic = getComic(mi);
|
||||||
|
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
|
|
||||||
comic.info.rating = 0;
|
comic.info.rating = 0;
|
||||||
_data[mi.row()]->setData(TableModel::Rating,0);
|
_data[mi.row()]->setData(ComicModel::Rating,0);
|
||||||
DBHelper::update(&(comic.info),db);
|
DBHelper::update(&(comic.info),db);
|
||||||
|
|
||||||
emit dataChanged(mi,mi);
|
emit dataChanged(mi,mi);
|
||||||
@ -709,7 +709,7 @@ void TableModel::resetComicRating(const QModelIndex &mi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TableModel::updateRating(int rating, QModelIndex mi)
|
void ComicModel::updateRating(int rating, QModelIndex mi)
|
||||||
{
|
{
|
||||||
ComicDB comic = getComic(mi);
|
ComicDB comic = getComic(mi);
|
||||||
|
|
||||||
@ -717,7 +717,7 @@ void TableModel::updateRating(int rating, QModelIndex mi)
|
|||||||
//TODO optimize update
|
//TODO optimize update
|
||||||
|
|
||||||
comic.info.rating = rating;
|
comic.info.rating = rating;
|
||||||
_data[mi.row()]->setData(TableModel::Rating,rating);
|
_data[mi.row()]->setData(ComicModel::Rating,rating);
|
||||||
DBHelper::update(&(comic.info),db);
|
DBHelper::update(&(comic.info),db);
|
||||||
|
|
||||||
emit dataChanged(mi,mi);
|
emit dataChanged(mi,mi);
|
||||||
@ -11,19 +11,19 @@
|
|||||||
|
|
||||||
class ComicDB;
|
class ComicDB;
|
||||||
|
|
||||||
class TableItem;
|
class ComicItem;
|
||||||
|
|
||||||
using namespace YACReader;
|
using namespace YACReader;
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class TableModel : public QAbstractItemModel
|
class ComicModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TableModel(QObject *parent = 0);
|
ComicModel(QObject *parent = 0);
|
||||||
TableModel( QSqlQuery &sqlquery, QObject *parent = 0);
|
ComicModel( QSqlQuery &sqlquery, QObject *parent = 0);
|
||||||
~TableModel();
|
~ComicModel();
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
@ -106,7 +106,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void setupModelData( QSqlQuery &sqlquery);
|
void setupModelData( QSqlQuery &sqlquery);
|
||||||
ComicDB _getComic(const QModelIndex & mi);
|
ComicDB _getComic(const QModelIndex & mi);
|
||||||
QList<TableItem *> _data;
|
QList<ComicItem *> _data;
|
||||||
|
|
||||||
QString _databasePath;
|
QString _databasePath;
|
||||||
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
#include <QtSql>
|
#include <QtSql>
|
||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
|
|
||||||
#include "treemodel.h"
|
#include "folder_model.h"
|
||||||
|
|
||||||
class ComicsInfoExporter : public QThread
|
class ComicsInfoExporter : public QThread
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,20 +1,20 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include "treeitem.h"
|
#include "folder_item.h"
|
||||||
#include "qnaturalsorting.h"
|
#include "qnaturalsorting.h"
|
||||||
|
|
||||||
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
|
FolderItem::FolderItem(const QList<QVariant> &data, FolderItem *parent)
|
||||||
{
|
{
|
||||||
parentItem = parent;
|
parentItem = parent;
|
||||||
itemData = data;
|
itemData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem::~TreeItem()
|
FolderItem::~FolderItem()
|
||||||
{
|
{
|
||||||
qDeleteAll(childItems);
|
qDeleteAll(childItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeItem::appendChild(TreeItem *item)
|
void FolderItem::appendChild(FolderItem *item)
|
||||||
{
|
{
|
||||||
item->parentItem = this;
|
item->parentItem = this;
|
||||||
|
|
||||||
@ -22,10 +22,10 @@ void TreeItem::appendChild(TreeItem *item)
|
|||||||
childItems.append(item);
|
childItems.append(item);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TreeItem * last = childItems.back();
|
FolderItem * last = childItems.back();
|
||||||
QString nameLast = last->data(1).toString(); //TODO usar info name si est<73> disponible, sino el nombre del fichero.....
|
QString nameLast = last->data(1).toString(); //TODO usar info name si est<73> disponible, sino el nombre del fichero.....
|
||||||
QString nameCurrent = item->data(1).toString();
|
QString nameCurrent = item->data(1).toString();
|
||||||
QList<TreeItem *>::iterator i;
|
QList<FolderItem *>::iterator i;
|
||||||
i = childItems.end();
|
i = childItems.end();
|
||||||
i--;
|
i--;
|
||||||
while (naturalSortLessThanCI(nameCurrent,nameLast) && i != childItems.begin())
|
while (naturalSortLessThanCI(nameCurrent,nameLast) && i != childItems.begin())
|
||||||
@ -43,61 +43,61 @@ void TreeItem::appendChild(TreeItem *item)
|
|||||||
//childItems.append(item);
|
//childItems.append(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem *TreeItem::child(int row)
|
FolderItem *FolderItem::child(int row)
|
||||||
{
|
{
|
||||||
return childItems.value(row);
|
return childItems.value(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TreeItem::childCount() const
|
int FolderItem::childCount() const
|
||||||
{
|
{
|
||||||
return childItems.count();
|
return childItems.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TreeItem::columnCount() const
|
int FolderItem::columnCount() const
|
||||||
{
|
{
|
||||||
return itemData.count();
|
return itemData.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TreeItem::data(int column) const
|
QVariant FolderItem::data(int column) const
|
||||||
{
|
{
|
||||||
return itemData.value(column);
|
return itemData.value(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeItem::setData(int column, const QVariant & value)
|
void FolderItem::setData(int column, const QVariant & value)
|
||||||
{
|
{
|
||||||
itemData[column] = value;
|
itemData[column] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeItem::removeChild(int childIndex)
|
void FolderItem::removeChild(int childIndex)
|
||||||
{
|
{
|
||||||
childItems.removeAt(childIndex);
|
childItems.removeAt(childIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeItem::clearChildren()
|
void FolderItem::clearChildren()
|
||||||
{
|
{
|
||||||
qDeleteAll(childItems);
|
qDeleteAll(childItems);
|
||||||
childItems.clear();
|
childItems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TreeItem *> TreeItem::children()
|
QList<FolderItem *> FolderItem::children()
|
||||||
{
|
{
|
||||||
return childItems;
|
return childItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem *TreeItem::parent()
|
FolderItem *FolderItem::parent()
|
||||||
{
|
{
|
||||||
return parentItem;
|
return parentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TreeItem::row() const
|
int FolderItem::row() const
|
||||||
{
|
{
|
||||||
if (parentItem)
|
if (parentItem)
|
||||||
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
|
return parentItem->childItems.indexOf(const_cast<FolderItem*>(this));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QVariant> TreeItem::getData() const
|
QList<QVariant> FolderItem::getData() const
|
||||||
{
|
{
|
||||||
return itemData;
|
return itemData;
|
||||||
}
|
}
|
||||||
@ -45,31 +45,31 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
||||||
class TreeItem
|
class FolderItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
|
FolderItem(const QList<QVariant> &data, FolderItem *parent = 0);
|
||||||
~TreeItem();
|
~FolderItem();
|
||||||
|
|
||||||
void appendChild(TreeItem *child);
|
void appendChild(FolderItem *child);
|
||||||
|
|
||||||
TreeItem *child(int row);
|
FolderItem *child(int row);
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
int columnCount() const;
|
int columnCount() const;
|
||||||
QVariant data(int column) const;
|
QVariant data(int column) const;
|
||||||
QList<QVariant> getData() const;
|
QList<QVariant> getData() const;
|
||||||
int row() const;
|
int row() const;
|
||||||
TreeItem *parent();
|
FolderItem *parent();
|
||||||
TreeItem *parentItem;
|
FolderItem *parentItem;
|
||||||
unsigned long long int id;
|
unsigned long long int id;
|
||||||
QList<QString> comicNames;
|
QList<QString> comicNames;
|
||||||
TreeItem * originalItem;
|
FolderItem * originalItem;
|
||||||
void setData(int column, const QVariant &value);
|
void setData(int column, const QVariant &value);
|
||||||
void removeChild(int childIndex);
|
void removeChild(int childIndex);
|
||||||
void clearChildren();
|
void clearChildren();
|
||||||
QList<TreeItem*> children();
|
QList<FolderItem*> children();
|
||||||
private:
|
private:
|
||||||
QList<TreeItem*> childItems;
|
QList<FolderItem*> childItems;
|
||||||
QList<QVariant> itemData;
|
QList<QVariant> itemData;
|
||||||
|
|
||||||
|
|
||||||
@ -48,8 +48,8 @@
|
|||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
|
|
||||||
#include "treeitem.h"
|
#include "folder_item.h"
|
||||||
#include "treemodel.h"
|
#include "folder_model.h"
|
||||||
#include "data_base_management.h"
|
#include "data_base_management.h"
|
||||||
#include "folder.h"
|
#include "folder.h"
|
||||||
#include "db_helper.h"
|
#include "db_helper.h"
|
||||||
@ -98,7 +98,7 @@ void drawMacOSXFinishedFolderIcon()
|
|||||||
|
|
||||||
#define ROOT 1
|
#define ROOT 1
|
||||||
|
|
||||||
TreeModel::TreeModel(QObject *parent)
|
FolderModel::FolderModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent),rootItem(0),rootBeforeFilter(0),filterEnabled(false),includeComics(false)
|
: QAbstractItemModel(parent),rootItem(0),rootBeforeFilter(0),filterEnabled(false),includeComics(false)
|
||||||
{
|
{
|
||||||
connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset()));
|
connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset()));
|
||||||
@ -106,13 +106,13 @@ TreeModel::TreeModel(QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
TreeModel::TreeModel( QSqlQuery &sqlquery, QObject *parent)
|
FolderModel::FolderModel( QSqlQuery &sqlquery, QObject *parent)
|
||||||
: QAbstractItemModel(parent),rootItem(0),rootBeforeFilter(0),filterEnabled(false),includeComics(false)
|
: QAbstractItemModel(parent),rootItem(0),rootBeforeFilter(0),filterEnabled(false),includeComics(false)
|
||||||
{
|
{
|
||||||
//lo m<>s probable es que el nodo ra<72>z no necesite tener informaci<63>n
|
//lo m<>s probable es que el nodo ra<72>z no necesite tener informaci<63>n
|
||||||
QList<QVariant> rootData;
|
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)
|
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||||
rootItem = new TreeItem(rootData);
|
rootItem = new FolderItem(rootData);
|
||||||
rootItem->id = ROOT;
|
rootItem->id = ROOT;
|
||||||
rootItem->parentItem = 0;
|
rootItem->parentItem = 0;
|
||||||
setupModelData(sqlquery, rootItem);
|
setupModelData(sqlquery, rootItem);
|
||||||
@ -121,7 +121,7 @@ TreeModel::TreeModel( QSqlQuery &sqlquery, QObject *parent)
|
|||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
TreeModel::~TreeModel()
|
FolderModel::~FolderModel()
|
||||||
{
|
{
|
||||||
if(rootItem != 0)
|
if(rootItem != 0)
|
||||||
delete rootItem;
|
delete rootItem;
|
||||||
@ -129,22 +129,22 @@ TreeModel::~TreeModel()
|
|||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
int TreeModel::columnCount(const QModelIndex &parent) const
|
int FolderModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
|
return static_cast<FolderItem*>(parent.internalPointer())->columnCount();
|
||||||
else
|
else
|
||||||
return rootItem->columnCount();
|
return rootItem->columnCount();
|
||||||
}
|
}
|
||||||
//! [2]
|
//! [2]
|
||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
QVariant TreeModel::data(const QModelIndex &index, int role) const
|
QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
FolderItem *item = static_cast<FolderItem*>(index.internalPointer());
|
||||||
|
|
||||||
if (role == Qt::DecorationRole)
|
if (role == Qt::DecorationRole)
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant(QFileIconProvider().icon(QFileIconProvider::Folder));
|
return QVariant(QFileIconProvider().icon(QFileIconProvider::Folder));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if(item->data(TreeModel::Finished).toBool())
|
if(item->data(FolderModel::Finished).toBool())
|
||||||
return QVariant(QIcon(":/images/folder_finished.png"));
|
return QVariant(QIcon(":/images/folder_finished.png"));
|
||||||
else
|
else
|
||||||
return QVariant(QIcon(":/images/folder.png"));
|
return QVariant(QIcon(":/images/folder.png"));
|
||||||
@ -176,7 +176,7 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
|
|||||||
//! [3]
|
//! [3]
|
||||||
|
|
||||||
//! [4]
|
//! [4]
|
||||||
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags FolderModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
@ -186,7 +186,7 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
|
|||||||
//! [4]
|
//! [4]
|
||||||
|
|
||||||
//! [5]
|
//! [5]
|
||||||
QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
|
QVariant FolderModel::headerData(int section, Qt::Orientation orientation,
|
||||||
int role) const
|
int role) const
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
@ -197,20 +197,20 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
//! [5]
|
//! [5]
|
||||||
|
|
||||||
//! [6]
|
//! [6]
|
||||||
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
|
QModelIndex FolderModel::index(int row, int column, const QModelIndex &parent)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
if (!hasIndex(row, column, parent))
|
if (!hasIndex(row, column, parent))
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
TreeItem *parentItem;
|
FolderItem *parentItem;
|
||||||
|
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
parentItem = rootItem;
|
parentItem = rootItem;
|
||||||
else
|
else
|
||||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
parentItem = static_cast<FolderItem*>(parent.internalPointer());
|
||||||
|
|
||||||
TreeItem *childItem = parentItem->child(row);
|
FolderItem *childItem = parentItem->child(row);
|
||||||
if (childItem)
|
if (childItem)
|
||||||
return createIndex(row, column, childItem);
|
return createIndex(row, column, childItem);
|
||||||
else
|
else
|
||||||
@ -219,13 +219,13 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
|
|||||||
//! [6]
|
//! [6]
|
||||||
|
|
||||||
//! [7]
|
//! [7]
|
||||||
QModelIndex TreeModel::parent(const QModelIndex &index) const
|
QModelIndex FolderModel::parent(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
|
FolderItem *childItem = static_cast<FolderItem*>(index.internalPointer());
|
||||||
TreeItem *parentItem = childItem->parent();
|
FolderItem *parentItem = childItem->parent();
|
||||||
|
|
||||||
if (parentItem == rootItem)
|
if (parentItem == rootItem)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
@ -234,7 +234,7 @@ QModelIndex TreeModel::parent(const QModelIndex &index) const
|
|||||||
}
|
}
|
||||||
//! [7]
|
//! [7]
|
||||||
|
|
||||||
QModelIndex TreeModel::indexFromItem(TreeItem * item,int column)
|
QModelIndex FolderModel::indexFromItem(FolderItem * item,int column)
|
||||||
{
|
{
|
||||||
//if(item->parent() != 0)
|
//if(item->parent() != 0)
|
||||||
// return index(item->row(),column,parent(indexFromItem(item->parent(),column-1)));
|
// return index(item->row(),column,parent(indexFromItem(item->parent(),column-1)));
|
||||||
@ -245,22 +245,22 @@ QModelIndex TreeModel::indexFromItem(TreeItem * item,int column)
|
|||||||
|
|
||||||
|
|
||||||
//! [8]
|
//! [8]
|
||||||
int TreeModel::rowCount(const QModelIndex &parent) const
|
int FolderModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
TreeItem *parentItem;
|
FolderItem *parentItem;
|
||||||
if (parent.column() > 0)
|
if (parent.column() > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
parentItem = rootItem;
|
parentItem = rootItem;
|
||||||
else
|
else
|
||||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
parentItem = static_cast<FolderItem*>(parent.internalPointer());
|
||||||
|
|
||||||
return parentItem->childCount();
|
return parentItem->childCount();
|
||||||
}
|
}
|
||||||
//! [8]
|
//! [8]
|
||||||
|
|
||||||
void TreeModel::setupModelData(QString path)
|
void FolderModel::setupModelData(QString path)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
if(rootItem != 0)
|
if(rootItem != 0)
|
||||||
@ -271,7 +271,7 @@ void TreeModel::setupModelData(QString path)
|
|||||||
//inicializar el nodo ra<72>z
|
//inicializar el nodo ra<72>z
|
||||||
QList<QVariant> rootData;
|
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)
|
rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||||
rootItem = new TreeItem(rootData);
|
rootItem = new FolderItem(rootData);
|
||||||
rootItem->id = ROOT;
|
rootItem->id = ROOT;
|
||||||
rootItem->parentItem = 0;
|
rootItem->parentItem = 0;
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ void TreeModel::setupModelData(QString path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TreeModel::setupModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
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
|
//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)
|
//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)
|
||||||
@ -308,11 +308,11 @@ void TreeModel::setupModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
|||||||
data << record.value("path").toString();
|
data << record.value("path").toString();
|
||||||
data << record.value("finished").toBool();
|
data << record.value("finished").toBool();
|
||||||
data << record.value("completed").toBool();
|
data << record.value("completed").toBool();
|
||||||
TreeItem * item = new TreeItem(data);
|
FolderItem * item = new FolderItem(data);
|
||||||
|
|
||||||
item->id = record.value("id").toULongLong();
|
item->id = record.value("id").toULongLong();
|
||||||
//la inserci<63>n de hijos se hace de forma ordenada
|
//la inserci<63>n de hijos se hace de forma ordenada
|
||||||
TreeItem * parent = items.value(record.value("parentId").toULongLong());
|
FolderItem * parent = items.value(record.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.
|
//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);
|
parent->appendChild(item);
|
||||||
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
||||||
@ -320,7 +320,7 @@ void TreeModel::setupModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::updateFolderModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
void FolderModel::updateFolderModelData(QSqlQuery &sqlquery, FolderItem *parent)
|
||||||
{
|
{
|
||||||
while (sqlquery.next()) {
|
while (sqlquery.next()) {
|
||||||
QList<QVariant> data;
|
QList<QVariant> data;
|
||||||
@ -330,11 +330,11 @@ void TreeModel::updateFolderModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
|||||||
data << record.value("path").toString();
|
data << record.value("path").toString();
|
||||||
data << record.value("finished").toBool();
|
data << record.value("finished").toBool();
|
||||||
data << record.value("completed").toBool();
|
data << record.value("completed").toBool();
|
||||||
TreeItem * item = new TreeItem(data);
|
FolderItem * item = new FolderItem(data);
|
||||||
|
|
||||||
item->id = record.value("id").toULongLong();
|
item->id = record.value("id").toULongLong();
|
||||||
//la inserci<63>n de hijos se hace de forma ordenada
|
//la inserci<63>n de hijos se hace de forma ordenada
|
||||||
TreeItem * parent = items.value(record.value("parentId").toULongLong());
|
FolderItem * parent = items.value(record.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.
|
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);
|
parent->appendChild(item);
|
||||||
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
//se a<>ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
|
||||||
@ -342,7 +342,7 @@ void TreeModel::updateFolderModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::setupFilteredModelData()
|
void FolderModel::setupFilteredModelData()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
@ -357,7 +357,7 @@ void TreeModel::setupFilteredModelData()
|
|||||||
|
|
||||||
QList<QVariant> rootData;
|
QList<QVariant> rootData;
|
||||||
rootData << "root"; //id 1, padre 1, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
rootData << "root"; //id 1, padre 1, title "root" (el id, y el id del padre van a ir en la clase TreeItem)
|
||||||
rootItem = new TreeItem(rootData);
|
rootItem = new FolderItem(rootData);
|
||||||
rootItem->id = ROOT;
|
rootItem->id = ROOT;
|
||||||
rootItem->parentItem = 0;
|
rootItem->parentItem = 0;
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ void TreeModel::setupFilteredModelData()
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
void FolderModel::setupFilteredModelData(QSqlQuery &sqlquery, FolderItem *parent)
|
||||||
{
|
{
|
||||||
//64 bits para la primary key, es decir la misma precisi<73>n que soporta sqlit 2^64
|
//64 bits para la primary key, es decir la misma precisi<73>n que soporta sqlit 2^64
|
||||||
filteredItems.clear();
|
filteredItems.clear();
|
||||||
@ -436,7 +436,7 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
|||||||
data << record.value("finished").toBool();
|
data << record.value("finished").toBool();
|
||||||
data << record.value("completed").toBool();
|
data << record.value("completed").toBool();
|
||||||
|
|
||||||
TreeItem * item = new TreeItem(data);
|
FolderItem * item = new FolderItem(data);
|
||||||
item->id = sqlquery.value(0).toULongLong();
|
item->id = sqlquery.value(0).toULongLong();
|
||||||
|
|
||||||
//id del padre
|
//id del padre
|
||||||
@ -461,9 +461,9 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
|||||||
while(parentId != ROOT )
|
while(parentId != ROOT )
|
||||||
{
|
{
|
||||||
//el padre no estaba en el modelo filtrado, as<61> que se rescata del modelo original
|
//el padre no estaba en el modelo filtrado, as<61> que se rescata del modelo original
|
||||||
TreeItem * parentItem = items.value(parentId);
|
FolderItem * parentItem = items.value(parentId);
|
||||||
//se debe crear un nuevo nodo (para no compartir los hijos con el nodo original)
|
//se debe crear un nuevo nodo (para no compartir los hijos con el nodo original)
|
||||||
TreeItem * newparentItem = new TreeItem(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->id = parentId;
|
||||||
|
|
||||||
newparentItem->originalItem = parentItem;
|
newparentItem->originalItem = parentItem;
|
||||||
@ -496,19 +496,19 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString TreeModel::getDatabase()
|
QString FolderModel::getDatabase()
|
||||||
{
|
{
|
||||||
return _databasePath;
|
return _databasePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TreeModel::getFolderPath(const QModelIndex &folder)
|
QString FolderModel::getFolderPath(const QModelIndex &folder)
|
||||||
{
|
{
|
||||||
if(!folder.isValid()) //root folder
|
if(!folder.isValid()) //root folder
|
||||||
return "/";
|
return "/";
|
||||||
return static_cast<TreeItem*>(folder.internalPointer())->data(TreeModel::Path).toString();
|
return static_cast<FolderItem*>(folder.internalPointer())->data(FolderModel::Path).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics)
|
void FolderModel::setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics)
|
||||||
{
|
{
|
||||||
this->filter = filter;
|
this->filter = filter;
|
||||||
this->includeComics = includeComics;
|
this->includeComics = includeComics;
|
||||||
@ -517,7 +517,7 @@ void TreeModel::setFilter(const YACReader::SearchModifiers modifier, QString fil
|
|||||||
setupFilteredModelData();
|
setupFilteredModelData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::resetFilter()
|
void FolderModel::resetFilter()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
filter = "";
|
filter = "";
|
||||||
@ -525,7 +525,7 @@ void TreeModel::resetFilter()
|
|||||||
//TODO hay que liberar la memoria reservada para el filtrado
|
//TODO hay que liberar la memoria reservada para el filtrado
|
||||||
//items.clear();
|
//items.clear();
|
||||||
filteredItems.clear();
|
filteredItems.clear();
|
||||||
TreeItem * root = rootItem;
|
FolderItem * root = rootItem;
|
||||||
rootItem = rootBeforeFilter; //TODO si no se aplica el filtro previamente, esto invalidar<61>a en modelo
|
rootItem = rootBeforeFilter; //TODO si no se aplica el filtro previamente, esto invalidar<61>a en modelo
|
||||||
if(root !=0)
|
if(root !=0)
|
||||||
delete root;
|
delete root;
|
||||||
@ -537,14 +537,14 @@ void TreeModel::resetFilter()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::updateFolderCompletedStatus(const QModelIndexList &list, bool status)
|
void FolderModel::updateFolderCompletedStatus(const QModelIndexList &list, bool status)
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
db.transaction();
|
db.transaction();
|
||||||
foreach (QModelIndex mi, list)
|
foreach (QModelIndex mi, list)
|
||||||
{
|
{
|
||||||
TreeItem * item = static_cast<TreeItem*>(mi.internalPointer());
|
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||||
item->setData(TreeModel::Completed,status);
|
item->setData(FolderModel::Completed,status);
|
||||||
|
|
||||||
Folder f = DBHelper::loadFolder(item->id,db);
|
Folder f = DBHelper::loadFolder(item->id,db);
|
||||||
f.setCompleted(status);
|
f.setCompleted(status);
|
||||||
@ -554,17 +554,17 @@ void TreeModel::updateFolderCompletedStatus(const QModelIndexList &list, bool st
|
|||||||
db.close();
|
db.close();
|
||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
|
||||||
emit dataChanged(index(list.first().row(),TreeModel::Name),index(list.last().row(),TreeModel::Completed));
|
emit dataChanged(index(list.first().row(),FolderModel::Name),index(list.last().row(),FolderModel::Completed));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::updateFolderFinishedStatus(const QModelIndexList &list, bool status)
|
void FolderModel::updateFolderFinishedStatus(const QModelIndexList &list, bool status)
|
||||||
{
|
{
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
db.transaction();
|
db.transaction();
|
||||||
foreach (QModelIndex mi, list)
|
foreach (QModelIndex mi, list)
|
||||||
{
|
{
|
||||||
TreeItem * item = static_cast<TreeItem*>(mi.internalPointer());
|
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||||
item->setData(TreeModel::Finished,status);
|
item->setData(FolderModel::Finished,status);
|
||||||
|
|
||||||
Folder f = DBHelper::loadFolder(item->id,db);
|
Folder f = DBHelper::loadFolder(item->id,db);
|
||||||
f.setFinished(status);
|
f.setFinished(status);
|
||||||
@ -574,15 +574,15 @@ void TreeModel::updateFolderFinishedStatus(const QModelIndexList &list, bool sta
|
|||||||
db.close();
|
db.close();
|
||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
|
||||||
emit dataChanged(index(list.first().row(),TreeModel::Name),index(list.last().row(),TreeModel::Completed));
|
emit dataChanged(index(list.first().row(),FolderModel::Name),index(list.last().row(),FolderModel::Completed));
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList TreeModel::getSubfoldersNames(const QModelIndex &mi)
|
QStringList FolderModel::getSubfoldersNames(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
qulonglong id = 1;
|
qulonglong id = 1;
|
||||||
if(mi.isValid()){
|
if(mi.isValid()){
|
||||||
TreeItem * item = static_cast<TreeItem*>(mi.internalPointer());
|
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||||
id = item->id;
|
id = item->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,11 +600,11 @@ QStringList TreeModel::getSubfoldersNames(const QModelIndex &mi)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::fetchMoreFromDB(const QModelIndex &parent)
|
void FolderModel::fetchMoreFromDB(const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
TreeItem * item;
|
FolderItem * item;
|
||||||
if(parent.isValid())
|
if(parent.isValid())
|
||||||
item = static_cast<TreeItem*>(parent.internalPointer());
|
item = static_cast<FolderItem*>(parent.internalPointer());
|
||||||
else
|
else
|
||||||
item = rootItem;
|
item = rootItem;
|
||||||
|
|
||||||
@ -615,8 +615,8 @@ void TreeModel::fetchMoreFromDB(const QModelIndex &parent)
|
|||||||
|
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
|
|
||||||
QList<TreeItem *> items;
|
QList<FolderItem *> items;
|
||||||
QList<TreeItem *> nextLevelItems;
|
QList<FolderItem *> nextLevelItems;
|
||||||
|
|
||||||
QSqlQuery selectQuery(db);
|
QSqlQuery selectQuery(db);
|
||||||
selectQuery.prepare("select * from folder where id <> 1 and parentId = :parentId order by parentId,name");
|
selectQuery.prepare("select * from folder where id <> 1 and parentId = :parentId order by parentId,name");
|
||||||
@ -626,7 +626,7 @@ void TreeModel::fetchMoreFromDB(const QModelIndex &parent)
|
|||||||
while(items.size() > 0)
|
while(items.size() > 0)
|
||||||
{
|
{
|
||||||
nextLevelItems.clear();
|
nextLevelItems.clear();
|
||||||
foreach(TreeItem * item, items)
|
foreach(FolderItem * item, items)
|
||||||
{
|
{
|
||||||
selectQuery.bindValue(":parentId", item->id);
|
selectQuery.bindValue(":parentId", item->id);
|
||||||
|
|
||||||
@ -655,12 +655,12 @@ void TreeModel::fetchMoreFromDB(const QModelIndex &parent)
|
|||||||
QSqlDatabase::removeDatabase(_databasePath);
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex TreeModel::addFolderAtParent(const QString &folderName, const QModelIndex &parent)
|
QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
TreeItem * parentItem;
|
FolderItem * parentItem;
|
||||||
|
|
||||||
if(parent.isValid())
|
if(parent.isValid())
|
||||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
parentItem = static_cast<FolderItem*>(parent.internalPointer());
|
||||||
else
|
else
|
||||||
parentItem = rootItem;
|
parentItem = rootItem;
|
||||||
|
|
||||||
@ -681,7 +681,7 @@ QModelIndex TreeModel::addFolderAtParent(const QString &folderName, const QModel
|
|||||||
data << false; //finished
|
data << false; //finished
|
||||||
data << true; //completed
|
data << true; //completed
|
||||||
|
|
||||||
TreeItem * item = new TreeItem(data);
|
FolderItem * item = new FolderItem(data);
|
||||||
item->id = newFolder.id;
|
item->id = newFolder.id;
|
||||||
|
|
||||||
parentItem->appendChild(item);
|
parentItem->appendChild(item);
|
||||||
@ -695,13 +695,13 @@ QModelIndex TreeModel::addFolderAtParent(const QString &folderName, const QModel
|
|||||||
return index(destRow,0,parent);
|
return index(destRow,0,parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeModel::deleteFolder(const QModelIndex &mi)
|
void FolderModel::deleteFolder(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
beginRemoveRows(mi.parent(),mi.row(),mi.row());
|
beginRemoveRows(mi.parent(),mi.row(),mi.row());
|
||||||
|
|
||||||
TreeItem * item = static_cast<TreeItem*>(mi.internalPointer());
|
FolderItem * item = static_cast<FolderItem*>(mi.internalPointer());
|
||||||
|
|
||||||
TreeItem * parent = item->parent();
|
FolderItem * parent = item->parent();
|
||||||
parent->removeChild(mi.row());
|
parent->removeChild(mi.row());
|
||||||
|
|
||||||
Folder f;
|
Folder f;
|
||||||
@ -49,17 +49,17 @@
|
|||||||
|
|
||||||
#include "yacreader_global.h"
|
#include "yacreader_global.h"
|
||||||
|
|
||||||
class TreeItem;
|
class FolderItem;
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class TreeModel : public QAbstractItemModel
|
class FolderModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TreeModel(QObject *parent = 0);
|
FolderModel(QObject *parent = 0);
|
||||||
TreeModel( QSqlQuery &sqlquery, QObject *parent = 0);
|
FolderModel( QSqlQuery &sqlquery, QObject *parent = 0);
|
||||||
~TreeModel();
|
~FolderModel();
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
@ -68,7 +68,7 @@ public:
|
|||||||
QModelIndex index(int row, int column,
|
QModelIndex index(int row, int column,
|
||||||
const QModelIndex &parent = QModelIndex()) const;
|
const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
QModelIndex indexFromItem(TreeItem * item, int column);
|
QModelIndex indexFromItem(FolderItem * item, int column);
|
||||||
/*QModelIndex _indexFromItem(TreeItem * item, int column);
|
/*QModelIndex _indexFromItem(TreeItem * item, int column);
|
||||||
int column;*/
|
int column;*/
|
||||||
|
|
||||||
@ -104,16 +104,16 @@ public slots:
|
|||||||
void deleteFolder(const QModelIndex & mi);
|
void deleteFolder(const QModelIndex & mi);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupModelData( QSqlQuery &sqlquery, TreeItem *parent);
|
void setupModelData( QSqlQuery &sqlquery, FolderItem *parent);
|
||||||
void updateFolderModelData( QSqlQuery &sqlquery, TreeItem *parent);
|
void updateFolderModelData( QSqlQuery &sqlquery, FolderItem *parent);
|
||||||
void setupFilteredModelData( QSqlQuery &sqlquery, TreeItem *parent);
|
void setupFilteredModelData( QSqlQuery &sqlquery, FolderItem *parent);
|
||||||
void setupFilteredModelData();
|
void setupFilteredModelData();
|
||||||
|
|
||||||
TreeItem *rootItem; //el árbol
|
FolderItem *rootItem; //el árbol
|
||||||
QMap<unsigned long long int, TreeItem *> items; //relación entre folders
|
QMap<unsigned long long int, FolderItem *> items; //relación entre folders
|
||||||
|
|
||||||
TreeItem *rootBeforeFilter;
|
FolderItem *rootBeforeFilter;
|
||||||
QMap<unsigned long long int, TreeItem *> filteredItems; //relación entre folders
|
QMap<unsigned long long int, FolderItem *> filteredItems; //relación entre folders
|
||||||
|
|
||||||
QString _databasePath;
|
QString _databasePath;
|
||||||
|
|
||||||
5
YACReaderLibrary/db/reading_list_item.cpp
Normal file
5
YACReaderLibrary/db/reading_list_item.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "reading_list_item.h"
|
||||||
|
|
||||||
|
ReadingListItem::ReadingListItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
10
YACReaderLibrary/db/reading_list_item.h
Normal file
10
YACReaderLibrary/db/reading_list_item.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef READING_LIST_ITEM_H
|
||||||
|
#define READING_LIST_ITEM_H
|
||||||
|
|
||||||
|
class ReadingListItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ReadingListItem();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // READING_LIST_ITEM_H
|
||||||
6
YACReaderLibrary/db/reading_list_model.cpp
Normal file
6
YACReaderLibrary/db/reading_list_model.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "reading_list_model.h"
|
||||||
|
|
||||||
|
ReadingListModel::ReadingListModel(QObject *parent) :
|
||||||
|
QAbstractItemModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
18
YACReaderLibrary/db/reading_list_model.h
Normal file
18
YACReaderLibrary/db/reading_list_model.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef READING_LIST_MODEL_H
|
||||||
|
#define READING_LIST_MODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
|
class ReadingListModel : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ReadingListModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // READING_LIST_MODEL_H
|
||||||
@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include "tableitem.h"
|
|
||||||
|
|
||||||
//! [0]
|
|
||||||
TableItem::TableItem(const QList<QVariant> &data)
|
|
||||||
|
|
||||||
{
|
|
||||||
itemData = data;
|
|
||||||
}
|
|
||||||
//! [0]
|
|
||||||
|
|
||||||
//! [1]
|
|
||||||
TableItem::~TableItem()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
//! [1]
|
|
||||||
|
|
||||||
|
|
||||||
//! [5]
|
|
||||||
int TableItem::columnCount() const
|
|
||||||
{
|
|
||||||
return itemData.count();
|
|
||||||
}
|
|
||||||
//! [5]
|
|
||||||
|
|
||||||
//! [6]
|
|
||||||
QVariant TableItem::data(int column) const
|
|
||||||
{
|
|
||||||
return itemData.value(column);
|
|
||||||
}
|
|
||||||
//! [6]
|
|
||||||
|
|
||||||
void TableItem::setData(int column,const QVariant & value)
|
|
||||||
{
|
|
||||||
itemData[column] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [8]
|
|
||||||
int TableItem::row() const
|
|
||||||
{
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//! [8]
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
GridComicsView::GridComicsView(QWidget *parent) :
|
GridComicsView::GridComicsView(QWidget *parent) :
|
||||||
ComicsView(parent),_selectionModel(NULL)
|
ComicsView(parent),_selectionModel(NULL)
|
||||||
{
|
{
|
||||||
qmlRegisterType<TableModel>("comicModel",1,0,"TableModel");
|
qmlRegisterType<ComicModel>("comicModel",1,0,"TableModel");
|
||||||
|
|
||||||
view = new QQuickView();
|
view = new QQuickView();
|
||||||
container = QWidget::createWindowContainer(view, this);
|
container = QWidget::createWindowContainer(view, this);
|
||||||
@ -41,7 +41,7 @@ QLOG_INFO() << "setToolBar";
|
|||||||
static_cast<QVBoxLayout *>(this->layout())->insertWidget(1,toolBar);
|
static_cast<QVBoxLayout *>(this->layout())->insertWidget(1,toolBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridComicsView::setModel(TableModel *model)
|
void GridComicsView::setModel(ComicModel *model)
|
||||||
{
|
{
|
||||||
QLOG_INFO() << "setModel";
|
QLOG_INFO() << "setModel";
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public:
|
|||||||
explicit GridComicsView(QWidget *parent = 0);
|
explicit GridComicsView(QWidget *parent = 0);
|
||||||
virtual ~GridComicsView();
|
virtual ~GridComicsView();
|
||||||
void setToolBar(QToolBar * toolBar);
|
void setToolBar(QToolBar * toolBar);
|
||||||
void setModel(TableModel *model);
|
void setModel(ComicModel *model);
|
||||||
void setCurrentIndex(const QModelIndex &index);
|
void setCurrentIndex(const QModelIndex &index);
|
||||||
QModelIndex currentIndex();
|
QModelIndex currentIndex();
|
||||||
QItemSelectionModel * selectionModel();
|
QItemSelectionModel * selectionModel();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include "library_window.h"
|
#include "library_window.h"
|
||||||
#include "custom_widgets.h"
|
#include "custom_widgets.h"
|
||||||
#include "treeitem.h"
|
#include "folder_item.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
@ -43,7 +43,7 @@
|
|||||||
#include "options_dialog.h"
|
#include "options_dialog.h"
|
||||||
#include "help_about_dialog.h"
|
#include "help_about_dialog.h"
|
||||||
#include "server_config_dialog.h"
|
#include "server_config_dialog.h"
|
||||||
#include "tablemodel.h"
|
#include "comic_model.h"
|
||||||
#include "yacreader_tool_bar_stretch.h"
|
#include "yacreader_tool_bar_stretch.h"
|
||||||
#include "yacreader_table_view.h"
|
#include "yacreader_table_view.h"
|
||||||
|
|
||||||
@ -378,9 +378,9 @@ void LibraryWindow::setUpShortcutsManagement()
|
|||||||
void LibraryWindow::doModels()
|
void LibraryWindow::doModels()
|
||||||
{
|
{
|
||||||
//folders
|
//folders
|
||||||
foldersModel = new TreeModel();
|
foldersModel = new FolderModel();
|
||||||
//comics
|
//comics
|
||||||
comicsModel = new TableModel();
|
comicsModel = new ComicModel();
|
||||||
|
|
||||||
setSearchFilter(YACReader::NoModifiers, ""); //clear search filter
|
setSearchFilter(YACReader::NoModifiers, ""); //clear search filter
|
||||||
}
|
}
|
||||||
@ -1259,7 +1259,7 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
|
|||||||
unsigned long long int folderId = 1;
|
unsigned long long int folderId = 1;
|
||||||
if(mi.isValid())
|
if(mi.isValid())
|
||||||
{
|
{
|
||||||
TreeItem *item = static_cast<TreeItem*>(mi.internalPointer());
|
FolderItem *item = static_cast<FolderItem*>(mi.internalPointer());
|
||||||
folderId = item->id;
|
folderId = item->id;
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
libraryToolBar->setCurrentFolderName(item->data(0).toString());
|
libraryToolBar->setCurrentFolderName(item->data(0).toString());
|
||||||
@ -1277,14 +1277,14 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
|
|||||||
//setFoldersFilter("");
|
//setFoldersFilter("");
|
||||||
if(mi.isValid())
|
if(mi.isValid())
|
||||||
{
|
{
|
||||||
index = static_cast<TreeItem *>(mi.internalPointer())->originalItem;
|
index = static_cast<FolderItem *>(mi.internalPointer())->originalItem;
|
||||||
column = mi.column();
|
column = mi.column();
|
||||||
searchEdit->clear();
|
searchEdit->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = static_cast<TreeItem *>(mi.internalPointer());
|
index = static_cast<FolderItem *>(mi.internalPointer());
|
||||||
column = mi.column();
|
column = mi.column();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1492,7 +1492,7 @@ void LibraryWindow::addFolderToCurrentIndex()
|
|||||||
tr("Folder name:"), QLineEdit::Normal,
|
tr("Folder name:"), QLineEdit::Normal,
|
||||||
"", &ok);
|
"", &ok);
|
||||||
|
|
||||||
QRegExp invalidChars("\/\\\:\*\?\"\<\>\|");
|
QRegExp invalidChars("\/\\\:\*\?\"\<\>\|");//TODO this regexp is not properly written
|
||||||
bool isValid = !newFolderName.contains(invalidChars);
|
bool isValid = !newFolderName.contains(invalidChars);
|
||||||
|
|
||||||
if (ok && !newFolderName.isEmpty() && isValid)
|
if (ok && !newFolderName.isEmpty() && isValid)
|
||||||
@ -2444,9 +2444,9 @@ void LibraryWindow::updateFoldersViewConextMenu(const QModelIndex &mi)
|
|||||||
if(!mi.isValid())
|
if(!mi.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TreeItem * item = static_cast<TreeItem *>(mi.internalPointer());
|
FolderItem * item = static_cast<FolderItem *>(mi.internalPointer());
|
||||||
bool isFinished = item->data(TreeModel::Finished).toBool();
|
bool isFinished = item->data(FolderModel::Finished).toBool();
|
||||||
bool isCompleted = item->data(TreeModel::Completed).toBool();
|
bool isCompleted = item->data(FolderModel::Completed).toBool();
|
||||||
|
|
||||||
setFolderAsReadAction->setVisible(!isFinished);
|
setFolderAsReadAction->setVisible(!isFinished);
|
||||||
setFolderAsUnreadAction->setVisible(isFinished);
|
setFolderAsUnreadAction->setVisible(isFinished);
|
||||||
|
|||||||
@ -29,10 +29,10 @@ class PropertiesDialog;
|
|||||||
class PackageManager;
|
class PackageManager;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class TableModel;
|
class ComicModel;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
class TreeItem;
|
class FolderItem;
|
||||||
class TreeModel;
|
class FolderModel;
|
||||||
class QItemSelectionModel;
|
class QItemSelectionModel;
|
||||||
class QString;
|
class QString;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
@ -94,7 +94,7 @@ private:
|
|||||||
QSize slideSizeF;
|
QSize slideSizeF;
|
||||||
//search filter
|
//search filter
|
||||||
YACReaderSearchLineEdit * searchEdit;
|
YACReaderSearchLineEdit * searchEdit;
|
||||||
TreeItem * index; //index al que hay que hacer scroll despu<70>s de pulsar sobre un folder filtrado
|
FolderItem * index; //index al que hay que hacer scroll despu<70>s de pulsar sobre un folder filtrado
|
||||||
int column;
|
int column;
|
||||||
QString previousFilter;
|
QString previousFilter;
|
||||||
QCheckBox * includeComicsCheckBox;
|
QCheckBox * includeComicsCheckBox;
|
||||||
@ -110,8 +110,8 @@ private:
|
|||||||
|
|
||||||
YACReaderTreeView * foldersView;
|
YACReaderTreeView * foldersView;
|
||||||
YACReaderLibraryListWidget * selectedLibrary;
|
YACReaderLibraryListWidget * selectedLibrary;
|
||||||
TreeModel * foldersModel;
|
FolderModel * foldersModel;
|
||||||
TableModel * comicsModel;
|
ComicModel * comicsModel;
|
||||||
//QStringList paths;
|
//QStringList paths;
|
||||||
YACReaderLibraries libraries;
|
YACReaderLibraries libraries;
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "tableitem.h"
|
#include "comic_item.h"
|
||||||
|
|
||||||
YACReaderTableView::YACReaderTableView(QWidget *parent) :
|
YACReaderTableView::YACReaderTableView(QWidget *parent) :
|
||||||
QTableView(parent),showDelete(false),editing(false),myeditor(0)
|
QTableView(parent),showDelete(false),editing(false),myeditor(0)
|
||||||
@ -187,7 +187,7 @@ void YACReaderTableView::resizeEvent(QResizeEvent * event)
|
|||||||
void YACReaderRatingDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void YACReaderRatingDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
int rating = ((TableItem *)index.internalPointer())->data(11).toInt();
|
int rating = ((ComicItem *)index.internalPointer())->data(11).toInt();
|
||||||
|
|
||||||
StarRating starRating(rating);
|
StarRating starRating(rating);
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ QSize YACReaderRatingDelegate::sizeHint(const QStyleOptionViewItem &option,
|
|||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(option)
|
Q_UNUSED(option)
|
||||||
int rating = ((TableItem *)index.internalPointer())->data(11).toInt();
|
int rating = ((ComicItem *)index.internalPointer())->data(11).toInt();
|
||||||
StarRating starRating(rating);
|
StarRating starRating(rating);
|
||||||
return starRating.sizeHint();
|
return starRating.sizeHint();
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ QWidget *YACReaderRatingDelegate::createEditor(QWidget *parent,
|
|||||||
void YACReaderRatingDelegate::setEditorData(QWidget *editor,
|
void YACReaderRatingDelegate::setEditorData(QWidget *editor,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
int rating = ((TableItem *)index.internalPointer())->data(11).toInt();
|
int rating = ((ComicItem *)index.internalPointer())->data(11).toInt();
|
||||||
|
|
||||||
StarRating starRating(rating);
|
StarRating starRating(rating);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include "yacreader_treeview.h"
|
#include "yacreader_treeview.h"
|
||||||
#include "treeitem.h"
|
#include "folder_item.h"
|
||||||
#include "treemodel.h"
|
#include "folder_model.h"
|
||||||
|
|
||||||
#include "comic.h"
|
#include "comic.h"
|
||||||
#include "comic_files_manager.h"
|
#include "comic_files_manager.h"
|
||||||
@ -161,9 +161,9 @@ YACReaderTreeViewItemDeletegate::YACReaderTreeViewItemDeletegate(QObject *parent
|
|||||||
|
|
||||||
void YACReaderTreeViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void YACReaderTreeViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
TreeItem * item = static_cast<TreeItem *>(index.internalPointer());
|
FolderItem * item = static_cast<FolderItem *>(index.internalPointer());
|
||||||
|
|
||||||
if(!item->data(TreeModel::Completed).toBool())
|
if(!item->data(FolderModel::Completed).toBool())
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
|||||||
Reference in New Issue
Block a user