Invoking Port Filter Dialog will now always show selected list in the same order as in the port stats window before invocation

This commit is contained in:
Srivats P. 2015-01-09 20:48:58 +05:30
parent 37711fdd5c
commit e2a4431418
3 changed files with 24 additions and 14 deletions

View File

@ -24,7 +24,8 @@ PortStatsFilterDialog::PortStatsFilterDialog(QWidget *parent)
{
setupUi(this);
mUnselected.setSortRole(PositionRole);
mUnselected.setSortRole(kLogicalIndex);
mSelected.setSortRole(kVisualIndex);
lvUnselected->setModel(&mUnselected);
lvSelected->setModel(&mSelected);
@ -49,7 +50,8 @@ QList<uint> PortStatsFilterDialog::getItemList(bool* ok,
QStandardItem *item;
item = new QStandardItem(model->headerData(i, orientation).toString());
item->setData(i, PositionRole);
item->setData(i, kLogicalIndex);
item->setData(initial.indexOf(i), kVisualIndex);
item->setFlags(Qt::ItemIsSelectable
| Qt::ItemIsDragEnabled
//| Qt::ItemIsDropEnabled
@ -60,6 +62,7 @@ QList<uint> PortStatsFilterDialog::getItemList(bool* ok,
else
mUnselected.appendRow(item);
}
mSelected.sort(0);
// No need to sort right now 'coz we have inserted items in order
@ -70,7 +73,7 @@ QList<uint> PortStatsFilterDialog::getItemList(bool* ok,
{
QModelIndex index = mSelected.index(i, 0, QModelIndex());
QStandardItem *item = mSelected.itemFromIndex(index);
ret.append(item->data(PositionRole).toInt());
ret.append(item->data(kLogicalIndex).toInt());
}
*ok = true;
}

View File

@ -38,7 +38,8 @@ public:
private:
enum ItemRole {
PositionRole = Qt::UserRole + 1
kLogicalIndex = Qt::UserRole + 1,
kVisualIndex
};
QStandardItemModel mUnselected;
QStandardItemModel mSelected;

View File

@ -158,23 +158,29 @@ void PortStatsWindow::on_tbFilter_clicked()
QList<uint> currentColumns, newColumns;
PortStatsFilterDialog dialog;
for(int i = 0; i < model->columnCount(); i++)
if (!tvPortStats->isColumnHidden(i))
currentColumns.append(i);
// create the input list for the filter dialog -
// list of logical-indexes ordered by their current visual indexes
for(int vi = 0; vi < model->columnCount(); vi++) {
int li = tvPortStats->horizontalHeader()->logicalIndex(vi);
if (!tvPortStats->isColumnHidden(li)) {
currentColumns.append(li);
}
}
// return list from the filter dialog -
// list of logical-indexes ordered by their new visual indexes
newColumns = dialog.getItemList(&ok, model, Qt::Horizontal, currentColumns);
if (ok)
{
QHeaderView *hv = tvPortStats->horizontalHeader();
// hide/show sections first ...
for(int i = 0; i < model->columnCount(); i++)
tvPortStats->setColumnHidden(i, !newColumns.contains(i));
for(int li = 0; li < model->columnCount(); li++)
tvPortStats->setColumnHidden(li, !newColumns.contains(li));
// ... then for the 'shown' columns, set the visual index
for(int i = 0; i < newColumns.size(); i++)
{
tvPortStats->horizontalHeader()->moveSection(tvPortStats->
horizontalHeader()->visualIndex(newColumns.at(i)), i);
}
for(int vi = 0; vi < newColumns.size(); vi++)
hv->moveSection(hv->visualIndex(newColumns.at(vi)), vi);
}
}