Feature: Show My Reserved Ports Only
This commit is contained in:
parent
7dc7a840f1
commit
05b73a5390
@ -93,6 +93,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(actionFileExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||
connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||
|
||||
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
||||
portsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
||||
|
||||
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
||||
this, SLOT(onNewVersion(QString)));
|
||||
updater->checkForNewVersion();
|
||||
|
@ -40,7 +40,14 @@
|
||||
<addaction name="actionHelpAbout" />
|
||||
<addaction name="actionAboutQt" />
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView" >
|
||||
<property name="title" >
|
||||
<string>&View</string>
|
||||
</property>
|
||||
<addaction name="actionViewShowMyReservedPortsOnly" />
|
||||
</widget>
|
||||
<addaction name="menuFile" />
|
||||
<addaction name="menuView" />
|
||||
<addaction name="menuHelp" />
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar" />
|
||||
@ -76,6 +83,14 @@
|
||||
<string>About Qt</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionViewShowMyReservedPortsOnly" >
|
||||
<property name="checkable" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Show My &Reserved Ports Only</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="ostinato.qrc" />
|
||||
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "abstractfileformat.h"
|
||||
#include "portconfigdialog.h"
|
||||
#include "settings.h"
|
||||
#include "streamconfigdialog.h"
|
||||
#include "streamlistdelegate.h"
|
||||
|
||||
@ -28,13 +29,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include <QInputDialog>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QMessageBox>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent), proxyPortModel(NULL)
|
||||
{
|
||||
QAction *sep;
|
||||
|
||||
delegate = new StreamListDelegate;
|
||||
proxyPortModel = new QSortFilterProxyModel(this);
|
||||
|
||||
//slm = new StreamListModel();
|
||||
//plm = new PortGroupList();
|
||||
plm = pgl;
|
||||
@ -78,7 +82,23 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
||||
addActions(tvStreamList->actions());
|
||||
|
||||
tvStreamList->setModel(plm->getStreamModel());
|
||||
tvPortList->setModel(plm->getPortModel());
|
||||
|
||||
// XXX: It would be ideal if we only needed to do the below to
|
||||
// get the proxy model to do its magic. However, the QModelIndex
|
||||
// used by the source model and the proxy model are different
|
||||
// i.e. the row, column, internalId/internalPtr used by both
|
||||
// will be different. Since our domain objects - PortGroupList,
|
||||
// PortGroup, Port etc. use these attributes, we need to map the
|
||||
// proxy's index to the source's index before invoking any domain
|
||||
// object methods
|
||||
// TODO: research if we can skip the mapping when the domain
|
||||
// objects' design is reviewed
|
||||
if (proxyPortModel) {
|
||||
proxyPortModel->setSourceModel(plm->getPortModel());
|
||||
tvPortList->setModel(proxyPortModel);
|
||||
}
|
||||
else
|
||||
tvPortList->setModel(plm->getPortModel());
|
||||
|
||||
connect( plm->getPortModel(),
|
||||
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
|
||||
@ -122,41 +142,74 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
||||
|
||||
void PortsWindow::streamModelDataChanged()
|
||||
{
|
||||
if (plm->isPort(tvPortList->currentIndex()))
|
||||
plm->port(tvPortList->currentIndex()).recalculateAverageRates();
|
||||
QModelIndex current = tvPortList->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (plm->isPort(current))
|
||||
plm->port(current).recalculateAverageRates();
|
||||
}
|
||||
|
||||
PortsWindow::~PortsWindow()
|
||||
{
|
||||
delete delegate;
|
||||
delete proxyPortModel;
|
||||
}
|
||||
|
||||
void PortsWindow::showMyReservedPortsOnly(bool enabled)
|
||||
{
|
||||
if (!proxyPortModel)
|
||||
return;
|
||||
|
||||
if (enabled) {
|
||||
QString rx = "Port Group|\\[xxx\\]";
|
||||
rx.replace("xxx",
|
||||
appSettings->value(kUserKey, kUserDefaultValue).toString());
|
||||
qDebug("%s: regexp: <%s>", __FUNCTION__, qPrintable(rx));
|
||||
proxyPortModel->setFilterRegExp(QRegExp(rx));
|
||||
}
|
||||
else
|
||||
proxyPortModel->setFilterRegExp(QRegExp(""));
|
||||
}
|
||||
|
||||
void PortsWindow::on_tvStreamList_activated(const QModelIndex & index)
|
||||
{
|
||||
QModelIndex currentPort = tvPortList->currentIndex();
|
||||
StreamConfigDialog *scd;
|
||||
int ret;
|
||||
|
||||
if (proxyPortModel)
|
||||
currentPort = proxyPortModel->mapToSource(currentPort);
|
||||
|
||||
if (!index.isValid())
|
||||
{
|
||||
qDebug("%s: invalid index", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
scd = new StreamConfigDialog(plm->port(tvPortList->currentIndex()),
|
||||
index.row(), this);
|
||||
scd = new StreamConfigDialog(plm->port(currentPort), index.row(), this);
|
||||
qDebug("stream list activated\n");
|
||||
ret = scd->exec();
|
||||
|
||||
if (ret == QDialog::Accepted)
|
||||
plm->port(tvPortList->currentIndex()).recalculateAverageRates();
|
||||
plm->port(currentPort).recalculateAverageRates();
|
||||
|
||||
delete scd;
|
||||
}
|
||||
|
||||
void PortsWindow::when_portView_currentChanged(const QModelIndex& current,
|
||||
const QModelIndex& previous)
|
||||
void PortsWindow::when_portView_currentChanged(const QModelIndex& currentIndex,
|
||||
const QModelIndex& previousIndex)
|
||||
{
|
||||
QModelIndex current = currentIndex;
|
||||
QModelIndex previous = previousIndex;
|
||||
|
||||
if (proxyPortModel) {
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
previous = proxyPortModel->mapToSource(previous);
|
||||
}
|
||||
|
||||
plm->getStreamModel()->setCurrentPortIndex(current);
|
||||
updatePortViewActions(current);
|
||||
updatePortViewActions(currentIndex);
|
||||
updateStreamViewActions();
|
||||
|
||||
qDebug("In %s", __FUNCTION__);
|
||||
@ -217,6 +270,9 @@ void PortsWindow::on_averagePacketsPerSec_editingFinished()
|
||||
{
|
||||
QModelIndex current = tvPortList->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
Q_ASSERT(plm->isPort(current));
|
||||
|
||||
bool isOk;
|
||||
@ -229,6 +285,9 @@ void PortsWindow::on_averageBitsPerSec_editingFinished()
|
||||
{
|
||||
QModelIndex current = tvPortList->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
Q_ASSERT(plm->isPort(current));
|
||||
|
||||
bool isOk;
|
||||
@ -241,6 +300,9 @@ void PortsWindow::updatePortRates()
|
||||
{
|
||||
QModelIndex current = tvPortList->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (!current.isValid())
|
||||
return;
|
||||
|
||||
@ -255,6 +317,11 @@ void PortsWindow::updatePortRates()
|
||||
|
||||
void PortsWindow::updateStreamViewActions()
|
||||
{
|
||||
QModelIndex current = tvPortList->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
// For some reason hasSelection() returns true even if selection size is 0
|
||||
// so additional check for size introduced
|
||||
if (tvStreamList->selectionModel()->hasSelection() &&
|
||||
@ -288,7 +355,7 @@ void PortsWindow::updateStreamViewActions()
|
||||
else
|
||||
{
|
||||
qDebug("No selection");
|
||||
if (plm->isPort(tvPortList->currentIndex()))
|
||||
if (plm->isPort(current))
|
||||
actionNew_Stream->setEnabled(true);
|
||||
else
|
||||
actionNew_Stream->setDisabled(true);
|
||||
@ -296,13 +363,17 @@ void PortsWindow::updateStreamViewActions()
|
||||
actionDuplicate_Stream->setDisabled(true);
|
||||
actionDelete_Stream->setDisabled(true);
|
||||
}
|
||||
actionOpen_Streams->setEnabled(plm->isPort(
|
||||
tvPortList->selectionModel()->currentIndex()));
|
||||
actionOpen_Streams->setEnabled(plm->isPort(current));
|
||||
actionSave_Streams->setEnabled(tvStreamList->model()->rowCount() > 0);
|
||||
}
|
||||
|
||||
void PortsWindow::updatePortViewActions(const QModelIndex& current)
|
||||
void PortsWindow::updatePortViewActions(const QModelIndex& currentIndex)
|
||||
{
|
||||
QModelIndex current = currentIndex;
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (!current.isValid())
|
||||
{
|
||||
qDebug("current is now invalid");
|
||||
@ -375,6 +446,8 @@ void PortsWindow::on_pbApply_clicked()
|
||||
QModelIndex curPortGroup;
|
||||
|
||||
curPort = tvPortList->selectionModel()->currentIndex();
|
||||
if (proxyPortModel)
|
||||
curPort = proxyPortModel->mapToSource(curPort);
|
||||
if (!curPort.isValid())
|
||||
{
|
||||
qDebug("%s: curPort is invalid", __FUNCTION__);
|
||||
@ -395,6 +468,8 @@ void PortsWindow::on_pbApply_clicked()
|
||||
}
|
||||
|
||||
curPortGroup = plm->getPortModel()->parent(curPort);
|
||||
if (proxyPortModel)
|
||||
curPortGroup = proxyPortModel->mapToSource(curPortGroup);
|
||||
if (!curPortGroup.isValid())
|
||||
{
|
||||
qDebug("%s: curPortGroup is invalid", __FUNCTION__);
|
||||
@ -447,6 +522,9 @@ void PortsWindow::on_actionDelete_Port_Group_triggered()
|
||||
{
|
||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (current.isValid())
|
||||
plm->removePortGroup(plm->portGroup(current));
|
||||
}
|
||||
@ -455,6 +533,9 @@ void PortsWindow::on_actionConnect_Port_Group_triggered()
|
||||
{
|
||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (current.isValid())
|
||||
plm->portGroup(current).connectToHost();
|
||||
}
|
||||
@ -463,6 +544,9 @@ void PortsWindow::on_actionDisconnect_Port_Group_triggered()
|
||||
{
|
||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (current.isValid())
|
||||
plm->portGroup(current).disconnectFromHost();
|
||||
}
|
||||
@ -471,6 +555,9 @@ void PortsWindow::on_actionExclusive_Control_triggered(bool checked)
|
||||
{
|
||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (plm->isPort(current))
|
||||
{
|
||||
OstProto::Port config;
|
||||
@ -484,6 +571,9 @@ void PortsWindow::on_actionPort_Configuration_triggered()
|
||||
{
|
||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (!plm->isPort(current))
|
||||
return;
|
||||
|
||||
@ -533,8 +623,12 @@ void PortsWindow::on_actionDuplicate_Stream_triggered()
|
||||
{
|
||||
QItemSelectionModel* model = tvStreamList->selectionModel();
|
||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||
|
||||
qDebug("Duplicate Stream Action");
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
if (model->hasSelection())
|
||||
{
|
||||
bool isOk;
|
||||
@ -584,6 +678,9 @@ void PortsWindow::on_actionOpen_Streams_triggered()
|
||||
bool append = true;
|
||||
bool ret;
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
Q_ASSERT(plm->isPort(current));
|
||||
|
||||
fileName = QFileDialog::getOpenFileName(this, tr("Open Streams"), dirName);
|
||||
@ -645,6 +742,9 @@ void PortsWindow::on_actionSave_Streams_triggered()
|
||||
QString errorStr;
|
||||
QFileDialog::Options options;
|
||||
|
||||
if (proxyPortModel)
|
||||
current = proxyPortModel->mapToSource(current);
|
||||
|
||||
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType
|
||||
// which we need.On some Linux distros the native dialog can't
|
||||
// distinguish between Ostinato(*) and PCAP(*)
|
||||
|
@ -32,6 +32,7 @@ LOW
|
||||
*/
|
||||
|
||||
class QAbstractItemDelegate;
|
||||
class QSortFilterProxyModel;
|
||||
|
||||
class PortsWindow : public QWidget, private Ui::PortsWindow
|
||||
{
|
||||
@ -47,17 +48,21 @@ public:
|
||||
private:
|
||||
QString lastNewPortGroup;
|
||||
QAbstractItemDelegate *delegate;
|
||||
QSortFilterProxyModel *proxyPortModel;
|
||||
|
||||
public slots:
|
||||
void showMyReservedPortsOnly(bool enabled);
|
||||
|
||||
private slots:
|
||||
void updatePortViewActions(const QModelIndex& current);
|
||||
void updatePortViewActions(const QModelIndex& currentIndex);
|
||||
void updateStreamViewActions();
|
||||
|
||||
void on_averagePacketsPerSec_editingFinished();
|
||||
void on_averageBitsPerSec_editingFinished();
|
||||
void updatePortRates();
|
||||
void on_tvStreamList_activated(const QModelIndex & index);
|
||||
void when_portView_currentChanged(const QModelIndex& current,
|
||||
const QModelIndex& previous);
|
||||
void when_portView_currentChanged(const QModelIndex& currentIndex,
|
||||
const QModelIndex& previousIndex);
|
||||
void when_portModel_dataChanged(const QModelIndex& topLeft,
|
||||
const QModelIndex& bottomRight);
|
||||
void when_portModel_reset();
|
||||
|
Loading…
Reference in New Issue
Block a user