Measurement database keyboard navigation.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-08 13:59:24 +03:00
parent 758fbc714f
commit 6533579b52
3 changed files with 54 additions and 4 deletions

View File

@ -30,6 +30,8 @@
#include "ui_dialogmdatabase.h" #include "ui_dialogmdatabase.h"
#include "../mapplication.h" #include "../mapplication.h"
#include <QKeyEvent>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogMDataBase::DialogMDataBase(const QStringList &list, QWidget *parent) DialogMDataBase::DialogMDataBase(const QStringList &list, QWidget *parent)
:QDialog(parent), :QDialog(parent),
@ -57,6 +59,8 @@ DialogMDataBase::DialogMDataBase(const QStringList &list, QWidget *parent)
ui->setupUi(this); ui->setupUi(this);
InitDataBase(list); InitDataBase(list);
ui->treeWidget->installEventFilter(this);
connect(ui->treeWidget, &QTreeWidget::itemChanged, this, &DialogMDataBase::UpdateChecks); connect(ui->treeWidget, &QTreeWidget::itemChanged, this, &DialogMDataBase::UpdateChecks);
connect(ui->treeWidget, &QTreeWidget::itemClicked, this, &DialogMDataBase::ShowDescription); connect(ui->treeWidget, &QTreeWidget::itemClicked, this, &DialogMDataBase::ShowDescription);
@ -91,6 +95,8 @@ DialogMDataBase::DialogMDataBase(QWidget *parent)
ui->setupUi(this); ui->setupUi(this);
InitDataBase(); InitDataBase();
ui->treeWidget->installEventFilter(this);
connect(ui->treeWidget, &QTreeWidget::itemClicked, this, &DialogMDataBase::ShowDescription); connect(ui->treeWidget, &QTreeWidget::itemClicked, this, &DialogMDataBase::ShowDescription);
ReadSettings(); ReadSettings();
@ -165,6 +171,38 @@ void DialogMDataBase::changeEvent(QEvent *event)
QDialog::changeEvent(event); QDialog::changeEvent(event);
} }
//---------------------------------------------------------------------------------------------------------------------
bool DialogMDataBase::eventFilter(QObject *target, QEvent *event)
{
if (target == ui->treeWidget)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch(keyEvent->key())
{
case Qt::Key_Up:
{
const QModelIndex model = ui->treeWidget->indexAbove(ui->treeWidget->currentIndex());
QTreeWidgetItem *item = ui->treeWidget->itemAbove(ui->treeWidget->currentItem());
emit ShowDescription(item, model.column());
break;
}
case Qt::Key_Down:
{
const QModelIndex model = ui->treeWidget->indexBelow(ui->treeWidget->currentIndex());
QTreeWidgetItem *item = ui->treeWidget->itemBelow(ui->treeWidget->currentItem());
emit ShowDescription(item, model.column());
break;
}
default:
break;
}
}
}
return QDialog::eventFilter(target, event);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogMDataBase::UpdateChecks(QTreeWidgetItem *item, int column) void DialogMDataBase::UpdateChecks(QTreeWidgetItem *item, int column)
{ {

View File

@ -53,6 +53,7 @@ public:
protected: protected:
virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE;
virtual bool eventFilter(QObject *target, QEvent *event) Q_DECL_OVERRIDE;
private slots: private slots:
void UpdateChecks(QTreeWidgetItem *item, int column); void UpdateChecks(QTreeWidgetItem *item, int column);

View File

@ -39,6 +39,9 @@
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::SingleSelection</enum>
</property> </property>
<property name="animated">
<bool>true</bool>
</property>
<attribute name="headerMinimumSectionSize"> <attribute name="headerMinimumSectionSize">
<number>57</number> <number>57</number>
</attribute> </attribute>
@ -63,6 +66,9 @@
</item> </item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -73,6 +79,11 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>treeWidget</tabstop>
<tabstop>textEdit</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources> <resources>
<include location="../share/resources/tapeicon.qrc"/> <include location="../share/resources/tapeicon.qrc"/>
</resources> </resources>
@ -84,8 +95,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>248</x> <x>257</x>
<y>254</y> <y>540</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@ -100,8 +111,8 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>316</x> <x>325</x>
<y>260</y> <y>540</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>286</x>