fix navigation with Tab or Shift+Tab in property editor

This commit is contained in:
wmayer
2019-03-04 19:15:53 +01:00
parent f29df543c2
commit f24bed170a
3 changed files with 41 additions and 25 deletions

View File

@@ -124,26 +124,6 @@ bool PropertyEditor::event(QEvent* event)
return QTreeView::event(event);
}
void PropertyEditor::closeEditor (QWidget * editor, QAbstractItemDelegate::EndEditHint hint)
{
if (autoupdate) {
App::Document* doc = App::GetApplication().getActiveDocument();
if (doc) {
if (!doc->isTransactionEmpty()) {
doc->commitTransaction();
// Between opening and committing a transaction a recompute
// could already have been done
if (doc->isTouched())
doc->recompute();
}
else {
doc->abortTransaction();
}
}
}
QTreeView::closeEditor(editor, hint);
}
void PropertyEditor::commitData (QWidget * editor)
{
committing = true;
@@ -185,6 +165,40 @@ void PropertyEditor::onItemActivated ( const QModelIndex & index )
openPersistentEditor(model()->buddy(index));
}
void PropertyEditor::closeEditor (QWidget * editor, QAbstractItemDelegate::EndEditHint hint)
{
if (autoupdate) {
App::Document* doc = App::GetApplication().getActiveDocument();
if (doc) {
if (!doc->isTransactionEmpty()) {
doc->commitTransaction();
// Between opening and committing a transaction a recompute
// could already have been done
if (doc->isTouched())
doc->recompute();
}
else {
doc->abortTransaction();
}
}
}
QTreeView::closeEditor(editor, hint);
if (autoupdate && this->state() == EditingState) {
App::Document* doc = App::GetApplication().getActiveDocument();
if (doc) {
QString edit;
QModelIndex index = currentIndex();
if (index.isValid()) {
PropertyItem* property = static_cast<PropertyItem*>(index.internalPointer());
edit = tr("Edit %1").arg(property->propertyName());
}
doc->openTransaction(edit.toUtf8());
}
}
}
void PropertyEditor::reset()
{
QTreeView::reset();

View File

@@ -38,8 +38,8 @@ using namespace Gui::PropertyEditor;
PropertyItemDelegate::PropertyItemDelegate(QObject* parent)
: QItemDelegate(parent), pressed(false)
{
connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
this, SLOT(editorClosed(QWidget*)));
connect(this, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
this, SLOT(editorClosed(QWidget*, QAbstractItemDelegate::EndEditHint)));
}
PropertyItemDelegate::~PropertyItemDelegate()
@@ -114,9 +114,11 @@ bool PropertyItemDelegate::editorEvent (QEvent * event, QAbstractItemModel* mode
return QItemDelegate::editorEvent(event, model, option, index);
}
void PropertyItemDelegate::editorClosed(QWidget *editor)
void PropertyItemDelegate::editorClosed(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
{
editor->close();
// don't close the editor when pressing Tab or Shift+Tab
if (hint != EditNextItem && hint != EditPreviousItem)
editor->close();
}
QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/,

View File

@@ -47,7 +47,7 @@ public:
public Q_SLOTS:
void valueChanged();
void editorClosed(QWidget *);
void editorClosed (QWidget * editor, QAbstractItemDelegate::EndEditHint hint);
private:
mutable bool pressed;