• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
  • tm
qaview.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2011 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 
25 #include "qaview.h"
26 #include "qamodel.h"
27 #include "project.h"
28 
29 #include <KLocale>
30 #include <QDomDocument>
31 #include <QFile>
32 #include <QAction>
33 
34 
35 QaView::QaView(QWidget* parent)
36  : QDockWidget ( i18nc("@title:window","Quality Assurance"), parent)
37  , m_browser(new QTreeView(this))
38 {
39  if (!QaModel::isInstantiated())
40  QaModel::instance()->loadRules(Project::instance()->qaPath());
41  m_qaModel=QaModel::instance();
42 
43  setWidget(m_browser);
44  m_browser->setModel(m_qaModel);
45  m_browser->setRootIsDecorated(false);
46  m_browser->setContextMenuPolicy(Qt::ActionsContextMenu);
47 
48  QAction* action=new QAction(i18nc("@action:inmenu", "Add"), m_browser);
49  connect(action, SIGNAL(triggered()), this, SLOT(addRule()));
50  m_browser->addAction(action);
51 
52  action=new QAction(i18nc("@action:inmenu", "Remove"), m_browser);
53  connect(action, SIGNAL(triggered()), this, SLOT(removeRule()));
54  m_browser->addAction(action);
55 
56  m_browser->setAlternatingRowColors(true);
57 
58  connect(m_qaModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(rulesChanged()));
59 }
60 
61 QaView::~QaView()
62 {
63 }
64 
65 bool QaView::loadRules(QString filename)
66 {
67  if (filename.isEmpty())
68  filename=Project::instance()->qaPath();
69 
70  bool ok=m_qaModel->loadRules(filename);
71  if (ok)
72  m_filename=filename;
73  return ok;
74 }
75 
76 bool QaView::saveRules(QString filename)
77 {
78  return m_qaModel->saveRules(filename.isEmpty()?m_filename:filename);
79 }
80 
81 QVector< Rule > QaView::rules() const
82 {
83  return m_qaModel->toVector();
84 }
85 
86 
87 void QaView::addRule()
88 {
89  QModelIndex newRule=m_qaModel->appendRow();
90  m_browser->selectionModel()->select(newRule, QItemSelectionModel::ClearAndSelect);
91  m_browser->edit(newRule);
92 }
93 
94 void QaView::removeRule()
95 {
96  foreach(const QModelIndex& rowIndex, m_browser->selectionModel()->selectedRows())
97  m_qaModel->removeRow(rowIndex);
98 }
99 
100 int findMatchingRule(const QVector<Rule>& rules, const QString& source, const QString& target,
101  QVector<StartLen>& positions)
102 {
103  for(QVector<Rule>::const_iterator it=rules.constBegin();it!=rules.constEnd();it++)
104  {
105  if (it->sources.first().indexIn(source)!=-1)
106  {
107  if (it->falseFriends.first().indexIn(target)!=-1)
108  {
109  if (positions.size())
110  {
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();
115  }
116  return it-rules.constBegin();
117  }
118  }
119  }
120  return -1;
121 }
QaView::rules
QVector< Rule > rules() const
Definition: qaview.cpp:81
QModelIndex
project.h
QWidget
QAbstractItemView::setAlternatingRowColors
void setAlternatingRowColors(bool enable)
QaView::~QaView
~QaView()
Definition: qaview.cpp:61
Project::qaPath
QString qaPath() const
Definition: project.h:72
QaView::saveRules
bool saveRules(QString filename=QString())
Definition: qaview.cpp:76
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
QDockWidget
QWidget::addAction
void addAction(QAction *action)
QaView::addRule
void addRule()
Definition: qaview.cpp:87
QVector::constEnd
const_iterator constEnd() const
Project::instance
static Project * instance()
Definition: project.cpp:67
QVector::first
T & first()
QaView::loadRules
bool loadRules(QString filename=QString())
Definition: qaview.cpp:65
QaModel::appendRow
QModelIndex appendRow()
Definition: qamodel.cpp:189
QaModel::saveRules
bool saveRules(QString filename=QString())
Definition: qamodel.cpp:170
QaModel::removeRow
void removeRow(const QModelIndex &)
Definition: qamodel.cpp:203
QItemSelectionModel::select
virtual void select(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
QString::isEmpty
bool isEmpty() const
QItemSelectionModel::selectedRows
QModelIndexList selectedRows(int column) const
QaView::removeRule
void removeRule()
Definition: qaview.cpp:94
QString
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
QDockWidget::setWidget
void setWidget(QWidget *widget)
findMatchingRule
int findMatchingRule(const QVector< Rule > &rules, const QString &source, const QString &target, QVector< StartLen > &positions)
Definition: qaview.cpp:100
QVector::constBegin
const_iterator constBegin() const
QVector< Rule >
QTreeView
QaModel::loadRules
bool loadRules(const QString &filename)
Definition: qamodel.cpp:145
QaView::rulesChanged
void rulesChanged()
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
qaview.h
QAction
QAbstractItemView::edit
void edit(const QModelIndex &index)
QaModel::isInstantiated
static bool isInstantiated()
Definition: qamodel.cpp:64
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QVector::size
int size() const
QaView::QaView
QaView(QWidget *)
Definition: qaview.cpp:35
QaModel::instance
static QaModel * instance()
Definition: qamodel.cpp:69
qamodel.h
QaModel::toVector
QVector< Rule > toVector() const
Definition: qamodel.cpp:125
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal