KTextEditor argument hinting

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 31 09:20:45 GMT 2019


On Fri, 25 Jan 2019 15:12:52 +0100
Thomas Friedrichsmeier <thomas.friedrichsmeier at ruhr-uni-bochum.de>
wrote:
> I'm currently trying to figure out how to show argument hints in a
> ktexteditor view. I can register a CodeCompletionModel all right, but
> any completions where I set ArgumentHintDepth to non-zero just
> disappear.

Ok, I admit that was a difficult type of question, so more specifically:
In the following minimal example, why does the hint disappear as soon
as I return 1 for ArgumentHintDepth (instead of popping up in a
separate tip, as I would expect):

class MyDummyModel : public KTextEditor::CodeCompletionModel {
public:
  MyDummyModel(QObject *parent) :
    KTextEditor::CodeCompletionModel(parent) {
    setRowCount(1);
    setHasGroups(false);
  };
  ~MyDummyModel() {};

  QVariant data(const QModelIndex & index, int role) const {
    int col = index.column ();
    if (role == Qt::DisplayRole) {
      if (col == KTextEditor::CodeCompletionModel::Name) {
        return i18n("dummyhint");
      }
    } else if (role ==
        KTextEditor::CodeCompletionModel::ArgumentHintDepth) {
      return 1; // change to 0, and the dummy hint is visible
    }
    return QVariant();
  }

  void completionInvoked(KTextEditor::View * view,
     const KTextEditor::Range & range,
     KTextEditor::CodeCompletionModel::InvocationType invocationType) {
    // fake an update:
    beginResetModel();
    endResetModel();
  }
};

void testMyDummyModel() {
  KTextEditor::Editor* editor = KTextEditor::Editor::instance();
  KTextEditor::Document* m_doc = editor->createDocument(0);
  KTextEditor::View* m_view = m_doc->createView(0);
  KTextEditor::CodeCompletionInterface* m_iface =
    qobject_cast<KTextEditor::CodeCompletionInterface*>(m_view);
  m_iface->registerCompletionModel(new MyDummyModel(m_view));
  m_iface->setAutomaticInvocationEnabled(true);
  m_view->show ();
};

Thanks!
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mail.kde.org/pipermail/kwrite-devel/attachments/20190131/be63d363/attachment.sig>


More information about the KWrite-Devel mailing list