implement feature req. per 2106266: "Save collapse/expand state of groups in policy"

This commit is contained in:
Vadim Kurland
2008-09-23 09:05:53 +00:00
parent c6aa73ff0f
commit f302ad15b3
9 changed files with 308 additions and 202 deletions
+11
View File
@@ -1,3 +1,14 @@
2008-09-23 Vadim Kurland <vadim@vk.crocodile.org>
* RuleSetView.cpp (RuleSetView::saveCollapsedGroups): fixed bug #
2106266: "Save collapse/expand state of groups in policy". The GUI
will remember state of the rule groups (expanded/collapsed)
between sessions. The state is saved in preferences. Groups are
referenced by combination of file name (full path), firewall object
name, ruleset name, group name. Since state is saved in
preferences rather than in the data file, state of the rule groups
is separate for each user.
2008-09-21 Vadim Kurland <vadim@vk.crocodile.org>
* NATCompiler_pix.cpp (mergeNATCmd::processNext): fixed crash in
+21
View File
@@ -730,3 +730,24 @@ void FWBSettings::setVisibleRuleSet(const QString &filename,
FWObjectDatabase::getStringId(ruleset->getId()).c_str() );
}
void FWBSettings::getCollapsedRuleGroups(const QString &filename,
const QString &firewall,
const QString &ruleset,
QStringList &collapsed_groups)
{
QString strl = value(QString(SETTINGS_PATH_PREFIX "/") +
"Window/" + filename + "/" + firewall + "/" +
ruleset + "/CollapsedRuleGroups").toString();
collapsed_groups = strl.split(",");
}
void FWBSettings::setCollapsedRuleGroups(const QString &filename,
const QString &firewall,
const QString &ruleset,
const QStringList &collapsed_groups)
{
setValue(QString(SETTINGS_PATH_PREFIX "/") +
"Window/" + filename + "/" + firewall + "/" + ruleset +
"/CollapsedRuleGroups",
collapsed_groups.join(","));
}
+9 -1
View File
@@ -179,7 +179,15 @@ class FWBSettings : public QSettings {
const QString &lib,
libfwbuilder::FWObject *ruleset);
void getCollapsedRuleGroups(const QString &filename,
const QString &firewall,
const QString &ruleset,
QStringList &collapsed_groups);
void setCollapsedRuleGroups(const QString &filename,
const QString &firewall,
const QString &ruleset,
const QStringList &collapsed_groups);
private:
QFont getFontByType(const char*type);
};
+2
View File
@@ -343,7 +343,9 @@ void ProjectPanel::updateRuleSetViewSelection()
RuleSetView* rv = dynamic_cast<RuleSetView*>(
m_panel->ruleSets->currentWidget());
if (rv!=NULL)
{
rv->repaintSelection();
}
}
void ProjectPanel::updateRuleSetView()
+3
View File
@@ -32,6 +32,7 @@
#include "ProjectPanel.h"
#include "FWBSettings.h"
#include "RCS.h"
#include "RuleSetView.h"
#include <QMdiSubWindow>
#include <QMdiArea>
@@ -235,6 +236,7 @@ void ProjectPanel::loadOpenedRuleSet()
{
m_panel->om->openObject(obj);
openRuleSet(RuleSet::cast(obj));
// getCurrentRuleSetView()->restoreCollapsedGroups();
}
}
}
@@ -249,6 +251,7 @@ void ProjectPanel::saveOpenedRuleSet()
st->setVisibleRuleSet(filename,
visibleRuleSet->getLibrary()->getName().c_str(),
visibleRuleSet);
getCurrentRuleSetView()->saveCollapsedGroups();
}
}
+6 -6
View File
@@ -29,25 +29,25 @@
RuleGroupPanel::RuleGroupPanel(QWidget * parent,
RuleSetView * rsv, int row) : QFrame(parent)
{
this->row= row;
this->row = row;
this->rsv = rsv;
this->setupUi(this);
setContentsMargins (3,3,3,3);
setContentsMargins(3,3,3,3);
showHideRuleGroupButton->hide();
connect(showHideRuleGroupButton, SIGNAL(pressed()),
this,SLOT(showHideRuleGroup()));
}
void RuleGroupPanel::mousePressEvent ( QMouseEvent * event )
void RuleGroupPanel::mousePressEvent( QMouseEvent * event )
{
if (event->buttons () == Qt::RightButton)
if (event->buttons() == Qt::RightButton)
{
rsv->firstSelectedRow = row;
rsv->contextMenu (row,0,event->globalPos ());
rsv->contextMenu(row,0,event->globalPos ());
}
}
void RuleGroupPanel::mouseDoubleClickEvent ( QMouseEvent * event )
void RuleGroupPanel::mouseDoubleClickEvent( QMouseEvent * event )
{
rsv->firstSelectedRow = row ;
rsv->renameGroup();
+248 -188
View File
@@ -44,20 +44,23 @@
#include "../../config.h"
#include "global.h"
#include "utils.h"
#include "FWWindow.h"
#include "RuleSetView.h"
#include "ObjectEditor.h"
#include "platforms.h"
#include "FWObjectDrag.h"
#include "FWObjectClipboard.h"
#include "findDialog.h"
#include "FWBSettings.h"
#include "SimpleTextEditor.h"
#include "SimpleIntEditor.h"
#include "ActionsDialog.h"
#include "FWBSettings.h"
#include "FWObjectClipboard.h"
#include "FWObjectDrag.h"
#include "FWObjectPropertiesFactory.h"
#include "ObjectTreeView.h"
#include "FWWindow.h"
#include "FindObjectWidget.h"
#include "ObjectEditor.h"
#include "ObjectTreeView.h"
#include "ProjectPanel.h"
#include "RuleRowInfo.h"
#include "RuleSetView.h"
#include "SimpleIntEditor.h"
#include "SimpleTextEditor.h"
#include "findDialog.h"
#include "platforms.h"
#include <ui_askrulenumberdialog_q.h>
@@ -68,9 +71,6 @@
#include "fwbuilder/Firewall.h"
#include "fwbuilder/Resources.h"
#include "fwbuilder/Policy.h"
#include "fwbuilder/InterfacePolicy.h"
#include "fwbuilder/NAT.h"
#include "fwbuilder/Routing.h"
#include "fwbuilder/RuleElement.h"
@@ -96,23 +96,23 @@
#include <qpushbutton.h>
#include <qlabel.h>
#include <qinputdialog.h>
#include "ProjectPanel.h"
#include "RuleRowInfo.h"
#include "RuleGroupPanel.h"
#include <QMdiSubWindow>
#include <QMdiArea>
using namespace libfwbuilder;
using namespace std;
#define DEBUG_RULE_GROUPS 1
//#define DRAW_RULE_GROUP_FRAME 1
int QMAX(int a, int b)
{
return (a>b)?a:b;
return(a>b)?a:b;
}
int QMIN(int a, int b)
{
return (a<b)?a:b;
return(a<b)?a:b;
}
@@ -126,31 +126,31 @@ RuleTableModel::RuleTableModel(const int rows, const int columns,
RuleTableModel::~RuleTableModel() {};
int RuleTableModel::rowCount ( const QModelIndex & ) const
int RuleTableModel::rowCount( const QModelIndex & ) const
{
return m_rowCount;
}
int RuleTableModel::columnCount ( const QModelIndex & ) const
int RuleTableModel::columnCount( const QModelIndex & ) const
{
return m_columnCount;
}
void RuleTableModel::setColumnCount ( const int &value )
void RuleTableModel::setColumnCount( const int &value )
{
m_columnCount = value;
reset();
//need to reset model for RuleSetView::init (one i)
//need to reset model for RuleSetView::init(one i)
}
void RuleTableModel::setRowCount ( const int &value )
void RuleTableModel::setRowCount( const int &value )
{
m_rowCount = value;
reset();
//need to reset model for RuleSetView::iinit (two is)
//need to reset model for RuleSetView::iinit(two is)
}
QVariant RuleTableModel::data ( const QModelIndex &, int /*role*/) const
QVariant RuleTableModel::data( const QModelIndex &, int /*role*/) const
{
return QVariant();
}
@@ -177,7 +177,7 @@ QVariant RuleTableModel::headerData(int section,
{
if (rule==NULL)
{
return QString ("");
return QString("");
}
int counter =0;
for (int i = section; i>=0; i--)
@@ -210,7 +210,7 @@ QVariant RuleTableModel::headerData(int section,
return QAbstractTableModel::headerData(section, orientation, role );
}
bool RuleTableModel::setHeader ( QStringList qsl )
bool RuleTableModel::setHeader( QStringList qsl )
{
header = qsl;
m_columnCount = qsl.size();
@@ -265,7 +265,7 @@ void RuleTableModel::swapRows( const int row1, const int row2 )
//just swap rules' sizes and then update() the table by yourself
}
void RuleTableModel::removeRows ( const int row1, const int row2 )
void RuleTableModel::removeRows( const int row1, const int row2 )
{
//(row2-row1)+1 rows deleted
m_rowCount -= (row2-row1)+1;
@@ -330,31 +330,35 @@ void RuleDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &,
const QModelIndex &index) const
{
if (ruleSetView->ruleIndex[index.row()]==NULL && index.column()==1)
QRect size = cellGeometry(index.row(), index.column());
if (fwbdebug)
qDebug("RuleDelegate::paint row=%d col=%d size=%dx%dx%dx%d",
index.row(), index.column(),
size.left(), size.top(), size.width(), size.height());
if (ruleSetView->ruleIndex[index.row()]==NULL)
{
QRect size = cellGeometry(index.row(), index.column());
int w = 0 ;
for (int i = 1; i < ruleSetView->ruleModel->columnCount(index); i++)
if (index.column() > 1) return;
if (index.column() == 1)
{
w += ruleSetView->getColumnWidth(i);
}
size.setWidth (w);
size.setHeight (ruleSetView->getRowHeight(index.row()));
ruleSetView->paintCell( painter,
index.row(),
index.column(),
size,
ruleSetView->itemSelectionRange.contains(index),
QPalette() );
// Correct geometry rect for the rule group head row
// Basically, we expand one cell for the whole row
int w = 0 ;
for (int i = 1; i < ruleSetView->ruleModel->columnCount(index); i++)
w += ruleSetView->getColumnWidth(i);
return ;
size.setWidth(w);
if (fwbdebug)
qDebug("RuleDelegate::paint rule group head width=%d", w);
}
}
ruleSetView->paintCell( painter,
index.row(),
index.column(),
cellGeometry(index.row(), index.column()),
size,
ruleSetView->itemSelectionRange.contains(index),
QPalette() );
}
@@ -534,11 +538,11 @@ RuleSetView::RuleSetView(ProjectPanel *project, int , int c, QWidget *parent):
LoadPixmap(icn_file, pm);
negIcon = QIcon(pm);
connect( horizontalHeader(), SIGNAL( sectionResized ( int, int, int ) ),
this, SLOT( horzSectionResized ( int, int, int ) ) );
connect( horizontalHeader(), SIGNAL( sectionResized( int, int, int ) ),
this, SLOT( horzSectionResized( int, int, int ) ) );
connect( verticalHeader(), SIGNAL( sectionResized ( int, int, int ) ),
this, SLOT( vertSectionResized ( int, int, int ) ) );
connect( verticalHeader(), SIGNAL( sectionResized( int, int, int ) ),
this, SLOT( vertSectionResized( int, int, int ) ) );
connect( this, SIGNAL( customContextMenuRequested(const QPoint&) ),
this, SLOT( contextMenuRequested(const QPoint&) ) );
@@ -665,7 +669,7 @@ bool RuleSetView::event( QEvent * event )
return QTableView::event(event);
}
void RuleSetView::contextMenuRequested ( const QPoint &p )
void RuleSetView::contextMenuRequested( const QPoint &p )
{
contextMenu(rowAt(p.y()), columnAt(p.x()), viewport()->mapToGlobal(p));
}
@@ -822,7 +826,7 @@ void RuleSetView::fixRulePosition(Rule *rule, FWObject *parent, int pos)
rule->setPosition(pos);
}
RuleRowInfo* RuleSetView::getRuleRowInfoByGroupName (QString name)
RuleRowInfo* RuleSetView::getRuleRowInfoByGroupName(QString name)
{
if (name=="") name = "New Group";
for (int i = 0 ; i < rowsInfo.size(); i++)
@@ -832,7 +836,7 @@ RuleRowInfo* RuleSetView::getRuleRowInfoByGroupName (QString name)
return NULL;
}
int RuleSetView::getRuleRowInfoIndexByGroupName (QString name)
int RuleSetView::getRuleRowInfoIndexByGroupName(QString name)
{
for (int i = 0 ; i < rowsInfo.size(); i++)
{
@@ -918,7 +922,7 @@ void RuleSetView::init()
{
if (col==0)
{
horizontalHeader()->setResizeMode (0, QHeaderView::Fixed);
horizontalHeader()->setResizeMode(0, QHeaderView::Fixed);
horizontalHeader()->resizeSection(0, 20);
colW[0]=20;
continue ;
@@ -934,9 +938,11 @@ void RuleSetView::init()
debugPrintRows();
}
#endif
//updateContents();
updateGroups();
QTimer::singleShot(0, this, SLOT(restoreCollapsedGroups()));
#if DEBUG_RULE_GROUPS
if (fwbdebug)
{
@@ -985,44 +991,6 @@ void RuleSetView::debugPrintRows()
qDebug(" ");
}
void RuleSetView::addRuleGroupPanel(int row)
{
RuleRowInfo * rri = rowsInfo[row];
if (rri==NULL)
return ;
setSpan(row, 1, 0, ruleModel->columnCount(this->model()->index(row,0))-1);
// rri->index = &model()->index(row,0);
if (rri->isFirstRow)
{
bool hide = isRowHidden(row+1);
RuleGroupPanel * grouppanel = new RuleGroupPanel(NULL,this,row);
int count = rulesInGroup[ rri->groupName ];
QString groupTitle = rri->groupName;
groupTitle += " (" ;
groupTitle +=QString().setNum(count);
groupTitle += " rules)";
grouppanel->ruleGroupName->setText(groupTitle);
rri->collapsedGroup = hide;
if (!hide)
{
grouppanel->showHideRuleGroupButton->setCheckState(Qt::Unchecked);
grouppanel->showHideRuleGroupButton->setText ("Collapse Group");
}
else
{
grouppanel->showHideRuleGroupButton->setCheckState(Qt::Checked);
grouppanel->showHideRuleGroupButton->setText ("Expand Group");
}
setIndexWidget (model()->index(row,1),grouppanel);
}
else
{
this->hideRow(row);
}
}
void RuleSetView::refreshGroups()
{
}
@@ -1038,8 +1006,16 @@ void RuleSetView::updateGroups()
reset();
QStringList collapsed_groups;
QString filename = m_project->getRCS()->getFileName();
st->getCollapsedRuleGroups(
filename,
getFirewall()->getName().c_str(),
ruleset->getName().c_str(),
collapsed_groups);
setColumnWidth(0, 20);
horizontalHeader()->setResizeMode (0, QHeaderView::Fixed);
horizontalHeader()->setResizeMode(0, QHeaderView::Fixed);
horizontalHeader()->resizeSection(0, 20);
QMap <QString, QString> groupColors ;
@@ -1093,8 +1069,8 @@ void RuleSetView::updateGroups()
int count = rulesInGroup[groupName];
count++;
rulesInGroup[groupName]=count ;
}
rulesInGroup[groupName] = count ;
}
}
if (fwbdebug) qDebug("RuleSetView::updateGroups checkpoint 2");
@@ -1122,6 +1098,8 @@ void RuleSetView::updateGroups()
}
}
RuleRowInfo *rri;
if (group!=memberRow)
{
ruleModel->insertRow(i);
@@ -1131,24 +1109,22 @@ void RuleSetView::updateGroups()
ruleIndex[i] = NULL ;
beginGroup = true ;
memberRow = group;
RuleRowInfo *rri = new RuleRowInfo(memberRow, true, false);
rri = new RuleRowInfo(memberRow, true, false);
rri->color = groupColors[memberRow];
rowsInfo.insert(i, rri);
addRuleGroupPanel(i);
}
else
{
insertRuleIndex(i);
ruleIndex[i] = NULL ;
beginGroup = false ;
rowsInfo.insert (i, new RuleRowInfo(memberRow, false, false));
rri = new RuleRowInfo(memberRow, false, false);
rowsInfo.insert (i, rri);
memberRow = "";
addRuleGroupPanel(i);
i--;
}
i++;
}
}
if (group!="")
@@ -1156,39 +1132,43 @@ void RuleSetView::updateGroups()
ruleModel->insertRow(rowsInfo.size());
ruleIndex[rowsInfo.size()] = NULL ;
beginGroup = false ;
rowsInfo.push_back (new RuleRowInfo(memberRow,false,false));
rowsInfo.push_back(new RuleRowInfo(memberRow,false,false));
memberRow = group;
addRuleGroupPanel(rowsInfo.size()-1);
}
for (int row = 0 ; row < rowsInfo.size(); row++)
{
RuleRowInfo *rri = rowsInfo[row];
if (rri)
{
rri->collapsedGroup =
bool(collapsed_groups.count(rri->groupName) > 0);
if (!rri->isFirstRow) hideRow(row);
}
}
if (fwbdebug) qDebug("RuleSetView::updateGroups done");
}
void RuleSetView::deleteRuleGroupPanel (int row)
{
setIndexWidget (model()->index(row,0),NULL);
}
QSize RuleSetView::getPMSize()
{
if (!st->getShowIconsInRules()){
pixmap_h = 0;
pixmap_w = 0;
if (!st->getShowIconsInRules())
{
pixmap_h = 0;
pixmap_w = 0;
return QSize();
}
QString icn="icon-ref";
if (FWBSettings::SIZE16X16 == st->getIconsInRulesSize())
icn="icon-tree";
// return QPixmap::fromMimeSource(
// Resources::global_res->getObjResourceStr(obj, icn).c_str() );
if (FWBSettings::SIZE16X16 == st->getIconsInRulesSize()) icn="icon-tree";
QString icn_file = QString(":/Icons/AddressTable/")+icn;
QPixmap pm;
LoadPixmap(icn_file, pm);
pixmap_h = pm.height();
pixmap_w = pm.width();
pixmap_h = pm.height();
pixmap_w = pm.width();
return pm.size();
}
@@ -1248,7 +1228,7 @@ void RuleSetView::iinit()
supports_time=
Resources::getTargetCapabilityBool(f->getStr("platform"),
"supports_time");
} catch (FWException &ex) { }
} catch(FWException &ex) { }
}
update();
@@ -1528,7 +1508,7 @@ void RuleSetView::paintCell(QPainter *pntr,
if (ruleIndex.count(row)==0) return;
QString rclr;
QString rclr;
Rule *rule = ruleIndex[row];
int groupEnd = getDownNullRuleIndex(row);
@@ -1646,6 +1626,29 @@ void RuleSetView::paintCell(QPainter *pntr,
{
p.drawLine( 1, cr.height()-3, cr.width() , cr.height()-3);
}
RuleRowInfo *rri = rowsInfo[row];
if (rri && rri->isFirstRow)
{
int count = rulesInGroup[ rri->groupName ];
QString groupTitle = rri->groupName;
groupTitle += " (" ;
groupTitle += QString().setNum(count);
groupTitle += " rules)";
QRect r = ruleDelegate->cellRect(row,col);
int x = r.left() + RuleElementSpacing/2;
int y = r.top();
QRect br = p.boundingRect(QRect(x, y, 1000, 1000),
Qt::AlignLeft|Qt::AlignVCenter,
groupTitle);
p.drawText( x, y + RuleElementSpacing/2,
br.width(),
br.height(),
Qt::AlignLeft|Qt::AlignTop,
groupTitle);
}
p.end();
@@ -1968,15 +1971,20 @@ void RuleSetView::drawComment(QPainter &p, int row, int col, const QRect &cr)
* Rule here */
Rule *rule = ruleIndex[row];
if (rule==NULL) return;
QString comm = QString::fromUtf8(rule->getComment().c_str());
if (fwbdebug) qDebug("drawComment: row=%d col=%d comm=%s cr=%dx%dx%dx%d",
row, col, comm.toAscii().constData(),
cr.left(), cr.top(), cr.width(), cr.height());
QRect r = ruleDelegate->cellRect(row,col);
int x = r.left() + RuleElementSpacing/2;
int y = r.top();
QString comm = QString::fromUtf8(rule->getComment().c_str());
QRect br=p.boundingRect(QRect(x, y, 1000, 1000),
Qt::AlignLeft|Qt::AlignVCenter,
comm);
QRect br = p.boundingRect(QRect(x, y, 1000, 1000),
Qt::AlignLeft|Qt::AlignVCenter,
comm);
if (st->getClipComment() && text_h > 0)
{
QStringList strs = comm.split('\n');
@@ -2444,42 +2452,31 @@ void RuleSetView::mouseMoveEvent( QMouseEvent* ev )
void RuleSetView::mousePressEvent( QMouseEvent* ev )
{
int row=rowAt(ev->y());
int col=columnAt(ev->x());
if (row==-1)
return ;
if (col==0)
int row = rowAt(ev->y());
int col = columnAt(ev->x());
if (row == -1) return ;
if (col == 0)
{
if (row<rowsInfo.size()&&row>=0)
if (row < rowsInfo.size() && row >= 0)
{
if (rowsInfo[row]!=NULL)
{
QWidget * wgt = indexWidget(model()->index(row,1));
RuleGroupPanel * rfp = dynamic_cast<RuleGroupPanel *>(wgt);
if (rfp!=NULL)
{
showHideRuleGroup(rfp);
}
}
}
if (rowsInfo[row] != NULL) showHideRuleGroup(row);
}
}
FWObject *obj=getObj(row,col,ev->y()+verticalOffset());
bool needUpdate= (row==currentRow() && col==currentColumn() && selectedObject!=obj);
FWObject *obj = getObj(row,col,ev->y()+verticalOffset());
if (fwbdebug)
qDebug("RuleSetView::contentsMousePressEvent obj=%s row=%d col=%d needUpdate=%d",
(obj)?obj->getName().c_str():"NULL",row,col,needUpdate);
qDebug("RuleSetView::contentsMousePressEvent obj=%s row=%d col=%d",
(obj)?obj->getName().c_str():"NULL", row, col);
if (fwbdebug)
qDebug("RuleSetView::contentsMousePressEvent 1 currentRow=%d currentColumn=%d",
qDebug("RuleSetView::contentsMousePressEvent 1 "
"currentRow=%d currentColumn=%d",
currentRow(),currentColumn());
QTableView::mousePressEvent(ev);
if ((row > 0) && (col > 0))
mw->selectRules();
if ((row > 0) && (col > 0)) mw->selectRules();
else
{
mw->unselectRules();
@@ -2488,12 +2485,16 @@ void RuleSetView::mousePressEvent( QMouseEvent* ev )
}
if (fwbdebug)
qDebug("RuleSetView::contentsMousePressEvent 2 currentRow=%d currentColumn=%d",
qDebug("RuleSetView::contentsMousePressEvent 2 "
"currentRow=%d currentColumn=%d",
currentRow(),currentColumn());
startingDrag = (row==currentRow() && col==currentColumn() && selectedObject==obj);
startingDrag = (row==currentRow() &&
col==currentColumn() &&
selectedObject==obj);
changeCurrentCell(row, col, true); //forget old selection by setting View's current cell
//forget old selection by setting View's current cell
changeCurrentCell(row, col, true);
setSelectedObject(obj);
//verticalHeader()->update();
@@ -2694,15 +2695,12 @@ void RuleSetView::addToGroupAbove ()
Rule *r = ruleIndex[row+i];
if (r)
{
r->setRuleGroupName (ru->groupName.toAscii().data());
r->setRuleGroupName(ru->groupName.toAscii().data());
//ruleIndex[row+i] =r ;
if (ru->collapsedGroup)
showHideRuleGroup(
dynamic_cast<RuleGroupPanel*>(
indexWidget(model()->index(top,1))));
if (ru->collapsedGroup) showHideRuleGroup(row);
}
}
QTimer::singleShot( 0, m_project, SLOT(reopenFirewall()) );
QTimer::singleShot(0, m_project, SLOT(reopenFirewall()));
// updateGroups();
}
@@ -2724,10 +2722,7 @@ void RuleSetView::addToGroupBelow()
{
r->setRuleGroupName (ru->groupName.toAscii().data());
//ruleIndex[row+i] =r ;
if (ru->collapsedGroup)
showHideRuleGroup(
dynamic_cast<RuleGroupPanel*>(
indexWidget(model()->index(bottom,1))));
if (ru->collapsedGroup) showHideRuleGroup(row);
}
}
QTimer::singleShot( 0, m_project, SLOT(reopenFirewall()) );
@@ -2735,41 +2730,58 @@ void RuleSetView::addToGroupBelow()
// updateGroups();
}
void RuleSetView::showHideRuleGroup(RuleGroupPanel * rgp)
void RuleSetView::showHideRuleGroup(int row)
{
if (rgp==NULL)
return ;
QString act = rgp->showHideRuleGroupButton->text();
int row = rgp->row ;
RuleRowInfo * rrf = rowsInfo[row];
int bottom = getDownNullRuleIndex(row+1);
int count = bottom-row-1;
if (act=="Collapse Group")
{
for (int i = row+1; i< row+1+count;i++)
{
hideRow(i);
}
rrf->collapsedGroup=true;
//rgp->showHideRuleGroupButton->setText("Expand Group");
}
if (fwbdebug) qDebug("RuleSetView::showHideRuleGroup row=%d", row);
if (act=="Expand Group")
RuleRowInfo *rri = rowsInfo[row];
if (rri)
{
for (int i = row+1; i< row+1+count;i++)
{
showRow(i);
adjustRow(i);
//setRowHeight(i,rowHeights[i]);
dataChanged (model()->index(i,0),model()->index(i,8));
}
rrf->collapsedGroup=false;
//rgp->showHideRuleGroupButton->setText("Collapse Group");
if (rri->collapsedGroup) expandRuleGroup(row);
else collapseRuleGroup(row);
}
// refreshGroups();
updateGroups();
}
void RuleSetView::collapseRuleGroup(int row)
{
RuleRowInfo *rrf = rowsInfo[row];
int bottom = getDownNullRuleIndex(row+1);
if (fwbdebug) qDebug("RuleSetView::collapseRuleGroup row=%d bottom=%d",
row, bottom);
rrf->collapsedGroup = true;
for (int ridx = bottom-1; ridx > row; ridx--)
{
hideRow(ridx);
}
dataChanged(model()->index(row, 0),
model()->index(model()->rowCount(), model()->columnCount()));
saveCollapsedGroups();
}
void RuleSetView::expandRuleGroup(int row)
{
RuleRowInfo *rrf = rowsInfo[row];
int bottom = getDownNullRuleIndex(row+1);
if (fwbdebug) qDebug("RuleSetView::expandRuleGroup row=%d bottom=%d",
row, bottom);
rrf->collapsedGroup = false;
for (int i = row+1; i< bottom; i++)
{
showRow(i);
adjustRow(i);
}
dataChanged(model()->index(row, 0),
model()->index(model()->rowCount(), model()->columnCount()));
saveCollapsedGroups();
}
void RuleSetView::removeFromGroup()
{
int row = firstSelectedRow;
@@ -4651,6 +4663,54 @@ void RuleSetView::restoreSelection(bool same_widget)
openObjectInTree(selectedObject);
}
void RuleSetView::saveCollapsedGroups()
{
QStringList collapsed_groups;
QString filename = m_project->getRCS()->getFileName();
for (int i =0 ; i < rowsInfo.size(); i++)
{
RuleRowInfo *rri = rowsInfo[i];
if (rri && rri->isFirstRow && rri->collapsedGroup)
collapsed_groups.push_back(rri->groupName);
}
st->setCollapsedRuleGroups(
filename,
getFirewall()->getName().c_str(),
ruleset->getName().c_str(),
collapsed_groups);
}
void RuleSetView::restoreCollapsedGroups()
{
freezeRowSizing();
QStringList collapsed_groups;
QString filename = m_project->getRCS()->getFileName();
st->getCollapsedRuleGroups(
filename,
getFirewall()->getName().c_str(),
ruleset->getName().c_str(),
collapsed_groups);
for (int row = 0 ; row < rowsInfo.size(); row++)
{
RuleRowInfo *rri = rowsInfo[row];
if (rri &&
rri->isFirstRow &&
collapsed_groups.count(rri->groupName) >0)
{
collapseRuleGroup(row);
}
}
mw->unselectRules();
setCurrentIndex(QModelIndex());
changeCurrentCell(0, 0, true);
unfreezeRowSizing();
}
void RuleSetView::updateAll()
{
if (fwbdebug) qDebug("RuleSetView::updateAll()");
+8 -4
View File
@@ -66,7 +66,7 @@ namespace libfwbuilder {
class RuleRowInfo;
class RuleSetView;
class ProjectPanel;
class RuleGroupPanel;
/**
* this class is used to intercept mouse clicks on the vertical header
* of the table so we could open a context menu
@@ -166,7 +166,7 @@ public slots:
void addToGroupBelow();
void removeFromGroup();
void insertRuleAboveFirstGroup();
void showHideRuleGroup (RuleGroupPanel * rgp);
void showHideRuleGroup(int row);
void editSelected();
void copySelectedObject();
@@ -218,6 +218,8 @@ public slots:
void pasteRuleAbove();
void pasteRuleBelow();
void saveCollapsedGroups();
void restoreCollapsedGroups();
void enableRule();
void disableRule();
@@ -269,6 +271,9 @@ public:
void resetRuleModel();
void createRuleModel();
void collapseRuleGroup(int row);
void expandRuleGroup(int row);
//these functions are added in the porting process
//they are needed to work with stored cell sizes (columnWidths,
@@ -356,8 +361,6 @@ public:
void iinit();
QString settingsKey();
void addRuleGroupPanel (int row);
void deleteRuleGroupPanel (int row);
void insertRuleIndex (int idx);
void removeRuleIndex (int idx);
void updateGroups ();
@@ -473,6 +476,7 @@ public:
REType getColType(int col) const;
int getColByType(REType) const;
private:
ProjectPanel *m_project;
virtual libfwbuilder::RuleElement* getRE(int row, int col ) = 0;
-3
View File
@@ -128,7 +128,6 @@ HEADERS += ../../config.h \
FakeWizard.h \
AskLibForCopyDialog.h \
FWBAboutDialog.h \
RuleGroupPanel.h \
RuleRowInfo.h \
Help.h \
HttpGet.h \
@@ -241,7 +240,6 @@ SOURCES += ProjectPanel.cpp \
FakeWizard.cpp \
AskLibForCopyDialog.cpp \
ObjectListViewItem.cpp \
RuleGroupPanel.cpp \
Help.cpp \
HttpGet.cpp
@@ -317,7 +315,6 @@ FORMS = FWBMainWindow_q.ui \
metriceditorpanel_q.ui \
findwhereusedwidget_q.ui \
confirmdeleteobjectdialog_q.ui\
rulegrouppanel.ui\
projectpanel_q.ui\
asklibforcopydialog_q.ui