fixed StyledDelegates and added proxymodel to lists model

This commit is contained in:
Luis Ángel San Martín 2014-11-20 23:15:05 +01:00
parent 58765649c2
commit 5f75d278d4
12 changed files with 92 additions and 30 deletions

View File

@ -166,6 +166,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
return QVariant(YACReader::noHighlightedIcon(":/images/folder.png")); return QVariant(YACReader::noHighlightedIcon(":/images/folder.png"));
#endif #endif
if(role == FolderModel::CompletedRole)
return item->data(FolderModel::Completed);
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();

View File

@ -125,6 +125,11 @@ public:
Completed = 3 Completed = 3
};//id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL };//id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL
enum Roles {
FinishedRole = Qt::UserRole + 1,
CompletedRole
};
public slots: public slots:
void deleteFolder(const QModelIndex & mi); void deleteFolder(const QModelIndex & mi);

View File

@ -58,6 +58,21 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const
ListItem * item = static_cast<ListItem*>(index.internalPointer()); ListItem * item = static_cast<ListItem*>(index.internalPointer());
if (role == ReadingListModel::TypeListsRole)
{
if(typeid(*item) == typeid(SpecialListItem))
return QVariant(ReadingListModel::SpecialList);
if(typeid(*item) == typeid(LabelItem))
return QVariant(ReadingListModel::Label);
if(typeid(*item) == typeid(ReadingListItem))
return QVariant(ReadingListModel::ReadingList);
if(typeid(*item) == typeid(ReadingListSeparatorItem))
return QVariant(ReadingListModel::Separator);
}
if(typeid(*item) == typeid(ReadingListSeparatorItem)) if(typeid(*item) == typeid(ReadingListSeparatorItem))
return QVariant(); return QVariant();
@ -446,3 +461,10 @@ int ReadingListModel::addLabelIntoList(LabelItem *item)
} }
ReadingListModelProxy::ReadingListModelProxy(QObject *parent)
:QSortFilterProxyModel(parent)
{
}

View File

@ -2,6 +2,7 @@
#define READING_LIST_MODEL_H #define READING_LIST_MODEL_H
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QSortFilterProxyModel>
#include <QModelIndex> #include <QModelIndex>
#include <QVariant> #include <QVariant>
#include <QSqlQuery> #include <QSqlQuery>
@ -14,6 +15,13 @@ class SpecialListItem;
class ReadingListItem; class ReadingListItem;
class ReadingListSeparatorItem; class ReadingListSeparatorItem;
class ReadingListModelProxy : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit ReadingListModelProxy(QObject *parent = 0);
};
class ReadingListModel : public QAbstractItemModel class ReadingListModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
@ -42,6 +50,17 @@ public:
void rename(const QModelIndex & mi, const QString & name); void rename(const QModelIndex & mi, const QString & name);
void deleteItem(const QModelIndex & mi); void deleteItem(const QModelIndex & mi);
enum Roles {
TypeListsRole = Qt::UserRole + 1,
};
enum TypeList {
SpecialList,
Label,
ReadingList,
Separator
};
signals: signals:
private: private:

View File

@ -418,6 +418,7 @@ void LibraryWindow::doModels()
comicsModel = new ComicModel(); comicsModel = new ComicModel();
//lists //lists
listsModel = new ReadingListModel(); listsModel = new ReadingListModel();
listsModelProxy = new ReadingListModelProxy();
//setSearchFilter(YACReader::NoModifiers, ""); //clear search filter //setSearchFilter(YACReader::NoModifiers, ""); //clear search filter
} }
@ -1223,7 +1224,8 @@ void LibraryWindow::loadLibrary(const QString & name)
foldersView->setModel(foldersModelProxy); foldersView->setModel(foldersModelProxy);
listsModel->setupReadingListsData(path); listsModel->setupReadingListsData(path);
listsView->setModel(listsModel); listsModelProxy->setSourceModel(listsModel);
listsView->setModel(listsModelProxy);
if(foldersModel->rowCount(QModelIndex())>0) if(foldersModel->rowCount(QModelIndex())>0)
disableFoldersActions(false); disableFoldersActions(false);

View File

@ -65,6 +65,7 @@ class EditShortcutsDialog;
class ComicFilesManager; class ComicFilesManager;
class QProgressDialog; class QProgressDialog;
class ReadingListModel; class ReadingListModel;
class ReadingListModelProxy;
class YACReaderReadingListsView; class YACReaderReadingListsView;
class YACReaderHistoryController; class YACReaderHistoryController;
@ -96,9 +97,7 @@ private:
bool fullscreen; bool fullscreen;
bool importedCovers; //if true, the library is read only (not updates,open comic or properties) bool importedCovers; //if true, the library is read only (not updates,open comic or properties)
bool fromMaximized; bool fromMaximized;
//Ya no se usan proxies, el rendimiento de la BD es suficiente
//YACReaderTreeSearch * proxyFilter;
//YACReaderSortComics * proxySort;
PackageManager * packageManager; PackageManager * packageManager;
QSize slideSizeW; QSize slideSizeW;
@ -131,6 +130,7 @@ private:
FolderModelProxy * foldersModelProxy; FolderModelProxy * foldersModelProxy;
ComicModel * comicsModel; ComicModel * comicsModel;
ReadingListModel * listsModel; ReadingListModel * listsModel;
ReadingListModelProxy * listsModelProxy;
//QStringList paths; //QStringList paths;
YACReaderLibraries libraries; YACReaderLibraries libraries;

View File

@ -87,10 +87,8 @@ YACReaderFoldersViewItemDeletegate::YACReaderFoldersViewItemDeletegate(QObject *
void YACReaderFoldersViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void YACReaderFoldersViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
/*
FolderItem * item = static_cast<FolderItem *>(index.internalPointer());
if(!item->data(FolderModel::Completed).toBool()) if(index.data(FolderModel::CompletedRole).toBool())
{ {
painter->save(); painter->save();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -102,6 +100,6 @@ void YACReaderFoldersViewItemDeletegate::paint(QPainter *painter, const QStyleOp
painter->drawRect(0,option.rect.y(),2,option.rect.height()); painter->drawRect(0,option.rect.y(),2,option.rect.height());
painter->restore(); painter->restore();
} }
*/
QStyledItemDelegate::paint(painter, option, index); QStyledItemDelegate::paint(painter, option, index);
} }

View File

