Skip to content

Commit

Permalink
Address PR review.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenD98 committed Aug 18, 2024
1 parent dc31931 commit 0f164f8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
13 changes: 9 additions & 4 deletions src/core/qfieldcloudprojectsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2453,7 +2453,7 @@ bool QFieldCloudProjectsFilterModel::showLocalOnly() const

bool QFieldCloudProjectsFilterModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
{
auto currentRowIndex = mSourceModel->index( source_row, 0, source_parent );
const QModelIndex currentRowIndex = mSourceModel->index( source_row, 0, source_parent );
if ( mShowLocalOnly && mSourceModel->data( currentRowIndex, QFieldCloudProjectsModel::LocalPathRole ).toString().isEmpty() )
{
return false;
Expand All @@ -2472,9 +2472,9 @@ bool QFieldCloudProjectsFilterModel::filterAcceptsRow( int source_row, const QMo
break;
}

QString Name = mSourceModel->data( currentRowIndex, QFieldCloudProjectsModel::NameRole ).toString();
QString Description = mSourceModel->data( currentRowIndex, QFieldCloudProjectsModel::DescriptionRole ).toString();
QString Owner = mSourceModel->data( currentRowIndex, QFieldCloudProjectsModel::OwnerRole ).toString();
const QString Name = mSourceModel->data( currentRowIndex, QFieldCloudProjectsModel::NameRole ).toString();
const QString Description = mSourceModel->data( currentRowIndex, QFieldCloudProjectsModel::DescriptionRole ).toString();
const QString Owner = mSourceModel->data( currentRowIndex, QFieldCloudProjectsModel::OwnerRole ).toString();

bool matchesTextFilter = mTextFilter.isEmpty() || Name.contains( mTextFilter, Qt::CaseInsensitive ) || Description.contains( mTextFilter, Qt::CaseInsensitive ) || Owner.contains( mTextFilter, Qt::CaseInsensitive );

Expand All @@ -2488,3 +2488,8 @@ void QFieldCloudProjectsFilterModel::setTextFilter( const QString &newTextFilter
mTextFilter = newTextFilter;
invalidateFilter();
}

QString QFieldCloudProjectsFilterModel::textFilter() const
{
return mTextFilter;
}
10 changes: 8 additions & 2 deletions src/core/qfieldcloudprojectsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ class QFieldCloudProjectsFilterModel : public QSortFilterProxyModel
Q_PROPERTY( QFieldCloudProjectsModel *projectsModel READ projectsModel WRITE setProjectsModel NOTIFY projectsModelChanged )
Q_PROPERTY( ProjectsFilter filter READ filter WRITE setFilter NOTIFY filterChanged )
Q_PROPERTY( bool showLocalOnly READ showLocalOnly WRITE setShowLocalOnly NOTIFY showLocalOnlyChanged )
Q_PROPERTY( QString textFilter READ textFilter WRITE setTextFilter NOTIFY textFilterChanged )

public:
enum ProjectsFilter
Expand Down Expand Up @@ -539,7 +540,7 @@ class QFieldCloudProjectsFilterModel : public QSortFilterProxyModel
ProjectsFilter filter() const;

/**
* Sets the the cloud project \a filter.
* Sets the cloud project \a filter.
*/
void setFilter( ProjectsFilter filter );

Expand All @@ -553,13 +554,18 @@ class QFieldCloudProjectsFilterModel : public QSortFilterProxyModel
*/
void setShowLocalOnly( bool showLocalOnly );

Q_INVOKABLE void setTextFilter( const QString &newTextFilter );
/**
* Sets a filter text to apply to projects. This text will be searched in the project's name, owner's name, and descriptions.
*/
void setTextFilter( const QString &newTextFilter );
QString textFilter() const;

signals:

void projectsModelChanged();
void filterChanged();
void showLocalOnlyChanged();
void textFilterChanged();

protected:
virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
Expand Down
10 changes: 3 additions & 7 deletions src/qml/QFieldCloudScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,10 @@ Page {
}
}

SearchBar {
QfSearchBar {
id: searchBar
Layout.fillWidth: true
Layout.preferredHeight: 41
color: Theme.mainBackgroundColor

onValidateFilter: function (filter) {
table.model.setTextFilter(filter);
}
}

Rectangle {
Expand All @@ -207,7 +203,7 @@ Page {
projectsModel: cloudProjectsModel
filter: filterBar.currentIndex === 0 ? QFieldCloudProjectsFilterModel.PrivateProjects : QFieldCloudProjectsFilterModel.PublicProjects
showLocalOnly: cloudConnection.status !== QFieldCloudConnection.LoggedIn

textFilter: searchBar.searchTerm
onFilterChanged: {
if (cloudConnection.state === QFieldCloudConnection.Idle && cloudProjectsModel.busyProjectIds.length === 0) {
refreshProjectsList(filter === QFieldCloudProjectsFilterModel.PublicProjects);
Expand Down
12 changes: 2 additions & 10 deletions src/qml/SearchBar.qml → src/qml/imports/Theme/QfSearchBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import QtQuick.Controls
import org.qfield
import Theme

Rectangle {
z: 20

signal validateFilter(string text)
Item {
property alias searchTerm: searchBar.text

Rectangle {
width: parent.width
Expand Down Expand Up @@ -56,12 +54,6 @@ Rectangle {
placeholderText: (!searchBar.activeFocus && text === "" && displayText === "") ? qsTr("Search for project") : ""
background: Item {
}
Keys.onEnterPressed: {
validateFilter(searchBar.text);
}
Keys.onReturnPressed: {
validateFilter(searchBar.text);
}
}
}
}
1 change: 1 addition & 0 deletions src/qml/imports/Theme/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ QfTabBar 1.0 QfTabBar.qml
QfSwipeAnimator 1.0 QfSwipeAnimator.qml
QfProgrerssRing 1.0 QfProgrerssRing.qml
QfScrollBar 1.0 QfScrollBar.qml
QfSearchBar 1.0 QfSearchBar.qml
2 changes: 1 addition & 1 deletion src/qml/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@
<file>QFieldGuide.qml</file>
<file>imports/Theme/QfProgrerssRing.qml</file>
<file>imports/Theme/QfScrollBar.qml</file>
<file>SearchBar.qml</file>
<file>imports/Theme/QfSearchBar.qml</file>
</qresource>
</RCC>

0 comments on commit 0f164f8

Please sign in to comment.