mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-24 20:27:22 +01:00
* RuleSetView.cpp (RuleSetView::restoreCurrentRowColumn): fixed
bug that caused rule set view to scroll all the way to the top every time user modified any object used in the rules. Fixes #968
This commit is contained in:
parent
70e016e04e
commit
40f3f6e713
@ -1,3 +1,9 @@
|
||||
2009-12-29 vadim <vadim@vk.crocodile.org>
|
||||
|
||||
* RuleSetView.cpp (RuleSetView::restoreCurrentRowColumn): fixed
|
||||
bug that caused rule set view to scroll all the way to the top
|
||||
every time user modified any object used in the rules. Fixes #968
|
||||
|
||||
2009-12-28 vadim <vadim@vk.crocodile.org>
|
||||
|
||||
Ticket #1040 (Another GUI crash in newClusterDialog) closed by a2k
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
#include <QApplication>
|
||||
#include <QUndoStack>
|
||||
#include <QUndoGroup>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@ -93,14 +93,15 @@ bool ProjectPanel::event(QEvent *event)
|
||||
case RELOAD_RULESET_EVENT:
|
||||
registerRuleSetRedrawRequest();
|
||||
// update rule set title as well
|
||||
updateFirewallName();
|
||||
//updateFirewallName();
|
||||
ev->accept();
|
||||
return true;
|
||||
|
||||
case RELOAD_RULESET_IMMEDIATELY_EVENT:
|
||||
reopenFirewall();
|
||||
redrawRuleSets();
|
||||
//reopenFirewall();
|
||||
// update rule set title as well
|
||||
updateFirewallName();
|
||||
//updateFirewallName();
|
||||
ev->accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -342,9 +342,14 @@ QModelIndex RuleSetModel::indexForPosition(int position) const
|
||||
|
||||
QModelIndex RuleSetModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetModel::index(int row, int column, const QModelIndex &parent)";
|
||||
// if (fwbdebug)
|
||||
// qDebug() << "RuleSetModel::index(int row, int column, const QModelIndex &parent)"
|
||||
// << "row=" << row
|
||||
// << "column=" << column;
|
||||
|
||||
if (row < 0 || column < 0)
|
||||
return QModelIndex();
|
||||
|
||||
RuleNode *parentNode = nodeFromIndex(parent);
|
||||
RuleNode *childNode = parentNode->children.value(row);
|
||||
if (!childNode)
|
||||
@ -355,7 +360,6 @@ QModelIndex RuleSetModel::index(int row, int column, const QModelIndex &parent)
|
||||
|
||||
QModelIndex RuleSetModel::index(QString groupName) const
|
||||
{
|
||||
|
||||
if (!groupName.isEmpty())
|
||||
{
|
||||
int row = 0;
|
||||
@ -363,47 +367,43 @@ QModelIndex RuleSetModel::index(QString groupName) const
|
||||
{
|
||||
if (node->type == RuleNode::Group && node->name == groupName)
|
||||
{
|
||||
|
||||
return createIndex(row, 0, node);
|
||||
}
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex RuleSetModel::index(int row, int column, QString groupName) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << " RuleSetModel::index(int row, int column, QString groupName)";
|
||||
|
||||
// if (fwbdebug)
|
||||
// qDebug() << " RuleSetModel::index(int row, int column, QString groupName)";
|
||||
QModelIndex parent = index(groupName);
|
||||
return (parent.isValid())?index(row, column, parent):QModelIndex();
|
||||
return (parent.isValid()) ? index(row, column, parent) : QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex RuleSetModel::index(libfwbuilder::Rule *rule, libfwbuilder::RuleElement *re) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetModel::index(libfwbuilder::Rule *rule, int col)";
|
||||
// if (fwbdebug)
|
||||
// qDebug() << "RuleSetModel::index(libfwbuilder::Rule *rule, int col)";
|
||||
int col = columnForRuleElementType(re->getTypeName().c_str());
|
||||
return index(rule, col);
|
||||
}
|
||||
|
||||
QModelIndex RuleSetModel::index(libfwbuilder::Rule *rule, int col) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetModel::index(libfwbuilder::Rule *rule, int col) " << col;
|
||||
|
||||
// if (fwbdebug)
|
||||
// qDebug() << "RuleSetModel::index(libfwbuilder::Rule *rule, int col) " << col;
|
||||
if (col < 0 || rule == 0) return QModelIndex();
|
||||
QModelIndex parent;
|
||||
QString groupName = QString::fromUtf8(rule->getRuleGroupName().c_str());
|
||||
|
||||
if (!groupName.isEmpty())
|
||||
{
|
||||
QList<RuleNode *> topLevel = root->children;
|
||||
|
||||
int row = 0;
|
||||
foreach (RuleNode * node, topLevel)
|
||||
{
|
||||
|
||||
if (node->type == RuleNode::Group && node->name == groupName)
|
||||
{
|
||||
parent = createIndex(row, 0, node);
|
||||
@ -412,9 +412,7 @@ QModelIndex RuleSetModel::index(libfwbuilder::Rule *rule, int col) const
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
RuleNode *parentNode = nodeFromIndex(parent);
|
||||
|
||||
int row = 0;
|
||||
RuleNode* child = NULL;
|
||||
foreach(RuleNode *node, parentNode->children)
|
||||
@ -426,15 +424,14 @@ QModelIndex RuleSetModel::index(libfwbuilder::Rule *rule, int col) const
|
||||
}
|
||||
row++;
|
||||
}
|
||||
|
||||
if (child == NULL) return QModelIndex();
|
||||
|
||||
return createIndex(row, col, child);
|
||||
}
|
||||
|
||||
int RuleSetModel::columnForRuleElementType(QString typeName) const
|
||||
{
|
||||
//if (fwbdebug) qDebug() << "RuleSetModel::columnForRuleElementType(QString typeName)";
|
||||
// if (fwbdebug)
|
||||
// qDebug() << "RuleSetModel::columnForRuleElementType(QString typeName)";
|
||||
int col = 1;
|
||||
foreach (ColDesc cd, header)
|
||||
{
|
||||
@ -442,13 +439,13 @@ int RuleSetModel::columnForRuleElementType(QString typeName) const
|
||||
break;
|
||||
col++;
|
||||
}
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
int RuleSetModel::columnByType(ColDesc::ColumnType type)
|
||||
{
|
||||
if (fwbdebug) qDebug() << "RuleSetModel::columnByType(ColDesc::ColumnType type)";
|
||||
// if (fwbdebug)
|
||||
// qDebug() << "RuleSetModel::columnByType(ColDesc::ColumnType type)";
|
||||
int col = 1;
|
||||
foreach (ColDesc cd, header)
|
||||
{
|
||||
@ -456,7 +453,6 @@ int RuleSetModel::columnByType(ColDesc::ColumnType type)
|
||||
break;
|
||||
col++;
|
||||
}
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
|
||||
@ -167,7 +167,9 @@ RuleSetView* RuleSetView::getRuleSetViewByType(ProjectPanel *project,
|
||||
void RuleSetView::selectRE(QModelIndex index)
|
||||
{
|
||||
if (fwbdebug)
|
||||
qDebug() << "RuleSetView::selectRE(QModelIndex index)";
|
||||
qDebug() << "RuleSetView::selectRE(QModelIndex index)"
|
||||
<< index;
|
||||
|
||||
if (fwosm->index != index)
|
||||
{
|
||||
fwosm->selectedObject = NULL;
|
||||
@ -2207,23 +2209,28 @@ FWObject* RuleSetView::getSelectedObject()
|
||||
|
||||
void RuleSetView::saveCurrentRowColumn(SelectionMemento &memento)
|
||||
{
|
||||
RuleSetModel* md = ((RuleSetModel*)model());
|
||||
QModelIndex index = fwosm->index;
|
||||
|
||||
memento.column = index.column();
|
||||
memento.row = index.row();
|
||||
RuleNode* node = static_cast<RuleNode *>(index.internalPointer());
|
||||
|
||||
if (node!=NULL && node->parent !=NULL && !node->parent->isRoot())
|
||||
if (index.isValid())
|
||||
{
|
||||
memento.groupName = node->parent->name;
|
||||
memento.column = index.column();
|
||||
memento.rule_id = md->nodeFromIndex(index)->rule->getId();
|
||||
} else
|
||||
{
|
||||
memento.column = -1;
|
||||
memento.rule_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void RuleSetView::restoreCurrentRowColumn(SelectionMemento &memento)
|
||||
{
|
||||
RuleSetModel* md = ((RuleSetModel*)model());
|
||||
QModelIndex index = md->index(memento.row, memento.column, memento.groupName);
|
||||
selectRE(index);
|
||||
if (memento.rule_id != -1)
|
||||
{
|
||||
RuleSetModel* md = ((RuleSetModel*)model());
|
||||
Rule *rule = Rule::cast(project->db()->findInIndex(memento.rule_id));
|
||||
QModelIndex index = md->index(rule, memento.column);
|
||||
selectRE(index);
|
||||
}
|
||||
}
|
||||
|
||||
void RuleSetView::updateCurrentCell()
|
||||
|
||||
@ -58,8 +58,8 @@ class RuleSetModel;
|
||||
class SelectionMemento
|
||||
{
|
||||
public:
|
||||
QString groupName;
|
||||
int row;
|
||||
SelectionMemento() { rule_id = -1; column = -1; }
|
||||
int rule_id;
|
||||
int column;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user