30 #include <QDomDocument>
36 :
QDockWidget ( i18nc(
"@title:window",
"Quality Assurance"), parent)
44 m_browser->setModel(m_qaModel);
45 m_browser->setRootIsDecorated(
false);
46 m_browser->setContextMenuPolicy(Qt::ActionsContextMenu);
48 QAction* action=
new QAction(i18nc(
"@action:inmenu",
"Add"), m_browser);
49 connect(action, SIGNAL(triggered()),
this, SLOT(
addRule()));
50 m_browser->addAction(action);
52 action=
new QAction(i18nc(
"@action:inmenu",
"Remove"), m_browser);
53 connect(action, SIGNAL(triggered()),
this, SLOT(
removeRule()));
54 m_browser->addAction(action);
56 m_browser->setAlternatingRowColors(
true);
58 connect(m_qaModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SIGNAL(
rulesChanged()));
67 if (filename.isEmpty())
78 return m_qaModel->
saveRules(filename.isEmpty()?m_filename:filename);
89 QModelIndex newRule=m_qaModel->
appendRow();
90 m_browser->selectionModel()->select(newRule, QItemSelectionModel::ClearAndSelect);
91 m_browser->edit(newRule);
96 foreach(
const QModelIndex& rowIndex, m_browser->selectionModel()->selectedRows())
100 int findMatchingRule(
const QVector<Rule>& rules,
const QString& source,
const QString& target,
101 QVector<StartLen>& positions)
103 for(QVector<Rule>::const_iterator it=rules.constBegin();it!=rules.constEnd();it++)
105 if (it->sources.first().indexIn(source)!=-1)
107 if (it->falseFriends.first().indexIn(target)!=-1)
109 if (positions.size())
111 positions[0].start=it->sources.first().pos();
112 positions[0].len=it->sources.first().matchedLength();
113 positions[1].start=it->falseFriends.first().pos();
114 positions[1].len=it->falseFriends.first().matchedLength();
116 return it-rules.constBegin();
QVector< Rule > rules() const
bool saveRules(QString filename=QString())
static Project * instance()
bool loadRules(QString filename=QString())
bool saveRules(QString filename=QString())
void removeRow(const QModelIndex &)
int findMatchingRule(const QVector< Rule > &rules, const QString &source, const QString &target, QVector< StartLen > &positions)
bool loadRules(const QString &filename)
static bool isInstantiated()
static QaModel * instance()
QVector< Rule > toVector() const