mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
fixed StyledDelegates and added proxymodel to lists model
This commit is contained in:
parent
58765649c2
commit
5f75d278d4
@ -166,6 +166,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
return QVariant(YACReader::noHighlightedIcon(":/images/folder.png"));
|
||||
#endif
|
||||
|
||||
if(role == FolderModel::CompletedRole)
|
||||
return item->data(FolderModel::Completed);
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
|
@ -125,6 +125,11 @@ public:
|
||||
Completed = 3
|
||||
};//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:
|
||||
void deleteFolder(const QModelIndex & mi);
|
||||
|
||||
|
@ -58,6 +58,21 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
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))
|
||||
return QVariant();
|
||||
|
||||
@ -446,3 +461,10 @@ int ReadingListModel::addLabelIntoList(LabelItem *item)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ReadingListModelProxy::ReadingListModelProxy(QObject *parent)
|
||||
:QSortFilterProxyModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define READING_LIST_MODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QModelIndex>
|
||||
#include <QVariant>
|
||||
#include <QSqlQuery>
|
||||
@ -14,6 +15,13 @@ class SpecialListItem;
|
||||
class ReadingListItem;
|
||||
class ReadingListSeparatorItem;
|
||||
|
||||
class ReadingListModelProxy : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ReadingListModelProxy(QObject *parent = 0);
|
||||
};
|
||||
|
||||
class ReadingListModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -42,6 +50,17 @@ public:
|
||||
void rename(const QModelIndex & mi, const QString & name);
|
||||
void deleteItem(const QModelIndex & mi);
|
||||
|
||||
enum Roles {
|
||||
TypeListsRole = Qt::UserRole + 1,
|
||||
};
|
||||
|
||||
enum TypeList {
|
||||
SpecialList,
|
||||
Label,
|
||||
ReadingList,
|
||||
Separator
|
||||
};
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
|
@ -418,6 +418,7 @@ void LibraryWindow::doModels()
|
||||
comicsModel = new ComicModel();
|
||||
//lists
|
||||
listsModel = new ReadingListModel();
|
||||
listsModelProxy = new ReadingListModelProxy();
|
||||
|
||||
//setSearchFilter(YACReader::NoModifiers, ""); //clear search filter
|
||||
}
|
||||
@ -1223,7 +1224,8 @@ void LibraryWindow::loadLibrary(const QString & name)
|
||||
foldersView->setModel(foldersModelProxy);
|
||||
|
||||
listsModel->setupReadingListsData(path);
|
||||
listsView->setModel(listsModel);
|
||||
listsModelProxy->setSourceModel(listsModel);
|
||||
listsView->setModel(listsModelProxy);
|
||||
|
||||
if(foldersModel->rowCount(QModelIndex())>0)
|
||||
disableFoldersActions(false);
|
||||
|
@ -65,6 +65,7 @@ class EditShortcutsDialog;
|
||||
class ComicFilesManager;
|
||||
class QProgressDialog;
|
||||
class ReadingListModel;
|
||||
class ReadingListModelProxy;
|
||||
class YACReaderReadingListsView;
|
||||
class YACReaderHistoryController;
|
||||
|
||||
@ -96,9 +97,7 @@ private:
|
||||
bool fullscreen;
|
||||
bool importedCovers; //if true, the library is read only (not updates,open comic or properties)
|
||||
bool fromMaximized;
|
||||
//Ya no se usan proxies, el rendimiento de la BD es suficiente
|
||||
//YACReaderTreeSearch * proxyFilter;
|
||||
//YACReaderSortComics * proxySort;
|
||||
|
||||
PackageManager * packageManager;
|
||||
|
||||
QSize slideSizeW;
|
||||
@ -131,6 +130,7 @@ private:
|
||||
FolderModelProxy * foldersModelProxy;
|
||||
ComicModel * comicsModel;
|
||||
ReadingListModel * listsModel;
|
||||
ReadingListModelProxy * listsModelProxy;
|
||||
//QStringList paths;
|
||||
YACReaderLibraries libraries;
|
||||
|
||||
|
@ -87,10 +87,8 @@ YACReaderFoldersViewItemDeletegate::YACReaderFoldersViewItemDeletegate(QObject *
|
||||
|
||||
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();
|
||||
#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->restore();
|
||||
}
|
||||
*/
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
@ -9,10 +9,13 @@
|
||||
#include "yacreader_history_controller.h"
|
||||
#include "comic_model.h"
|
||||
#include "folder_model.h"
|
||||
#include "reading_list_model.h"
|
||||
#include "comics_view.h"
|
||||
#include "empty_folder_widget.h"
|
||||
#include "yacreader_search_line_edit.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
YACReaderNavigationController::YACReaderNavigationController(LibraryWindow *parent) :
|
||||
QObject(parent),libraryWindow(parent)
|
||||
{
|
||||
@ -38,6 +41,8 @@ void YACReaderNavigationController::selectedFolder(const QModelIndex &mi)
|
||||
|
||||
loadFolderInfo(modelIndex);
|
||||
|
||||
//if a folder is selected, listsView selection must be cleared
|
||||
libraryWindow->listsView->clearSelection();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
//TODO NO searching allowed, just disable backward/forward actions in searching mode
|
||||
|
@ -29,6 +29,7 @@ public slots:
|
||||
void loadEmptyFolderInfo(const QModelIndex & modelIndex);
|
||||
|
||||
void loadFolderInfo(const QModelIndex & modelIndex);
|
||||
void loadListInfo(const QModelIndex & modelIndex);
|
||||
void loadPreviousStatus();
|
||||
|
||||
private:
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "yacreader_reading_lists_view.h"
|
||||
|
||||
#include "reading_list_item.h"
|
||||
#include "reading_list_model.h"
|
||||
|
||||
YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent)
|
||||
:YACReaderTreeView(parent)
|
||||
@ -20,9 +21,9 @@ YACReaderReadingListsViewItemDeletegate::YACReaderReadingListsViewItemDeletegate
|
||||
|
||||
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;
|
||||
}
|
||||
@ -45,14 +46,12 @@ void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QSt
|
||||
|
||||
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);
|
||||
|
||||
newSize.setHeight(7);
|
||||
|
||||
return newSize;
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,6 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent) :
|
||||
readingListsView = new YACReaderReadingListsView;
|
||||
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"));
|
||||
foldersTitle = new YACReaderTitledToolBar(tr("FOLDERS"));
|
||||
readingListsTitle = new YACReaderTitledToolBar(tr("READING LISTS"));
|
||||
@ -176,15 +173,6 @@ QSize YACReaderSideBar::sizeHint() const
|
||||
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)
|
||||
:QWidget(parent)
|
||||
{
|
||||
|
@ -38,9 +38,6 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected slots:
|
||||
void selectedIndex(const QModelIndex & mi);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user