Commit 515fefc2 authored by Allen Winter's avatar Allen Winter
Browse files

Implement filtering by priorities.

From Jaydeep, thanks!

Also includes a fix for expanding the tree whenever filtering changes.
and some added tooltips, whatsthis and KUIT.

REvIEW: 105760
BUG: 214879
FIXED-IN: 4.10
MERGE: backport the expandTree() stuff *only* to 4.8 and 4.9
parent edf47488
......@@ -78,8 +78,16 @@ KOTodoView::KOTodoView( bool sidebarView, QWidget *parent )
mQuickSearch->setVisible( KOPrefs::instance()->enableTodoQuickSearch() );
connect( mQuickSearch, SIGNAL(searchTextChanged(QString)),
mProxyModel, SLOT(setFilterRegExp(QString)) );
connect( mQuickSearch, SIGNAL(searchCategoryChanged(QStringList)),
connect( mQuickSearch, SIGNAL(searchTextChanged(QString)),
this, SLOT(expandTree()) );
connect( mQuickSearch, SIGNAL(filterCategoryChanged(QStringList)),
mProxyModel, SLOT(setCategoryFilter(QStringList)) );
connect( mQuickSearch, SIGNAL(filterCategoryChanged(QStringList)),
this, SLOT(expandTree()) );
connect( mQuickSearch, SIGNAL(filterPriorityChanged(QStringList)),
mProxyModel, SLOT(setPriorityFilter(QStringList)) );
connect( mQuickSearch, SIGNAL(filterPriorityChanged(QStringList)),
this, SLOT(expandTree()) );
}
mView = new KOTodoViewView( this );
......@@ -304,6 +312,11 @@ void KOTodoView::expandIndex( const QModelIndex &index )
}
}
void KOTodoView::expandTree()
{
mView->expandAll();
}
void KOTodoView::setCalendar( CalendarSupport::Calendar *cal )
{
BaseView::setCalendar( cal );
......
......@@ -88,6 +88,7 @@ class KOTodoView : public BaseView
virtual void updateConfig();
virtual void clearSelection();
void expandIndex( const QModelIndex &index );
void expandTree();
protected Q_SLOTS:
void addQuickTodo( Qt::KeyboardModifiers modifier );
......
......@@ -49,7 +49,12 @@ KOTodoViewQuickSearch::KOTodoViewQuickSearch( CalendarSupport::Calendar *calenda
layout->setContentsMargins( 0, 0, 0, 0 );
mSearchLine = new KLineEdit( this );
mSearchLine->setClickMessage( i18nc( "@label in QuickSearchLine", "Search" ) );
mSearchLine->setToolTip(
i18nc( "@info:tooltip", "Filter on matching summaries" ) );
mSearchLine->setWhatsThis(
i18nc( "@info:whatsthis",
"Enter text here to filter the to-dos that are shown by matching summaries." ) );
mSearchLine->setClickMessage( i18nc( "@label in QuickSearchLine", "Search Summaries" ) );
mSearchLine->setClearButtonShown( true );
connect( mSearchLine, SIGNAL(textChanged(QString)),
this, SIGNAL(searchTextChanged(QString)) );
......@@ -57,11 +62,17 @@ KOTodoViewQuickSearch::KOTodoViewQuickSearch( CalendarSupport::Calendar *calenda
layout->addWidget( mSearchLine, 3 );
mCategoryCombo = new KPIM::KCheckComboBox( this );
mCategoryCombo->setToolTip(
i18nc( "@info:tooltip", "Filter on these categories" ) );
mCategoryCombo->setWhatsThis(
i18nc( "@info:whatsthis",
"Use this combobox to filter the to-dos that are shown by "
"a list of selected categories." ) );
mCategoryCombo->setDefaultText( i18nc( "@item:inlistbox", "Select Categories" ) );
mCategoryCombo->setSeparator( i18nc( "@item:intext delimiter for joining category names", "," ) );
connect( mCategoryCombo, SIGNAL(checkedItemsChanged(QStringList)),
SLOT(emitSearchCategoryChanged()) );
SLOT(emitFilterCategoryChanged()) );
layout->addWidget( mCategoryCombo, 1 );
fillCategories();
......@@ -81,6 +92,20 @@ KOTodoViewQuickSearch::KOTodoViewQuickSearch( CalendarSupport::Calendar *calenda
mCategoryCombo->setMinimumWidth( mCategoryCombo->width() + pixelsToAdd );
}
mPriorityCombo = new KPIM::KCheckComboBox( this );
mPriorityCombo->setToolTip(
i18nc( "@info:tooltip", "Filter on these priorities" ) );
mPriorityCombo->setWhatsThis(
i18nc( "@info:whatsthis",
"Use this combobox to filter the to-dos that are shown by "
"a list of selected priorities." ) );
mPriorityCombo->setDefaultText( i18nc( "@item:inlistbox", "Select Priority" ) );
connect( mPriorityCombo,SIGNAL(checkedItemsChanged(QStringList)),
SLOT(emitFilterPriorityChanged()) );
layout->addWidget( mPriorityCombo, 1 );
fillPriorities();
setLayout( layout );
}
......@@ -101,6 +126,7 @@ void KOTodoViewQuickSearch::reset()
{
mSearchLine->clear();
mCategoryCombo->setCurrentIndex( 0 );
mPriorityCombo->setCurrentIndex( 0 );
}
void KOTodoViewQuickSearch::fillCategories()
......@@ -141,11 +167,34 @@ void KOTodoViewQuickSearch::fillCategories()
mCategoryCombo->setCheckedItems( currentCategories, Qt::UserRole );
}
void KOTodoViewQuickSearch::emitSearchCategoryChanged()
void KOTodoViewQuickSearch::fillPriorities()
{
QStringList priorityValues;
priorityValues.append( i18nc( "@action:inmenu priority is unspecified", "unspecified" ) );
priorityValues.append( i18nc( "@action:inmenu highest priority", "%1 (highest)", 1 ) );
for ( int p = 2; p < 10; ++p ) {
if ( p == 5 ) {
priorityValues.append( i18nc( "@action:inmenu medium priority", "%1 (medium)", p ) );
} else if ( p == 9 ) {
priorityValues.append( i18nc( "@action:inmenu lowest priority", "%1 (lowest)", p ) );
} else {
priorityValues.append( i18nc( "@action:inmenu", "%1", p ) );
}
}
// TODO: Using the same method as for categories to fill mPriorityCombo
IncidenceEditorNG::CategoryHierarchyReaderQComboBox( mPriorityCombo ).read( priorityValues );
}
void KOTodoViewQuickSearch::emitFilterCategoryChanged()
{
// The display role doesn't work because it represents subcategories
// as " subcategory", and we want "ParentCollection:subCategory"
emit searchCategoryChanged( mCategoryCombo->checkedItems( Qt::UserRole ) );
emit filterCategoryChanged( mCategoryCombo->checkedItems( Qt::UserRole ) );
}
void KOTodoViewQuickSearch::emitFilterPriorityChanged()
{
emit filterPriorityChanged( mPriorityCombo->checkedItems( Qt::UserRole ) );
}
#include "kotodoviewquicksearch.moc"
......@@ -58,22 +58,27 @@ class KOTodoViewQuickSearch : public QWidget
* so, if someone checks a subcategory, the value will be "ParentCategory:subCategory"
* and not " subcategory".
* */
void searchCategoryChanged( const QStringList & );
void filterCategoryChanged( const QStringList & );
void filterPriorityChanged( const QStringList & );
public Q_SLOTS:
void reset();
private Q_SLOTS:
void emitSearchCategoryChanged();
void emitFilterCategoryChanged();
void emitFilterPriorityChanged();
private:
/** Helper method for the filling of the category combo. */
void fillCategories();
/** Helper method for the filling of the priority combo. */
void fillPriorities();
CalendarSupport::Calendar *mCalendar;
KLineEdit *mSearchLine;
KPIM::KCheckComboBox *mCategoryCombo;
KPIM::KCheckComboBox *mPriorityCombo;
};
#endif
......@@ -40,18 +40,26 @@ void KOTodoViewSortFilterProxyModel::sort( int column, Qt::SortOrder order )
QSortFilterProxyModel::sort( column, order );
}
bool KOTodoViewSortFilterProxyModel::filterAcceptsRow(
int source_row, const QModelIndex &source_parent ) const
bool KOTodoViewSortFilterProxyModel::filterAcceptsRow( int source_row,
const QModelIndex &source_parent ) const
{
bool ret = QSortFilterProxyModel::filterAcceptsRow( source_row, source_parent );
bool returnValue = true;
if ( ret && !mPriorities.isEmpty() ) {
QString priorityValue =
sourceModel()->index( source_row, KOTodoModel::PriorityColumn, source_parent ).
data( Qt::EditRole ).toString();
returnValue = mPriorities.contains( priorityValue );
}
if ( ret && !mCategories.isEmpty() ) {
QStringList categories =
sourceModel()->index( source_row, KOTodoModel::CategoriesColumn, source_parent ).
data( Qt::EditRole ).toStringList();
foreach ( const QString &category, categories ) {
if ( mCategories.contains( category ) ) {
return true;
return returnValue && true;
}
}
ret = false;
......@@ -67,7 +75,7 @@ bool KOTodoViewSortFilterProxyModel::filterAcceptsRow(
}
}
return ret;
return ret && returnValue;
}
bool KOTodoViewSortFilterProxyModel::lessThan( const QModelIndex &left,
......@@ -152,6 +160,26 @@ bool KOTodoViewSortFilterProxyModel::lessThan( const QModelIndex &left,
}
}
void KOTodoViewSortFilterProxyModel::setPriorityFilter( const QStringList &priorities )
{
// preparing priority list for comparison
mPriorities.clear();
foreach ( const QString &eachPriority, priorities ){
if ( eachPriority == i18nc( "priority is unspecified", "unspecified" ) ){
mPriorities.append( i18n( "%1", 0 ) );
} else if ( eachPriority == i18nc( "highest priority", "%1 (highest)", 1 ) ) {
mPriorities.append( i18n( "%1", 1 ) );
} else if ( eachPriority == i18nc( "medium priority", "%1 (medium)", 5 ) ) {
mPriorities.append( i18n( "%1", 5 ) );
} else if ( eachPriority == i18nc( "lowest priority", "%1 (lowest)", 9 ) ) {
mPriorities.append( i18n( "%1", 9 ) );
} else {
mPriorities.append( eachPriority );
}
}
invalidateFilter();
}
void KOTodoViewSortFilterProxyModel::setCategoryFilter( const QStringList &categories )
{
mCategories = categories;
......
......@@ -42,18 +42,25 @@ class KOTodoViewSortFilterProxyModel : public QSortFilterProxyModel
return mCategories;
}
const QStringList &priorities() const
{
return mPriorities;
}
protected:
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
public Q_SLOTS:
void setCategoryFilter( const QStringList &categories );
void setPriorityFilter( const QStringList &priorities );
private:
int compareDueDates( const QModelIndex &left, const QModelIndex &right ) const;
int comparePriorities( const QModelIndex &left, const QModelIndex &right ) const;
int compareCompletion( const QModelIndex &left, const QModelIndex &right ) const;
QStringList mCategories;
QStringList mPriorities;
Qt::SortOrder mSortOrder;
};
......
Supports Markdown
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