if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant();
- if (index.column() == 0)
- return toqstr(list_->data(index.row()));
- else if (index.column() == 1) {
+ if (index.column() == 0) {
+ docstring const word = list_->data(index.row());
+ return toqstr(word);
+ } else if (index.column() == 1) {
// get icon from cache
QPixmap scaled;
QString const name = ":" + toqstr(list_->icon(index.row()));
}
+bool GuiCompleter::completionAvailable() const
+{
+ return popup()->model()->rowCount() > 0;
+}
+
+
bool GuiCompleter::popupVisible() const
{
return popup()->isVisible();
rect = QRect(x, y - dim.ascent() - 3, 200, dim.height() + 6);
// show/update popup
- complete(rect);
QTreeView * p = static_cast<QTreeView *>(popup());
p->setColumnWidth(0, popup()->width() - 22 - p->verticalScrollBar()->width());
+
+ complete(rect);
}
popup()->hide();
if (popup_timer_.isActive())
popup_timer_.stop();
+
+ if (!inlineVisible())
+ setModel(new GuiCompletionModel(this, 0));
}
{
gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
inlineVisible_ = false;
+
+ if (!popupVisible())
+ setModel(new GuiCompletionModel(this, 0));
}
}
+void GuiCompleter::hidePopup()
+{
+ Cursor cur = gui_->bufferView().cursor();
+ cur.updateFlags(Update::None);
+
+ hidePopup(cur);
+
+ // redraw if needed
+ if (cur.disp_.update())
+ gui_->bufferView().processUpdateFlags(cur.disp_.update());
+}
+
+
+void GuiCompleter::hideInline()
+{
+ Cursor cur = gui_->bufferView().cursor();
+ cur.updateFlags(Update::None);
+
+ hideInline(cur);
+
+ // redraw if needed
+ if (cur.disp_.update())
+ gui_->bufferView().processUpdateFlags(cur.disp_.update());
+}
+
+
void GuiCompleter::activate()
{
if (!popupVisible() && !inlineVisible())
}
} else {
// In sorted models, do binary search for s.
- i = 0;
- size_t r = n - 1;
- while (r >= i && i < n) {
- size_t mid = (r + i) / 2;
+ int l = 0;
+ int r = n - 1;
+ while (r >= l && l < int(n)) {
+ size_t mid = (r + l) / 2;
QString const & mids
= model.data(model.index(mid, 0),
Qt::EditRole).toString();
// from the CompletionList has?
int c = s.compare(mids, Qt::CaseSensitive);
if (c == 0) {
- i = mid;
+ l = mid;
break;
- } else if (i == r) {
- i = n;
+ } else if (l == r) {
+ l = n;
break;
} else if (c > 0)
// middle is not far enough
- i = mid + 1;
+ l = mid + 1;
else
// middle is too far
r = mid - 1;
}
// loop was left without finding anything
- if (r < i)
+ if (r < l)
i = n;
+ else
+ i = l;
+ BOOST_ASSERT(0 <= i && i <= n);
}
// select the first if none was found