mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Clean-up DolphinFacetsWidget
Summary: Small refactor patch to clean-up some logic on setter and getter: - Search terms are previously splitted and set separately, so no need for extra splitting and `foreach` loop - Return search terms on a `QStringList` rather than join first Depends on: D26029 Test Plan: No behavior changes Reviewers: #dolphin, elvisangelaccio Reviewed By: #dolphin, elvisangelaccio Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D26150
This commit is contained in:
parent
732697d0d6
commit
c331d70685
3 changed files with 25 additions and 43 deletions
|
@ -115,7 +115,7 @@ void DolphinFacetsWidget::resetSearchTerms()
|
||||||
updateTagsMenu();
|
updateTagsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DolphinFacetsWidget::searchTerms() const
|
QStringList DolphinFacetsWidget::searchTerms() const
|
||||||
{
|
{
|
||||||
QStringList terms;
|
QStringList terms;
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ QString DolphinFacetsWidget::searchTerms() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return terms.join(QLatin1String(" AND "));
|
return terms;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DolphinFacetsWidget::facetType() const
|
QString DolphinFacetsWidget::facetType() const
|
||||||
|
@ -145,50 +145,36 @@ QString DolphinFacetsWidget::facetType() const
|
||||||
|
|
||||||
bool DolphinFacetsWidget::isSearchTerm(const QString& term) const
|
bool DolphinFacetsWidget::isSearchTerm(const QString& term) const
|
||||||
{
|
{
|
||||||
const QStringList subTerms = term.split(' ', QString::SkipEmptyParts);
|
static const QLatin1String searchTokens[] {
|
||||||
|
QLatin1String("modified>="),
|
||||||
|
QLatin1String("rating>="),
|
||||||
|
QLatin1String("tag:"), QLatin1String("tag=")
|
||||||
|
};
|
||||||
|
|
||||||
// If term has sub terms, then sone of the sub terms are always "rating" and "modified" terms.
|
for (const auto &searchToken : searchTokens) {
|
||||||
bool containsRating = false;
|
if (term.startsWith(searchToken)) {
|
||||||
bool containsModified = false;
|
return true;
|
||||||
bool containsTag = false;
|
|
||||||
|
|
||||||
foreach (const QString& subTerm, subTerms) {
|
|
||||||
if (subTerm.startsWith(QLatin1String("rating>="))) {
|
|
||||||
containsRating = true;
|
|
||||||
} else if (subTerm.startsWith(QLatin1String("modified>="))) {
|
|
||||||
containsModified = true;
|
|
||||||
} else if (subTerm.startsWith(QLatin1String("tag:")) ||
|
|
||||||
subTerm.startsWith(QLatin1String("tag="))) {
|
|
||||||
containsTag = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return containsModified || containsRating || containsTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinFacetsWidget::setSearchTerm(const QString& term)
|
void DolphinFacetsWidget::setSearchTerm(const QString& term)
|
||||||
{
|
{
|
||||||
// If term has sub terms, then the sub terms are always "rating" and "modified" terms.
|
if (term.startsWith(QLatin1String("modified>="))) {
|
||||||
// If term has no sub terms, then the term itself is either a "rating" term or a "modified"
|
const QString value = term.mid(10);
|
||||||
// term. To avoid code duplication we add term to subTerms list, if the list is empty.
|
|
||||||
QStringList subTerms = term.split(' ', QString::SkipEmptyParts);
|
|
||||||
|
|
||||||
foreach (const QString& subTerm, subTerms) {
|
|
||||||
if (subTerm.startsWith(QLatin1String("modified>="))) {
|
|
||||||
const QString value = subTerm.mid(10);
|
|
||||||
const QDate date = QDate::fromString(value, Qt::ISODate);
|
const QDate date = QDate::fromString(value, Qt::ISODate);
|
||||||
setTimespan(date);
|
setTimespan(date);
|
||||||
} else if (subTerm.startsWith(QLatin1String("rating>="))) {
|
} else if (term.startsWith(QLatin1String("rating>="))) {
|
||||||
const QString value = subTerm.mid(8);
|
const QString value = term.mid(8);
|
||||||
const int stars = value.toInt() / 2;
|
const int stars = value.toInt() / 2;
|
||||||
setRating(stars);
|
setRating(stars);
|
||||||
} else if (subTerm.startsWith(QLatin1String("tag:")) ||
|
} else if (term.startsWith(QLatin1String("tag:")) ||
|
||||||
subTerm.startsWith(QLatin1String("tag="))) {
|
term.startsWith(QLatin1String("tag="))) {
|
||||||
const QString value = subTerm.mid(4);
|
const QString value = term.mid(4);
|
||||||
addSearchTag(value);
|
addSearchTag(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DolphinFacetsWidget::setFacetType(const QString& type)
|
void DolphinFacetsWidget::setFacetType(const QString& type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
explicit DolphinFacetsWidget(QWidget* parent = nullptr);
|
explicit DolphinFacetsWidget(QWidget* parent = nullptr);
|
||||||
~DolphinFacetsWidget() override;
|
~DolphinFacetsWidget() override;
|
||||||
|
|
||||||
QString searchTerms() const;
|
QStringList searchTerms() const;
|
||||||
QString facetType() const;
|
QString facetType() const;
|
||||||
|
|
||||||
bool isSearchTerm(const QString& term) const;
|
bool isSearchTerm(const QString& term) const;
|
||||||
|
|
|
@ -477,11 +477,7 @@ QUrl DolphinSearchBox::balooUrlForSearching() const
|
||||||
Baloo::Query query;
|
Baloo::Query query;
|
||||||
query.addType(m_facetsWidget->facetType());
|
query.addType(m_facetsWidget->facetType());
|
||||||
|
|
||||||
QStringList queryStrings;
|
QStringList queryStrings = m_facetsWidget->searchTerms();
|
||||||
QString ratingQuery = m_facetsWidget->searchTerms();
|
|
||||||
if (!ratingQuery.isEmpty()) {
|
|
||||||
queryStrings << ratingQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_contentButton->isChecked()) {
|
if (m_contentButton->isChecked()) {
|
||||||
queryStrings << text;
|
queryStrings << text;
|
||||||
|
|
Loading…
Reference in a new issue