UX: Auto expand port group and allow deselect in PortsWindow

This commit is contained in:
Srivats P 2017-09-09 13:13:52 +05:30
parent d348229028
commit abb48a1c12
3 changed files with 72 additions and 2 deletions

View File

@ -373,7 +373,22 @@ void PortsWindow::when_portView_currentChanged(const QModelIndex& currentIndex,
void PortsWindow::when_portModel_dataChanged(const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{
qDebug("In %s", __FUNCTION__);
qDebug("In %s %d:(%d, %d) - %d:(%d, %d)", __FUNCTION__,
topLeft.parent().isValid(), topLeft.row(), topLeft.column(),
bottomRight.parent().isValid(), bottomRight.row(), bottomRight.column());
if (!topLeft.isValid() || !bottomRight.isValid())
return;
if (topLeft.parent() != bottomRight.parent())
return;
// If a port has changed, expand the port group
if (topLeft.parent().isValid())
tvPortList->expand(proxyPortModel ?
proxyPortModel->mapFromSource(topLeft.parent()) :
topLeft.parent());
#if 0 // not sure why the >= <= operators are not overloaded in QModelIndex
if ((tvPortList->currentIndex() >= topLeft) &&
(tvPortList->currentIndex() <= bottomRight))

View File

@ -22,7 +22,7 @@
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QTreeView" name="tvPortList">
<widget class="XTreeView" name="tvPortList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
@ -368,6 +368,11 @@
<header>deviceswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>XTreeView</class>
<extends>QTreeView</extends>
<header>xtreeview.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="ostinato.qrc"/>

50
client/xtreeview.h Normal file
View File

@ -0,0 +1,50 @@
/*
Copyright (C) 2017 Srivats P.
This file is part of "Ostinato"
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef _X_TREE_VIEW_H
#define _X_TREE_VIEW_H
#include <QTreeView>
#include <QMouseEvent>
#if QT_VERSION >= 0x050000
#error "Do we even need this anymore?"
#endif
class XTreeView : public QTreeView
{
public:
XTreeView(QWidget *parent) : QTreeView(parent) {}
virtual ~XTreeView() {}
private:
virtual void mousePressEvent(QMouseEvent *event)
{
QModelIndex item = indexAt(event->pos());
if (!item.isValid())
setCurrentIndex(QModelIndex());
QTreeView::mousePressEvent(event);
}
};
#endif