Spreadsheet: Added auto completer.

This commit is contained in:
Eivind Kvedalen
2015-08-21 20:48:18 +02:00
committed by wmayer
parent e39578c742
commit 95088a0061
4 changed files with 47 additions and 11 deletions

View File

@@ -22,14 +22,22 @@
* *
***************************************************************************/
#include "SpreadsheetDelegate.h"
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QItemDelegate>
#include <QLineEdit>
#endif
#include "SpreadsheetDelegate.h"
#include <App/DocumentObject.h>
#include <Mod/Spreadsheet/App/Sheet.h>
#include <Gui/ExpressionCompleter.h>
using namespace SpreadsheetGui;
SpreadsheetDelegate::SpreadsheetDelegate(QWidget *parent) :
QItemDelegate(parent)
SpreadsheetDelegate::SpreadsheetDelegate(Spreadsheet::Sheet * _sheet, QWidget *parent)
: QItemDelegate(parent)
, sheet(_sheet)
{
}
@@ -37,17 +45,23 @@ QWidget *SpreadsheetDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex &index) const
{
QLineEdit *editor = new QLineEdit(parent);
Gui::ExpressionLineEdit *editor = new Gui::ExpressionLineEdit(parent);
editor->setDocumentObject(sheet);
connect(editor, SIGNAL(returnPressed()), this, SLOT(commitAndCloseEditor()));
return editor;
}
void SpreadsheetDelegate::commitAndCloseEditor()
{
QLineEdit *editor = qobject_cast<QLineEdit *>(sender());
emit commitData(editor);
emit closeEditor(editor);
Gui::ExpressionLineEdit *editor = qobject_cast<Gui::ExpressionLineEdit *>(sender());
if (editor->completerActive()) {
editor->hideCompleter();
return;
}
Q_EMIT commitData(editor);
Q_EMIT closeEditor(editor);
}
void SpreadsheetDelegate::setEditorData(QWidget *editor,