void CategoricalCompleter::updateCurrentSuggestions() { QLineEdit*le=dynamic_cast<QLineEdit*>(widget()); if(le) { QString search=le->text(); QString newString=le->text(); QString suffix=search; search.truncate(le->cursorPosition()); suffix.remove(0,le->cursorPosition()+1); newString=search; search.remove(_completed); if(search.contains(" ")) { search.remove(0,search.lastIndexOf(" ")+1); } for(int i=_data.size()-1;i>=0;i--) { if((search==_data[i].prefix())) { qDebug()<<"!"<<completionPrefix()<<"##"<<newString<<"##"<<suffix<<search; setCompletionPrefix(newString); if(popup()->isHidden()) { // le->setText(newString); setModel(new QStringListModel(join(_data[i],newString))); complete(); _tableView->setData(&_data[i],newString); _currentSubset=&_data[i]; } break; } } } // if(popup()->isHidden()) { // complete(); // } }
void Completer::onTabPressed() { if (!d.lineEdit) return; // store selection int pos = d.lineEdit->cursorPosition(); int start = d.lineEdit->selectionStart(); QString selected = d.lineEdit->selectedText(); // select current word d.lineEdit->cursorWordForward(false); d.lineEdit->cursorWordBackward(true); QString word = d.lineEdit->selectedText(); // choose model if (word.startsWith('/')) { if (model() != d.slashModel) setModel(d.slashModel); } else { if (model() != d.defaultModel) setModel(d.defaultModel); } QString prefix = completionPrefix(); if (prefix.isEmpty() || !word.startsWith(prefix, Qt::CaseInsensitive)) setCompletionPrefix(word); // restore selection d.lineEdit->setCursorPosition(pos); if (start != -1) d.lineEdit->setSelection(start, selected.length()); // complete if (!word.isEmpty()) { complete(); int count = completionCount(); if (count > 0) { int next = currentRow() + 1; setCurrentRow(next % count); } } }
void HistoryCompleter::saveHistory() { Q_D(HistoryCompleter); d->model->saveEntry(completionPrefix()); }