Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/widgets/kmymoneyaccountcombo.cpp
Show First 20 Lines • Show All 231 Lines • ▼ Show 20 Line(s) | 231 | { | |||
---|---|---|---|---|---|
232 | return d->m_lastSelectedAccount; | 232 | return d->m_lastSelectedAccount; | ||
233 | } | 233 | } | ||
234 | 234 | | |||
235 | void KMyMoneyAccountCombo::setModel(QSortFilterProxyModel *model) | 235 | void KMyMoneyAccountCombo::setModel(QSortFilterProxyModel *model) | ||
236 | { | 236 | { | ||
237 | delete d->m_popupView; | 237 | delete d->m_popupView; | ||
238 | 238 | | |||
239 | KComboBox::setModel(model); | 239 | KComboBox::setModel(model); | ||
240 | 240 | model->setFilterKeyColumn(AccountsModel::Account); // CAUTION! Assumption is being made that Account column number is always 0 | |||
tbaumgart: Account column **must** always be column zero as only column 0 can carry the hierarchy. | |||||
That's understood. I think it's important to use AccountsModel::Account instead of 0 as it gives meaning and to forewarn developers that AccountsModel::Account shouldn't be anything else than 0. wojnilowicz: That's understood. I think it's important to use AccountsModel::Account instead of 0 as it… | |||||
241 | model->setFilterKeyColumn(AccountsModel::Account); | | |||
242 | model->setFilterRole(AccountsModel::FullNameRole); | 241 | model->setFilterRole(AccountsModel::FullNameRole); | ||
243 | 242 | | |||
244 | d->m_popupView = new QTreeView(this); | 243 | d->m_popupView = new QTreeView(this); | ||
245 | d->m_popupView->setModel(model); | 244 | d->m_popupView->setModel(model); | ||
246 | d->m_popupView->setSelectionMode(QAbstractItemView::SingleSelection); | 245 | d->m_popupView->setSelectionMode(QAbstractItemView::SingleSelection); | ||
247 | setView(d->m_popupView); | 246 | setView(d->m_popupView); | ||
248 | 247 | | |||
249 | d->m_popupView->setHeaderHidden(true); | 248 | d->m_popupView->setHeaderHidden(true); | ||
Show All 21 Lines | |||||
271 | 270 | | |||
272 | void KMyMoneyAccountCombo::makeCompletion(const QString& txt) | 271 | void KMyMoneyAccountCombo::makeCompletion(const QString& txt) | ||
273 | { | 272 | { | ||
274 | if(!d->m_inMakeCompletion) { | 273 | if(!d->m_inMakeCompletion) { | ||
275 | d->m_inMakeCompletion = true; | 274 | d->m_inMakeCompletion = true; | ||
276 | AccountNamesFilterProxyModel* filterModel = qobject_cast<AccountNamesFilterProxyModel*>(model()); | 275 | AccountNamesFilterProxyModel* filterModel = qobject_cast<AccountNamesFilterProxyModel*>(model()); | ||
277 | 276 | | |||
278 | if(filterModel) { | 277 | if(filterModel) { | ||
278 | const auto completionStr = QStringLiteral(".*"); | ||||
279 | if (txt.contains(MyMoneyFile::AccountSeperator) == 0) { | 279 | if (txt.contains(MyMoneyFile::AccountSeperator) == 0) { | ||
280 | // for some reason it helps to avoid internal errors if we | 280 | // for some reason it helps to avoid internal errors if we | ||
281 | // clear the filter before setting it to a new value | 281 | // clear the filter before setting it to a new value | ||
282 | filterModel->setFilterFixedString(QString()); | 282 | filterModel->setFilterFixedString(QString()); | ||
283 | const QString filterString = QString("%1%2%3").arg(".*").arg(QRegExp::escape(txt)).arg(".*"); | 283 | const auto filterString = QString::fromLatin1("%1%2%3").arg(completionStr).arg(QRegExp::escape(txt)).arg(completionStr); | ||
284 | filterModel->setFilterRegExp(QRegExp(filterString, Qt::CaseInsensitive)); | 284 | filterModel->setFilterRegExp(QRegExp(filterString, Qt::CaseInsensitive)); | ||
285 | } else { | 285 | } else { | ||
286 | QStringList parts = txt.split(MyMoneyFile::AccountSeperator /*, QString::SkipEmptyParts */); | 286 | QStringList parts = txt.split(MyMoneyFile::AccountSeperator /*, QString::SkipEmptyParts */); | ||
287 | QString pattern; | 287 | QString pattern; | ||
288 | QStringList::iterator it; | 288 | QStringList::iterator it; | ||
289 | for (it = parts.begin(); it != parts.end(); ++it) { | 289 | for (it = parts.begin(); it != parts.end(); ++it) { | ||
290 | if (pattern.length() > 1) | 290 | if (pattern.length() > 1) | ||
291 | pattern += MyMoneyFile::AccountSeperator; | 291 | pattern += MyMoneyFile::AccountSeperator; | ||
292 | pattern += QRegExp::escape(QString(*it).trimmed()) + ".*"; | 292 | pattern += QRegExp::escape(QString(*it).trimmed()) + completionStr; | ||
293 | } | 293 | } | ||
294 | // for some reason it helps to avoid internal errors if we | 294 | // for some reason it helps to avoid internal errors if we | ||
295 | // clear the filter before setting it to a new value | 295 | // clear the filter before setting it to a new value | ||
296 | filterModel->setFilterFixedString(QString()); | 296 | filterModel->setFilterFixedString(QString()); | ||
297 | filterModel->setFilterRegExp(QRegExp(pattern, Qt::CaseInsensitive)); | 297 | filterModel->setFilterRegExp(QRegExp(pattern, Qt::CaseInsensitive)); | ||
298 | // if we don't have a match, we try it again, but this time | 298 | // if we don't have a match, we try it again, but this time | ||
299 | // we add a wildcard for the top level | 299 | // we add a wildcard for the top level | ||
300 | if (filterModel->visibleItems() == 0) { | 300 | if (filterModel->visibleItems() == 0) { | ||
301 | // for some reason it helps to avoid internal errors if we | 301 | // for some reason it helps to avoid internal errors if we | ||
302 | // clear the filter before setting it to a new value | 302 | // clear the filter before setting it to a new value | ||
303 | pattern = pattern.prepend(QString(".*") + MyMoneyFile::AccountSeperator); | 303 | pattern = pattern.prepend(completionStr + MyMoneyFile::AccountSeperator); | ||
304 | filterModel->setFilterFixedString(QString()); | 304 | filterModel->setFilterFixedString(QString()); | ||
305 | filterModel->setFilterRegExp(QRegExp(pattern, Qt::CaseInsensitive)); | 305 | filterModel->setFilterRegExp(QRegExp(pattern, Qt::CaseInsensitive)); | ||
306 | } | 306 | } | ||
307 | } | 307 | } | ||
308 | 308 | | |||
309 | // if nothing is shown, we might as well close the popup | 309 | // if nothing is shown, we might as well close the popup | ||
310 | switch(filterModel->visibleItems()) { | 310 | switch(filterModel->visibleItems()) { | ||
311 | case 0: | 311 | case 0: | ||
Show All 37 Lines |
Account column must always be column zero as only column 0 can carry the hierarchy.