From abb48a1c12cacbb0132d9d1cc25ff95216ddb459 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Sat, 9 Sep 2017 13:13:52 +0530 Subject: [PATCH] UX: Auto expand port group and allow deselect in PortsWindow --- client/portswindow.cpp | 17 +++++++++++++- client/portswindow.ui | 7 +++++- client/xtreeview.h | 50 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 client/xtreeview.h diff --git a/client/portswindow.cpp b/client/portswindow.cpp index 68d9e24..b3a31d5 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -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)) diff --git a/client/portswindow.ui b/client/portswindow.ui index ca3331f..546e468 100644 --- a/client/portswindow.ui +++ b/client/portswindow.ui @@ -22,7 +22,7 @@ false - + 1 @@ -368,6 +368,11 @@
deviceswidget.h
1 + + XTreeView + QTreeView +
xtreeview.h
+
diff --git a/client/xtreeview.h b/client/xtreeview.h new file mode 100644 index 0000000..b69eebb --- /dev/null +++ b/client/xtreeview.h @@ -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 +*/ + +#ifndef _X_TREE_VIEW_H +#define _X_TREE_VIEW_H + +#include + +#include + +#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 +