@ -9,10 +9,13 @@
#include "yacreader_history_controller.h" #include "yacreader_history_controller.h"
#include "comic_model.h" #include "comic_model.h"
#include "folder_model.h" #include "folder_model.h"
#include "reading_list_model.h"
#include "comics_view.h" #include "comics_view.h"
#include "empty_folder_widget.h" #include "empty_folder_widget.h"
#include "yacreader_search_line_edit.h" #include "yacreader_search_line_edit.h"
#include "QsLog.h"
YACReaderNavigationController::YACReaderNavigationController(LibraryWindow *parent) : YACReaderNavigationController::YACReaderNavigationController(LibraryWindow *parent) :
QObject(parent),libraryWindow(parent) QObject(parent),libraryWindow(parent)
{ {
@ -38,6 +41,8 @@ void YACReaderNavigationController::selectedFolder(const QModelIndex &mi)
loadFolderInfo(modelIndex); loadFolderInfo(modelIndex);
//if a folder is selected, listsView selection must be cleared
libraryWindow->listsView->clearSelection();
} }
void YACReaderNavigationController::reselectCurrentFolder() void YACReaderNavigationController::reselectCurrentFolder()
@ -69,11 +74,34 @@ void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex
} }
} }
void YACReaderNavigationController::selectedList(const QModelIndex &mi) void YACReaderNavigationController::loadListInfo(const QModelIndex &modelIndex)
{ {
} }
void YACReaderNavigationController::selectedList(const QModelIndex &mi)
{/*
//A proxy is used
QModelIndex modelIndex = libraryWindow->listsModelProxy->mapToSource(mi);
//update history
libraryWindow->historyController->updateHistory(modelIndex);
if(libraryWindow->status == LibraryWindow::Searching)
{
//when a list is selected the search mode has to be reset
libraryWindow->searchEdit->clearText();
libraryWindow->clearSearchFilter();
libraryWindow->listsView->scrollTo(mi,QAbstractItemView::PositionAtTop);
libraryWindow->listsView->setCurrentIndex(mi);
}
loadListInfo(modelIndex);
//if a list is selected, foldersView selection must be cleared
libraryWindow->foldersView->clearSelection();*/
}
void YACReaderNavigationController::selectedIndexFromHistory(const QModelIndex &sourceMI) void YACReaderNavigationController::selectedIndexFromHistory(const QModelIndex &sourceMI)
{ {
//TODO NO searching allowed, just disable backward/forward actions in searching mode //TODO NO searching allowed, just disable backward/forward actions in searching mode

View File

@ -29,6 +29,7 @@ public slots:
void loadEmptyFolderInfo(const QModelIndex & modelIndex); void loadEmptyFolderInfo(const QModelIndex & modelIndex);
void loadFolderInfo(const QModelIndex & modelIndex); void loadFolderInfo(const QModelIndex & modelIndex);
void loadListInfo(const QModelIndex & modelIndex);
void loadPreviousStatus(); void loadPreviousStatus();
private: private:

View File

@ -1,6 +1,7 @@
#include "yacreader_reading_lists_view.h" #include "yacreader_reading_lists_view.h"
#include "reading_list_item.h" #include "reading_list_item.h"
#include "reading_list_model.h"
YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent) YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent)
:YACReaderTreeView(parent) :YACReaderTreeView(parent)
@ -20,9 +21,9 @@ YACReaderReadingListsViewItemDeletegate::YACReaderReadingListsViewItemDeletegate
void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
ListItem * item = static_cast<ListItem*>(index.internalPointer()); ReadingListModel::TypeList typeList = (ReadingListModel::TypeList)index.data(ReadingListModel::TypeListsRole).toInt();
if(typeid(*item) == typeid(ReadingListSeparatorItem)) if(typeList == ReadingListModel::Separator)
{ {
return; return;
} }
@ -45,14 +46,12 @@ void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QSt
QSize YACReaderReadingListsViewItemDeletegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const QSize YACReaderReadingListsViewItemDeletegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
ListItem * item = static_cast<ListItem*>(index.internalPointer()); ReadingListModel::TypeList typeList = (ReadingListModel::TypeList)index.data(ReadingListModel::TypeListsRole).toInt();
if(typeid(*item) == typeid(ReadingListSeparatorItem)) if(typeList == ReadingListModel::Separator)
{ {
QSize newSize = QStyledItemDelegate::sizeHint(option, index); QSize newSize = QStyledItemDelegate::sizeHint(option, index);
newSize.setHeight(7); newSize.setHeight(7);
return newSize; return newSize;
} }

View File

@ -20,9 +20,6 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent) :
readingListsView = new YACReaderReadingListsView; readingListsView = new YACReaderReadingListsView;
selectedLibrary = new YACReaderLibraryListWidget; selectedLibrary = new YACReaderLibraryListWidget;
connect(foldersView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedIndex(QModelIndex)));
connect(readingListsView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedIndex(QModelIndex)));
librariesTitle = new YACReaderTitledToolBar(tr("LIBRARIES")); librariesTitle = new YACReaderTitledToolBar(tr("LIBRARIES"));
foldersTitle = new YACReaderTitledToolBar(tr("FOLDERS")); foldersTitle = new YACReaderTitledToolBar(tr("FOLDERS"));
readingListsTitle = new YACReaderTitledToolBar(tr("READING LISTS")); readingListsTitle = new YACReaderTitledToolBar(tr("READING LISTS"));
@ -176,15 +173,6 @@ QSize YACReaderSideBar::sizeHint() const
return QSize(275,200); return QSize(275,200);
} }
void YACReaderSideBar::selectedIndex(const QModelIndex &mi)
{
if(sender() == foldersView)
readingListsView->clearSelection();
else if(sender() == readingListsView)
foldersView->clearSelection();
}
YACReaderSideBarSeparator::YACReaderSideBarSeparator(QWidget *parent) YACReaderSideBarSeparator::YACReaderSideBarSeparator(QWidget *parent)
:QWidget(parent) :QWidget(parent)
{ {

View File

@ -38,9 +38,6 @@ signals:
public slots: public slots:
protected slots:
void selectedIndex(const QModelIndex & mi);
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);