Fix Tab key edition on the Equipment table [patch]

Tomaz Canabrava tcanabrava at kde.org
Tue Oct 15 09:45:24 UTC 2013


I think I should have learned the format patch before.


On Tue, Oct 15, 2013 at 1:38 PM, Tomaz Canabrava <tcanabrava at kde.org> wrote:

> dirk asked me for the diff, here it is.
>
>
> On Tue, Oct 15, 2013 at 1:25 PM, Tomaz Canabrava <tcanabrava at kde.org>wrote:
>
>> The following changes since commit
>> e93f96a8ebfb38696c964f9a0af28eadccf8d1a2:
>>
>>   Add test dive with tank pressure sensor information (2013-10-15
>> 04:12:16 -0700)
>>
>> are available in the git repository at:
>>
>>   tabOnEquipmentEdit
>>
>> for you to fetch changes up to 28b458e8d9dd774b4d54d97788d7d00e650cc328:
>>
>>   Fixed the Tab behavior on the QCombobox Delegate (2013-10-15 13:11:35
>> -0300)
>>
>> ----------------------------------------------------------------
>> Tomaz Canabrava (1):
>>       Fixed the Tab behavior on the QCombobox Delegate
>>
>>  qt-ui/modeldelegates.cpp | 18 +++++++++++++++++-
>>  qt-ui/modeldelegates.h   |  1 +
>>  2 files changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
>> index a4f457f..d1e2839 100644
>> --- a/qt-ui/modeldelegates.cpp
>> +++ b/qt-ui/modeldelegates.cpp
>> @@ -22,6 +22,7 @@
>>  // Gets the index of the model in the currentRow and column.
>>  // currCombo is defined below.
>>  #define IDX( XX ) mymodel->index(currCombo.currRow, XX)
>> +static bool keyboardFinished = false;
>>
>>  StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
>>         QStyledItemDelegate(parent),
>> @@ -91,11 +92,12 @@ QWidget* ComboBoxDelegate::createEditor(QWidget*
>> parent, const QStyleOptionViewI
>>         comboDelegate->lineEdit()->installEventFilter(
>> const_cast<QObject*>(qobject_cast<const QObject*>(this)));
>>         comboDelegate->view()->installEventFilter(
>> const_cast<QObject*>(qobject_cast<const QObject*>(this)));
>>         connect(comboDelegate, SIGNAL(highlighted(QString)), this,
>> SLOT(testActivation(QString)));
>> -       connect(comboDelegate->lineEdit(), SIGNAL(editingFinished()),
>> this, SLOT(testActivation()));
>>         connect(comboDelegate, SIGNAL(activated(QString)), this,
>> SLOT(fakeActivation()));
>> +       connect(this,
>> SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), this,
>> SLOT(fixTabBehavior()));
>>         currCombo.comboEditor = comboDelegate;
>>         currCombo.currRow = index.row();
>>         currCombo.model = const_cast<QAbstractItemModel*>(index.model());
>> +       keyboardFinished = false;
>>
>>         // Current display of things on Gnome3 looks like shit, so
>>         // let`s fix that.
>> @@ -137,6 +139,16 @@ void ComboBoxDelegate::fakeActivation(){
>>         QStyledItemDelegate::eventFilter(currCombo.comboEditor, &ev);
>>  }
>>
>> +// This 'reverts' the model data to what we actually choosed,
>> +// becaus e a TAB is being understood by Qt as 'cancel' while
>> +// we are on a QComboBox ( but not on a QLineEdit.
>> +void ComboBoxDelegate::fixTabBehavior()
>> +{
>> +       if(keyboardFinished){
>> +               setModelData(0,0,QModelIndex());
>> +       }
>> +}
>> +
>>  bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event)
>>  {
>>         // Reacts on Key_UP and Key_DOWN to show the QComboBox - list of
>> choices.
>> @@ -147,6 +159,10 @@ bool ComboBoxDelegate::eventFilter(QObject* object,
>> QEvent* event)
>>                                 currCombo.ignoreSelection = true;
>>                                 currCombo.comboEditor->showPopup();
>>                         }
>> +                       if(ev->key() == Qt::Key_Tab || ev->key() ==
>> Qt::Key_Enter || ev->key() == Qt::Key_Return){
>> +                               currCombo.activeText  =
>> currCombo.comboEditor->currentText();
>> +                               keyboardFinished = true;
>> +                       }
>>                 }
>>                 else{   // the 'Drop Down Menu' part.
>>                         QKeyEvent *ev = static_cast<QKeyEvent*>(event);
>> diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h
>> index a16e472..9fade15 100644
>> --- a/qt-ui/modeldelegates.h
>> +++ b/qt-ui/modeldelegates.h
>> @@ -27,6 +27,7 @@ public slots:
>>         void testActivation(const QString& currString = QString());
>>         //HACK: try to get rid of this in the future.
>>         void fakeActivation();
>> +       void fixTabBehavior();
>>         virtual void revertModelData(QWidget* widget,
>> QAbstractItemDelegate::EndEditHint hint) = 0;
>>  protected:
>>         QAbstractItemModel *model;
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20131015/ad76e3f9/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fixed-the-Tab-behavior-on-the-QCombobox-Delegate.patch
Type: application/octet-stream
Size: 3694 bytes
Desc: not available
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20131015/ad76e3f9/attachment-0001.obj>


More information about the subsurface mailing list