Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit c70cb99b authored by Tobias Koenig's avatar Tobias Koenig

Add proxy model for grouping by author

svn path=/trunk/KDE/kdegraphics/okular/; revision=710548
parent df27f634
......@@ -304,7 +304,7 @@ QVariant AnnotationModel::data( const QModelIndex &index, int role ) const
switch ( role )
{
case Qt::DisplayRole:
return item->annotation->author();
return AnnotationGuiUtils::captionForAnnotation( item->annotation );
break;
case Qt::DecorationRole:
return KIcon( "okular" );
......
This diff is collapsed.
......@@ -61,7 +61,7 @@ class PageGroupProxyModel : public QAbstractProxyModel
public:
/**
* Creates a new page group proxy model.
* Creates a new page group proxy model.
*
* @param parent The parent object.
*/
......@@ -93,4 +93,53 @@ class PageGroupProxyModel : public QAbstractProxyModel
QList<QModelIndex> mIndexes;
QList<QPair< QModelIndex, QList<QModelIndex> > > mTreeIndexes;
};
/**
* A proxy model which groups the annotations by author.
*/
class AuthorGroupProxyModel : public QAbstractProxyModel
{
Q_OBJECT
public:
/**
* Creates a new author group proxy model.
*
* @param parent The parent object.
*/
AuthorGroupProxyModel( QObject *parent = 0 );
~AuthorGroupProxyModel();
virtual int columnCount( const QModelIndex &parentIndex ) const;
virtual int rowCount( const QModelIndex &parentIndex ) const;
virtual QModelIndex index( int row, int column, const QModelIndex &parentIndex = QModelIndex() ) const;
virtual QModelIndex parent( const QModelIndex &index ) const;
virtual QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const;
virtual QModelIndex mapToSource( const QModelIndex &proxyIndex ) const;
virtual void setSourceModel( QAbstractItemModel *model );
virtual QItemSelection mapSelectionToSource(const QItemSelection &selection) const;
virtual QItemSelection mapSelectionFromSource(const QItemSelection &selection) const;
QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const;
QMap<int, QVariant> itemData(const QModelIndex &index) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
public Q_SLOTS:
/**
* Sets whether the proxy model shall group
* the annotations by author.
*/
void groupByAuthor( bool value );
private Q_SLOTS:
void rebuildIndexes();
private:
class Private;
Private* const d;
};
#endif
......@@ -103,11 +103,14 @@ Reviews::Reviews( QWidget * parent, Okular::Document * document )
m_filterProxy = new PageFilterProxyModel( m_view );
m_groupProxy = new PageGroupProxyModel( m_view );
m_authorProxy = new AuthorGroupProxyModel( m_view );
m_filterProxy->setSourceModel( m_model );
m_groupProxy->setSourceModel( m_filterProxy );
m_authorProxy->setSourceModel( m_groupProxy );
m_view->setModel( m_groupProxy );
m_view->setModel( m_authorProxy );
vLayout->addWidget( new KTreeViewSearchLine( this, m_view ) );
vLayout->addWidget( m_view );
......@@ -121,12 +124,11 @@ Reviews::Reviews( QWidget * parent, Okular::Document * document )
connect( groupByPageAction, SIGNAL( toggled( bool ) ), this, SLOT( slotPageEnabled( bool ) ) );
groupByPageAction->setChecked( Okular::Settings::groupByPage() );
// - add Author button
/*
QAction * groupByAuthorAction = toolBar->addAction( KIcon( "user" ), i18n( "Group by Author" ) );
groupByAuthorAction->setCheckable( true );
connect( groupByAuthorAction, SIGNAL( toggled( bool ) ), this, SLOT( slotAuthorEnabled( bool ) ) );
groupByAuthorAction->setChecked( Okular::Settings::groupByAuthor() );
*/
// - add separator
toolBar->addSeparator();
// - add Current Page Only button
......@@ -157,13 +159,17 @@ void Reviews::slotPageEnabled( bool on )
// store toggle state in Settings and update the listview
Okular::Settings::setGroupByPage( on );
m_groupProxy->groupByPage( on );
m_view->expandAll();
}
void Reviews::slotAuthorEnabled( bool on )
{
// store toggle state in Settings and update the listview
Okular::Settings::setGroupByAuthor( on );
//m_proxy->groupByAuthor( on );
m_authorProxy->groupByAuthor( on );
m_view->expandAll();
}
void Reviews::slotCurrentPageOnly( bool on )
......@@ -171,13 +177,16 @@ void Reviews::slotCurrentPageOnly( bool on )
// store toggle state in Settings and update the listview
Okular::Settings::setCurrentPageOnly( on );
m_filterProxy->groupByCurrentPage( on );
m_view->expandAll();
}
//END GUI Slots
void Reviews::activated( const QModelIndex &index )
{
const QModelIndex filterIndex = m_groupProxy->mapToSource( index );
const QModelIndex authorIndex = m_authorProxy->mapToSource( index );
const QModelIndex filterIndex = m_groupProxy->mapToSource( authorIndex );
const QModelIndex annotIndex = m_filterProxy->mapToSource( filterIndex );
Okular::Annotation *annotation = m_model->annotationForIndex( annotIndex );
......
......@@ -23,6 +23,7 @@ class Document;
}
class AnnotationModel;
class AuthorGroupProxyModel;
class PageFilterProxyModel;
class PageGroupProxyModel;
class TreeView;
......@@ -59,6 +60,7 @@ class Reviews : public QWidget, public Okular::DocumentObserver
// internal storage
Okular::Document * m_document;
AnnotationModel * m_model;
AuthorGroupProxyModel * m_authorProxy;
PageFilterProxyModel * m_filterProxy;
PageGroupProxyModel * m_groupProxy;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment