Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering documents #1142

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions resources/forms/documents.ui
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,6 @@
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="sortOrder">
<property name="sizePolicy">
Expand Down Expand Up @@ -146,17 +130,14 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QLineEdit" name="filterText">
<property name="placeholderText">
<string>filter the documents</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</spacer>
</widget>
</item>
</layout>
</item>
Expand Down
9 changes: 9 additions & 0 deletions src/document/UBDocumentController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,7 @@ void UBDocumentController::setupViews()

connect(mDocumentUI->sortKind, SIGNAL(activated(int)), this, SLOT(onSortKindChanged(int)));
connect(mDocumentUI->sortOrder, SIGNAL(toggled(bool)), this, SLOT(onSortOrderChanged(bool)));
connect(mDocumentUI->filterText, &QLineEdit::textChanged, this, &UBDocumentController::onFilterTextChanged);

connect(mDocumentUI->splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(onSplitterMoved(int, int)));

Expand Down Expand Up @@ -2416,6 +2417,12 @@ void UBDocumentController::onSortKindChanged(int index)
UBSettings::settings()->documentSortKind->setInt(index);
}

void UBDocumentController::onFilterTextChanged(const QString& filter)
{
mSortFilterProxyModel->setFilterCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
mSortFilterProxyModel->setFilterRegularExpression(filter);
}

void UBDocumentController::onSplitterMoved(int size, int index)
{
Q_UNUSED(index);
Expand Down Expand Up @@ -2461,6 +2468,8 @@ void UBDocumentController::show()

if(!mToolsPalette)
setupPalettes();

mDocumentUI->filterText->clear();
}


Expand Down
1 change: 1 addition & 0 deletions src/document/UBDocumentController.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ class UBDocumentController : public UBDocumentContainer
//N/C - NNE - 20140403
void onSortKindChanged(int index);
void onSortOrderChanged(bool order);
void onFilterTextChanged(const QString& filter);
void onSplitterMoved(int size, int index);
void collapseAll();
void expandAll();
Expand Down
21 changes: 21 additions & 0 deletions src/document/UBSortFilterProxyModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ bool UBSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex

return QSortFilterProxyModel::lessThan(left, right);
}

bool UBSortFilterProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
UBDocumentTreeModel *model = dynamic_cast<UBDocumentTreeModel*>(sourceModel());
if(model == nullptr)
{
return false;
}

if(model->isCatalog(model->index(sourceRow, 0, sourceParent)))
{
// Always show the catalog folders
return true;
}
else
{
// Filter the documents
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
}
6 changes: 3 additions & 3 deletions src/document/UBSortFilterProxyModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define UBSORTFILTERPROXYMODEL_H

#include <QSortFilterProxyModel>
#include "core/UBPersistenceManager.h"

class UBSortFilterProxyModel : public QSortFilterProxyModel
{
public:
UBSortFilterProxyModel();

bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
};

#endif // UBSORTFILTERPROXYMODEL_H
2 changes: 1 addition & 1 deletion src/gui/UBDocumentThumbnailsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "frameworks/UBCoreGraphicsScene.h"
#include "domain/UBGraphicsScene.h"
#include "core/UBSettings.h"
#include "domain/UBItem.h"
#include "gui/UBThumbnailView.h"
Expand Down
1 change: 1 addition & 0 deletions src/gui/UBFeaturesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBApplication.h"
#include "core/UBDownloadManager.h"
#include "core/UBPersistenceManager.h"
#include "globals/UBGlobals.h"
#include "board/UBBoardController.h"
#include "document/UBDocumentController.h"
Expand Down