Feature: Show My Reserved Ports Only linked to Port Stats window also
This commit is contained in:
parent
ad3a279cd6
commit
efbc2dcf48
@ -100,6 +100,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
||||||
portsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
portsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
||||||
|
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
||||||
|
statsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
||||||
|
|
||||||
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
||||||
this, SLOT(onNewVersion(QString)));
|
this, SLOT(onNewVersion(QString)));
|
||||||
|
@ -42,8 +42,9 @@ HEADERS += \
|
|||||||
portgroup.h \
|
portgroup.h \
|
||||||
portgrouplist.h \
|
portgrouplist.h \
|
||||||
portmodel.h \
|
portmodel.h \
|
||||||
portstatsmodel.h \
|
|
||||||
portstatsfilterdialog.h \
|
portstatsfilterdialog.h \
|
||||||
|
portstatsmodel.h \
|
||||||
|
portstatsproxymodel.h \
|
||||||
portstatswindow.h \
|
portstatswindow.h \
|
||||||
portswindow.h \
|
portswindow.h \
|
||||||
preferences.h \
|
preferences.h \
|
||||||
|
@ -118,6 +118,10 @@ QVariant PortStatsModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
switch(row)
|
switch(row)
|
||||||
{
|
{
|
||||||
|
// Info
|
||||||
|
case e_INFO_USER:
|
||||||
|
return pgl->mPortGroups.at(pgidx)->mPorts[pidx]->userName();
|
||||||
|
|
||||||
// States
|
// States
|
||||||
case e_LINK_STATE:
|
case e_LINK_STATE:
|
||||||
return LinkStateName.at(stats.state().link_state());
|
return LinkStateName.at(stats.state().link_state());
|
||||||
@ -179,12 +183,10 @@ QVariant PortStatsModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
else if (role == Qt::TextAlignmentRole)
|
else if (role == Qt::TextAlignmentRole)
|
||||||
{
|
{
|
||||||
if (row >= e_STATE_START && row <= e_STATE_END)
|
if (row >= e_STATISTICS_START && row <= e_STATISTICS_END)
|
||||||
return Qt::AlignHCenter;
|
return Qt::AlignRight; // right-align numbers
|
||||||
else if (row >= e_STATISTICS_START && row <= e_STATISTICS_END)
|
|
||||||
return Qt::AlignRight;
|
|
||||||
else
|
else
|
||||||
return QVariant();
|
return Qt::AlignHCenter; // center-align everything else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -299,6 +301,8 @@ void PortStatsModel::when_portListChanged()
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: unused? if used, the index calculation row/column needs to be swapped
|
||||||
|
#if 0
|
||||||
void PortStatsModel::on_portStatsUpdate(int port, void* /*stats*/)
|
void PortStatsModel::on_portStatsUpdate(int port, void* /*stats*/)
|
||||||
{
|
{
|
||||||
QModelIndex topLeft = index(port, 0, QModelIndex());
|
QModelIndex topLeft = index(port, 0, QModelIndex());
|
||||||
@ -306,6 +310,7 @@ void PortStatsModel::on_portStatsUpdate(int port, void* /*stats*/)
|
|||||||
|
|
||||||
emit dataChanged(topLeft, bottomRight);
|
emit dataChanged(topLeft, bottomRight);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void PortStatsModel::updateStats()
|
void PortStatsModel::updateStats()
|
||||||
{
|
{
|
||||||
@ -320,7 +325,7 @@ void PortStatsModel::when_portGroup_stats_update(quint32 /*portGroupId*/)
|
|||||||
// FIXME(MED): update only the changed ports, not all
|
// FIXME(MED): update only the changed ports, not all
|
||||||
|
|
||||||
QModelIndex topLeft = index(0, 0, QModelIndex());
|
QModelIndex topLeft = index(0, 0, QModelIndex());
|
||||||
QModelIndex bottomRight = index(rowCount(), columnCount(), QModelIndex());
|
QModelIndex bottomRight = index(rowCount()-1, columnCount()-1, QModelIndex());
|
||||||
|
|
||||||
emit dataChanged(topLeft, bottomRight);
|
emit dataChanged(topLeft, bottomRight);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
// Info
|
||||||
|
e_INFO_START = 0,
|
||||||
|
|
||||||
|
e_INFO_USER = e_INFO_START,
|
||||||
|
|
||||||
|
e_INFO_END = e_INFO_USER,
|
||||||
|
|
||||||
// State
|
// State
|
||||||
e_STATE_START = 0,
|
e_STATE_START,
|
||||||
|
|
||||||
e_LINK_STATE = e_STATE_START,
|
e_LINK_STATE = e_STATE_START,
|
||||||
e_TRANSMIT_STATE,
|
e_TRANSMIT_STATE,
|
||||||
@ -65,6 +72,8 @@ typedef enum {
|
|||||||
} PortStat;
|
} PortStat;
|
||||||
|
|
||||||
static QStringList PortStatName = (QStringList()
|
static QStringList PortStatName = (QStringList()
|
||||||
|
<< "User"
|
||||||
|
|
||||||
<< "Link State"
|
<< "Link State"
|
||||||
<< "Transmit State"
|
<< "Transmit State"
|
||||||
<< "Capture State"
|
<< "Capture State"
|
||||||
@ -127,7 +136,7 @@ class PortStatsModel : public QAbstractTableModel
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void when_portListChanged();
|
void when_portListChanged();
|
||||||
void on_portStatsUpdate(int port, void*stats);
|
//void on_portStatsUpdate(int port, void*stats);
|
||||||
void when_portGroup_stats_update(quint32 portGroupId);
|
void when_portGroup_stats_update(quint32 portGroupId);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
52
client/portstatsproxymodel.h
Normal file
52
client/portstatsproxymodel.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2015 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 _PORT_STATS_PROXY_MODEL_H
|
||||||
|
#define _PORT_STATS_PROXY_MODEL_H
|
||||||
|
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
class PortStatsProxyModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
PortStatsProxyModel(QObject *parent = 0)
|
||||||
|
: QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsColumn(int sourceColumn,
|
||||||
|
const QModelIndex &sourceParent) const
|
||||||
|
{
|
||||||
|
QModelIndex index = sourceModel()->index(0, sourceColumn, sourceParent);
|
||||||
|
QString user = sourceModel()->data(index).toString();
|
||||||
|
|
||||||
|
return filterRegExp().exactMatch(user) ? true : false;
|
||||||
|
}
|
||||||
|
bool filterAcceptsRow(int sourceRow,
|
||||||
|
const QModelIndex &sourceParent) const
|
||||||
|
{
|
||||||
|
// Hide row 0 - username (needed only by this filter class)
|
||||||
|
return (sourceRow > 0) ? true : false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -19,18 +19,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
|
|
||||||
#include "portstatswindow.h"
|
#include "portstatswindow.h"
|
||||||
#include "portstatsmodel.h"
|
|
||||||
#include "portstatsfilterdialog.h"
|
|
||||||
|
|
||||||
#include "QHeaderView"
|
#include "portstatsfilterdialog.h"
|
||||||
|
#include "portstatsmodel.h"
|
||||||
|
#include "portstatsproxymodel.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
#include <QHeaderView>
|
||||||
|
|
||||||
PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent)
|
PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent), proxyStatsModel(NULL)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
this->pgl = pgl;
|
this->pgl = pgl;
|
||||||
model = pgl->getPortStatsModel();
|
model = pgl->getPortStatsModel();
|
||||||
|
|
||||||
|
proxyStatsModel = new PortStatsProxyModel(this);
|
||||||
|
if (proxyStatsModel) {
|
||||||
|
proxyStatsModel->setSourceModel(model);
|
||||||
|
tvPortStats->setModel(proxyStatsModel);
|
||||||
|
}
|
||||||
|
else
|
||||||
tvPortStats->setModel(model);
|
tvPortStats->setModel(model);
|
||||||
|
|
||||||
tvPortStats->verticalHeader()->setHighlightSections(false);
|
tvPortStats->verticalHeader()->setHighlightSections(false);
|
||||||
@ -41,17 +51,31 @@ PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent)
|
|||||||
|
|
||||||
PortStatsWindow::~PortStatsWindow()
|
PortStatsWindow::~PortStatsWindow()
|
||||||
{
|
{
|
||||||
|
delete proxyStatsModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------- SLOTS -------------- */
|
/* ------------- SLOTS (public) -------------- */
|
||||||
|
|
||||||
|
void PortStatsWindow::showMyReservedPortsOnly(bool enabled)
|
||||||
|
{
|
||||||
|
if (!proxyStatsModel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
QString rx(appSettings->value(kUserKey, kUserDefaultValue).toString());
|
||||||
|
proxyStatsModel->setFilterRegExp(QRegExp::escape(rx));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
proxyStatsModel->setFilterRegExp(QRegExp(".*")); // match all
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------- SLOTS (private) -------------- */
|
||||||
void PortStatsWindow::on_tbStartTransmit_clicked()
|
void PortStatsWindow::on_tbStartTransmit_clicked()
|
||||||
{
|
{
|
||||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||||
|
|
||||||
// Get selected ports
|
// Get selected ports
|
||||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
model->portListFromIndex(selectedColumns(), pgpl);
|
||||||
pgpl);
|
|
||||||
|
|
||||||
// Clear selected ports, portgroup by portgroup
|
// Clear selected ports, portgroup by portgroup
|
||||||
for (int i = 0; i < pgpl.size(); i++)
|
for (int i = 0; i < pgpl.size(); i++)
|
||||||
@ -66,8 +90,7 @@ void PortStatsWindow::on_tbStopTransmit_clicked()
|
|||||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||||
|
|
||||||
// Get selected ports
|
// Get selected ports
|
||||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
model->portListFromIndex(selectedColumns(), pgpl);
|
||||||
pgpl);
|
|
||||||
|
|
||||||
// Clear selected ports, portgroup by portgroup
|
// Clear selected ports, portgroup by portgroup
|
||||||
for (int i = 0; i < pgpl.size(); i++)
|
for (int i = 0; i < pgpl.size(); i++)
|
||||||
@ -83,8 +106,7 @@ void PortStatsWindow::on_tbStartCapture_clicked()
|
|||||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||||
|
|
||||||
// Get selected ports
|
// Get selected ports
|
||||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
model->portListFromIndex(selectedColumns(), pgpl);
|
||||||
pgpl);
|
|
||||||
|
|
||||||
// Clear selected ports, portgroup by portgroup
|
// Clear selected ports, portgroup by portgroup
|
||||||
for (int i = 0; i < pgpl.size(); i++)
|
for (int i = 0; i < pgpl.size(); i++)
|
||||||
@ -100,8 +122,7 @@ void PortStatsWindow::on_tbStopCapture_clicked()
|
|||||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||||
|
|
||||||
// Get selected ports
|
// Get selected ports
|
||||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
model->portListFromIndex(selectedColumns(), pgpl);
|
||||||
pgpl);
|
|
||||||
|
|
||||||
// Clear selected ports, portgroup by portgroup
|
// Clear selected ports, portgroup by portgroup
|
||||||
for (int i = 0; i < pgpl.size(); i++)
|
for (int i = 0; i < pgpl.size(); i++)
|
||||||
@ -117,8 +138,7 @@ void PortStatsWindow::on_tbViewCapture_clicked()
|
|||||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||||
|
|
||||||
// Get selected ports
|
// Get selected ports
|
||||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
model->portListFromIndex(selectedColumns(), pgpl);
|
||||||
pgpl);
|
|
||||||
|
|
||||||
// Clear selected ports, portgroup by portgroup
|
// Clear selected ports, portgroup by portgroup
|
||||||
for (int i = 0; i < pgpl.size(); i++)
|
for (int i = 0; i < pgpl.size(); i++)
|
||||||
@ -133,8 +153,7 @@ void PortStatsWindow::on_tbClear_clicked()
|
|||||||
QList<PortStatsModel::PortGroupAndPortList> portList;
|
QList<PortStatsModel::PortGroupAndPortList> portList;
|
||||||
|
|
||||||
// Get selected ports
|
// Get selected ports
|
||||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
model->portListFromIndex(selectedColumns(), portList);
|
||||||
portList);
|
|
||||||
|
|
||||||
// Clear selected ports, portgroup by portgroup
|
// Clear selected ports, portgroup by portgroup
|
||||||
for (int i = 0; i < portList.size(); i++)
|
for (int i = 0; i < portList.size(); i++)
|
||||||
@ -146,6 +165,7 @@ void PortStatsWindow::on_tbClear_clicked()
|
|||||||
|
|
||||||
void PortStatsWindow::on_tbClearAll_clicked()
|
void PortStatsWindow::on_tbClearAll_clicked()
|
||||||
{
|
{
|
||||||
|
// FIXME: we clear all, not just all ports currently displayed!!!
|
||||||
for (int i = 0; i < pgl->numPortGroups(); i++)
|
for (int i = 0; i < pgl->numPortGroups(); i++)
|
||||||
{
|
{
|
||||||
pgl->portGroupByIndex(i).clearPortStats();
|
pgl->portGroupByIndex(i).clearPortStats();
|
||||||
@ -157,10 +177,14 @@ void PortStatsWindow::on_tbFilter_clicked()
|
|||||||
bool ok;
|
bool ok;
|
||||||
QList<uint> currentColumns, newColumns;
|
QList<uint> currentColumns, newColumns;
|
||||||
PortStatsFilterDialog dialog;
|
PortStatsFilterDialog dialog;
|
||||||
|
QAbstractItemModel *mdl = model;
|
||||||
|
|
||||||
|
if (proxyStatsModel)
|
||||||
|
mdl = proxyStatsModel;
|
||||||
|
|
||||||
// create the input list for the filter dialog -
|
// create the input list for the filter dialog -
|
||||||
// list of logical-indexes ordered by their current visual indexes
|
// list of logical-indexes ordered by their current visual indexes
|
||||||
for(int vi = 0; vi < model->columnCount(); vi++) {
|
for(int vi = 0; vi < mdl->columnCount(); vi++) {
|
||||||
int li = tvPortStats->horizontalHeader()->logicalIndex(vi);
|
int li = tvPortStats->horizontalHeader()->logicalIndex(vi);
|
||||||
if (!tvPortStats->isColumnHidden(li)) {
|
if (!tvPortStats->isColumnHidden(li)) {
|
||||||
currentColumns.append(li);
|
currentColumns.append(li);
|
||||||
@ -169,14 +193,14 @@ void PortStatsWindow::on_tbFilter_clicked()
|
|||||||
|
|
||||||
// return list from the filter dialog -
|
// return list from the filter dialog -
|
||||||
// list of logical-indexes ordered by their new visual indexes
|
// list of logical-indexes ordered by their new visual indexes
|
||||||
newColumns = dialog.getItemList(&ok, model, Qt::Horizontal, currentColumns);
|
newColumns = dialog.getItemList(&ok, mdl, Qt::Horizontal, currentColumns);
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
QHeaderView *hv = tvPortStats->horizontalHeader();
|
QHeaderView *hv = tvPortStats->horizontalHeader();
|
||||||
|
|
||||||
// hide/show sections first ...
|
// hide/show sections first ...
|
||||||
for(int li = 0; li < model->columnCount(); li++)
|
for(int li = 0; li < mdl->columnCount(); li++)
|
||||||
tvPortStats->setColumnHidden(li, !newColumns.contains(li));
|
tvPortStats->setColumnHidden(li, !newColumns.contains(li));
|
||||||
|
|
||||||
// ... then for the 'shown' columns, set the visual index
|
// ... then for the 'shown' columns, set the visual index
|
||||||
@ -184,3 +208,20 @@ void PortStatsWindow::on_tbFilter_clicked()
|
|||||||
hv->moveSection(hv->visualIndex(newColumns.at(vi)), vi);
|
hv->moveSection(hv->visualIndex(newColumns.at(vi)), vi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------ Private Methods -------------- */
|
||||||
|
|
||||||
|
QModelIndexList PortStatsWindow::selectedColumns()
|
||||||
|
{
|
||||||
|
QModelIndexList indexList =
|
||||||
|
tvPortStats->selectionModel()->selectedColumns();
|
||||||
|
QModelIndexList sourceIndexList;
|
||||||
|
|
||||||
|
if (!proxyStatsModel)
|
||||||
|
return indexList;
|
||||||
|
|
||||||
|
foreach(QModelIndex index, indexList)
|
||||||
|
sourceIndexList.append(proxyStatsModel->mapToSource(index));
|
||||||
|
|
||||||
|
return sourceIndexList;
|
||||||
|
}
|
||||||
|
@ -26,6 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "portgrouplist.h"
|
#include "portgrouplist.h"
|
||||||
#include "portstatsmodel.h"
|
#include "portstatsmodel.h"
|
||||||
|
|
||||||
|
class QSortFilterProxyModel;
|
||||||
|
|
||||||
class PortStatsWindow : public QWidget, public Ui::PortStatsWindow
|
class PortStatsWindow : public QWidget, public Ui::PortStatsWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -34,9 +36,8 @@ public:
|
|||||||
PortStatsWindow(PortGroupList *pgl, QWidget *parent = 0);
|
PortStatsWindow(PortGroupList *pgl, QWidget *parent = 0);
|
||||||
~PortStatsWindow();
|
~PortStatsWindow();
|
||||||
|
|
||||||
private:
|
public slots:
|
||||||
PortGroupList *pgl;
|
void showMyReservedPortsOnly(bool enabled);
|
||||||
PortStatsModel *model;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_tbStartTransmit_clicked();
|
void on_tbStartTransmit_clicked();
|
||||||
@ -50,6 +51,14 @@ private slots:
|
|||||||
void on_tbClearAll_clicked();
|
void on_tbClearAll_clicked();
|
||||||
|
|
||||||
void on_tbFilter_clicked();
|
void on_tbFilter_clicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QModelIndexList selectedColumns();
|
||||||
|
|
||||||
|
PortGroupList *pgl;
|
||||||
|
PortStatsModel *model;
|
||||||
|
QSortFilterProxyModel *proxyStatsModel;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user