Changeset View
Changeset View
Standalone View
Standalone View
src/search/dolphinfacetswidget.cpp
Show All 24 Lines | |||||
25 | #include <QComboBox> | 25 | #include <QComboBox> | ||
26 | #include <QDate> | 26 | #include <QDate> | ||
27 | #include <QEvent> | 27 | #include <QEvent> | ||
28 | #include <QHBoxLayout> | 28 | #include <QHBoxLayout> | ||
29 | #include <QIcon> | 29 | #include <QIcon> | ||
30 | #include <QMenu> | 30 | #include <QMenu> | ||
31 | #include <QToolButton> | 31 | #include <QToolButton> | ||
32 | 32 | | |||
33 | namespace { | ||||
34 | | ||||
35 | QString termValue(const QString& text, int start = 0) | ||||
36 | { | ||||
37 | QString value = text.mid(start); | ||||
38 | if (!value.isEmpty() && value.at(0) == QLatin1Char('"')) { | ||||
meven: Maybe check that the first and last characters are quotes first before removing "
a tag could… | |||||
39 | value = value.mid(1); | ||||
40 | } | ||||
41 | if (!value.isEmpty() && value.back() == QLatin1Char('"')) { | ||||
42 | value = value.mid(0, value.size() - 1); | ||||
43 | } | ||||
44 | return value; | ||||
45 | } | ||||
46 | | ||||
47 | } | ||||
48 | | ||||
33 | DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : | 49 | DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : | ||
34 | QWidget(parent), | 50 | QWidget(parent), | ||
35 | m_typeSelector(nullptr), | 51 | m_typeSelector(nullptr), | ||
36 | m_dateSelector(nullptr), | 52 | m_dateSelector(nullptr), | ||
37 | m_ratingSelector(nullptr), | 53 | m_ratingSelector(nullptr), | ||
38 | m_tagsSelector(nullptr) | 54 | m_tagsSelector(nullptr) | ||
39 | { | 55 | { | ||
40 | m_typeSelector = new QComboBox(this); | 56 | m_typeSelector = new QComboBox(this); | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 135 | { | |||
126 | 142 | | |||
127 | if (m_dateSelector->currentIndex() > 0) { | 143 | if (m_dateSelector->currentIndex() > 0) { | ||
128 | const QDate date = m_dateSelector->currentData().toDate(); | 144 | const QDate date = m_dateSelector->currentData().toDate(); | ||
129 | terms << QStringLiteral("modified>=%1").arg(date.toString(Qt::ISODate)); | 145 | terms << QStringLiteral("modified>=%1").arg(date.toString(Qt::ISODate)); | ||
130 | } | 146 | } | ||
131 | 147 | | |||
132 | if (!m_searchTags.isEmpty()) { | 148 | if (!m_searchTags.isEmpty()) { | ||
133 | for (auto const &tag : m_searchTags) { | 149 | for (auto const &tag : m_searchTags) { | ||
150 | if (tag.contains(QLatin1Char(' '))) { | ||||
151 | terms << QStringLiteral("tag:\"%1\"").arg(tag); | ||||
152 | } else { | ||||
134 | terms << QStringLiteral("tag:%1").arg(tag); | 153 | terms << QStringLiteral("tag:%1").arg(tag); | ||
135 | } | 154 | } | ||
136 | } | 155 | } | ||
156 | } | ||||
137 | 157 | | |||
138 | return terms; | 158 | return terms; | ||
139 | } | 159 | } | ||
140 | 160 | | |||
141 | QString DolphinFacetsWidget::facetType() const | 161 | QString DolphinFacetsWidget::facetType() const | ||
142 | { | 162 | { | ||
143 | return m_typeSelector->currentData().toString(); | 163 | return m_typeSelector->currentData().toString(); | ||
144 | } | 164 | } | ||
Show All 11 Lines | 175 | if (term.startsWith(searchToken)) { | |||
156 | return true; | 176 | return true; | ||
157 | } | 177 | } | ||
158 | } | 178 | } | ||
159 | return false; | 179 | return false; | ||
160 | } | 180 | } | ||
161 | 181 | | |||
162 | void DolphinFacetsWidget::setSearchTerm(const QString& term) | 182 | void DolphinFacetsWidget::setSearchTerm(const QString& term) | ||
163 | { | 183 | { | ||
164 | if (term.startsWith(QLatin1String("modified>="))) { | 184 | if (term.startsWith(QLatin1String("modified>="))) { | ||
165 | const QString value = term.mid(10); | 185 | const QString value = termValue(term, 10); | ||
IMHO the new helper function should only strip the quotes. I'd keep the QString::mid(10) logic here, because it's clear that we are removing the modified>= prefix. elvisangelaccio: IMHO the new helper function should only strip the quotes. I'd keep the `QString::mid(10)`… | |||||
Done. It's more clear indeed. iasensio: Done. It's more clear indeed.
I just kept `stripQuotes()` for the `tags`case, since it's not… | |||||
166 | const QDate date = QDate::fromString(value, Qt::ISODate); | 186 | const QDate date = QDate::fromString(value, Qt::ISODate); | ||
167 | setTimespan(date); | 187 | setTimespan(date); | ||
168 | } else if (term.startsWith(QLatin1String("rating>="))) { | 188 | } else if (term.startsWith(QLatin1String("rating>="))) { | ||
169 | const QString value = term.mid(8); | 189 | const QString value = termValue(term, 8); | ||
170 | const int stars = value.toInt() / 2; | 190 | const int stars = value.toInt() / 2; | ||
171 | setRating(stars); | 191 | setRating(stars); | ||
172 | } else if (term.startsWith(QLatin1String("tag:")) || | 192 | } else if (term.startsWith(QLatin1String("tag:")) || | ||
173 | term.startsWith(QLatin1String("tag="))) { | 193 | term.startsWith(QLatin1String("tag="))) { | ||
174 | const QString value = term.mid(4); | 194 | const QString value = termValue(term, 4); | ||
175 | addSearchTag(value); | 195 | addSearchTag(value); | ||
176 | } | 196 | } | ||
177 | } | 197 | } | ||
178 | 198 | | |||
179 | void DolphinFacetsWidget::setFacetType(const QString& type) | 199 | void DolphinFacetsWidget::setFacetType(const QString& type) | ||
180 | { | 200 | { | ||
181 | for (int index = 0; index <= m_typeSelector->count(); index++) { | 201 | for (int index = 0; index <= m_typeSelector->count(); index++) { | ||
182 | if (type == m_typeSelector->itemData(index).toString()) { | 202 | if (type == m_typeSelector->itemData(index).toString()) { | ||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |
Maybe check that the first and last characters are quotes first before removing "
a tag could be 'my_documents"' (unlikely but...)