Skip to content

Commit

Permalink
PropertyEditor: improve editing experience
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Sep 11, 2018
1 parent 7cf8dc2 commit 3a81bd5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/Gui/propertyeditor/PropertyEditor.cpp
Expand Up @@ -53,6 +53,9 @@ PropertyEditor::PropertyEditor(QWidget *parent)
QStyleOptionViewItem opt = viewOptions();
this->background = opt.palette.dark();
this->groupColor = opt.palette.color(QPalette::BrightText);

connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &)));
connect(this, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &)));
}

PropertyEditor::~PropertyEditor()
Expand Down Expand Up @@ -127,8 +130,17 @@ void PropertyEditor::currentChanged ( const QModelIndex & current, const QModelI
QTreeView::currentChanged(current, previous);
if (previous.isValid())
closePersistentEditor(model()->buddy(previous));
if (current.isValid())
openPersistentEditor(model()->buddy(current));

// DO NOT activate editor here, use onItemActivate() which response to
// signals of activated and clicked.
//
// if (current.isValid())
// openPersistentEditor(model()->buddy(current));
}

void PropertyEditor::onItemActivated ( const QModelIndex & index )
{
openPersistentEditor(model()->buddy(index));
}

void PropertyEditor::reset()
Expand Down
3 changes: 3 additions & 0 deletions src/Gui/propertyeditor/PropertyEditor.h
Expand Up @@ -81,6 +81,9 @@ class PropertyEditor : public QTreeView
QColor groupTextColor() const;
void setGroupTextColor(const QColor& c);

public Q_SLOTS:
void onItemActivated(const QModelIndex &index);

protected:
virtual void closeEditor (QWidget * editor, QAbstractItemDelegate::EndEditHint hint);
virtual void commitData (QWidget * editor);
Expand Down
14 changes: 13 additions & 1 deletion src/Gui/propertyeditor/PropertyItemDelegate.cpp
Expand Up @@ -38,6 +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*)));
}

PropertyItemDelegate::~PropertyItemDelegate()
Expand Down Expand Up @@ -112,6 +114,10 @@ bool PropertyItemDelegate::editorEvent (QEvent * event, QAbstractItemModel* mode
return QItemDelegate::editorEvent(event, model, option, index);
}

void PropertyItemDelegate::editorClosed(QWidget *editor) {
editor->close();
}

QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/,
const QModelIndex & index ) const
{
Expand All @@ -126,8 +132,14 @@ QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOpti
editor->setAutoFillBackground(true);
if (editor && childItem->isReadOnly())
editor->setDisabled(true);
else if (editor && this->pressed)
// else if (editor && this->pressed)
else if(editor) {
// We changed the way editor is activated in PropertyEditor (in response
// of signal activated and clicked), so now we should grab focus
// regardless of "preseed" or not (e.g. when activated by keyboard
// enter)
editor->setFocus();
}
this->pressed = false;
return editor;
}
Expand Down
1 change: 1 addition & 0 deletions src/Gui/propertyeditor/PropertyItemDelegate.h
Expand Up @@ -47,6 +47,7 @@ class PropertyItemDelegate : public QItemDelegate

public Q_SLOTS:
void valueChanged();
void editorClosed(QWidget *);

private:
mutable bool pressed;
Expand Down

0 comments on commit 3a81bd5

Please sign in to comment.