Spreadsheet: Added auto completer.
This commit is contained in:
parent
4d5646fa5d
commit
310a684251
|
@ -27,7 +27,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="cellContent">
|
||||
<widget class="Gui::ExpressionLineEdit" name="cellContent">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
@ -46,6 +46,11 @@
|
|||
<extends>QTableView</extends>
|
||||
<header>SheetTableView.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::ExpressionLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header location="global">Gui/ExpressionCompleter.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>cells</tabstop>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -27,13 +27,17 @@
|
|||
|
||||
#include <QItemDelegate>
|
||||
|
||||
namespace Spreadsheet {
|
||||
class Sheet;
|
||||
}
|
||||
|
||||
namespace SpreadsheetGui {
|
||||
|
||||
class SpreadsheetDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SpreadsheetDelegate(QWidget *parent = 0);
|
||||
explicit SpreadsheetDelegate(Spreadsheet::Sheet * sheet, QWidget *parent = 0);
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
|
||||
const QModelIndex &index) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
|
@ -43,7 +47,8 @@ public:
|
|||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
private Q_SLOTS:
|
||||
void commitAndCloseEditor();
|
||||
|
||||
private:
|
||||
Spreadsheet::Sheet * sheet;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/ExpressionCompleter.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyStandard.h>
|
||||
#include <Gui/Command.h>
|
||||
|
@ -73,7 +74,7 @@ SheetView::SheetView(Gui::Document *pcDocument, App::DocumentObject *docObj, QWi
|
|||
ui->setupUi(w);
|
||||
setCentralWidget(w);
|
||||
|
||||
delegate = new SpreadsheetDelegate();
|
||||
delegate = new SpreadsheetDelegate(sheet);
|
||||
ui->cells->setModel(model);
|
||||
ui->cells->setItemDelegate(delegate);
|
||||
ui->cells->setSheet(sheet);
|
||||
|
@ -110,6 +111,9 @@ SheetView::SheetView(Gui::Document *pcDocument, App::DocumentObject *docObj, QWi
|
|||
QList<QtColorPicker*> fgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(QString::fromAscii("Spreadsheet_ForegroundColor"));
|
||||
if (fgList.size() > 0)
|
||||
fgList[0]->setCurrentColor(palette.color(QPalette::Text));
|
||||
|
||||
// Set document object to create auto completer
|
||||
ui->cellContent->setDocumentObject(sheet);
|
||||
}
|
||||
|
||||
SheetView::~SheetView()
|
||||
|
@ -195,6 +199,9 @@ void SheetView::updateContentLine()
|
|||
cell->getStringContent(str);
|
||||
ui->cellContent->setText(QString::fromUtf8(str.c_str()));
|
||||
ui->cellContent->setEnabled(true);
|
||||
|
||||
// Update completer model; for the time being, we do this by setting the document object of the input line.
|
||||
ui->cellContent->setDocumentObject(sheet);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,6 +280,11 @@ void SheetView::resizeRow(int col, int newSize)
|
|||
|
||||
void SheetView::editingFinished()
|
||||
{
|
||||
if (ui->cellContent->completerActive()) {
|
||||
ui->cellContent->hideCompleter();
|
||||
return;
|
||||
}
|
||||
|
||||
QModelIndex i = ui->cells->currentIndex();
|
||||
|
||||
// Update data in cell
|
||||
|
|
Loading…
Reference in New Issue
Block a user