Small code clean up in kordf

* use Soprano::Statement as const ref where possible
* order & normalize include statements
parent 8f3deaa3
......@@ -27,8 +27,8 @@
#include "InsertSemanticObjectReferenceAction.h"
#include "KoRdfSemanticItemRegistry.h"
#include "../KoView.h"
#include "../KoDocument.h"
#include <KoView.h>
#include <KoDocument.h>
#include <KoToolManager.h>
#include <KoTextDocument.h>
#include <KoTextRdfCore.h>
......@@ -160,7 +160,7 @@ void KoDocumentRdf::freshenBNodes(QSharedPointer<Soprano::Model> m)
StatementIterator it = m->listStatements();
QList<Statement> allStatements = it.allElements();
RDEBUG << "freshening model.sz:" << allStatements.size();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
Soprano::Node subj = s.subject();
Soprano::Node obj = s.object();
Soprano::Statement news;
......@@ -221,7 +221,7 @@ bool KoDocumentRdf::loadRdf(KoStore *store, const Soprano::Parser *parser, const
Soprano::SerializationRdfXml);
QList<Statement> allStatements = it.allElements();
RDEBUG << "Found " << allStatements.size() << " triples..." << endl;
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
Soprano::Node subj = s.subject();
Soprano::Node pred = s.predicate();
Soprano::Node obj = s.object();
......@@ -365,7 +365,7 @@ bool KoDocumentRdf::saveOasis(KoStore *store, KoXmlWriter *manifestWriter)
bool ok = true;
NodeIterator contextIter = model()->listContexts();
QList<Node> contexts = contextIter.allElements();
foreach (Soprano::Node node, contexts) {
foreach (const Soprano::Node &node, contexts) {
if (!saveRdf(store, manifestWriter, node)) {
ok = false;
}
......@@ -391,12 +391,12 @@ void KoDocumentRdf::updateXmlIdReferences(const QMap<QString, QString> &m)
QMap<QString, QWeakPointer<KoTextInlineRdf> > inlineRdfObjects;
QList<Statement> allStatements = it.allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
RDEBUG << "seeking obj:" << s.object();
QMap<QString, QString>::const_iterator mi = m.find(s.object().toString());
if (mi != m.end()) {
QString oldID = mi.key();
QString newID = mi.value();
const QString &oldID = mi.key();
const QString &newID = mi.value();
removeList << s;
Statement n(s.subject(),
s.predicate(),
......@@ -452,7 +452,7 @@ void KoDocumentRdf::dumpModel(const QString &msg, QSharedPointer<Soprano::Model>
QList<Soprano::Statement> allStatements = m->listStatements().allElements();
RDEBUG << "----- " << msg << " ----- model size:" << allStatements.size();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
RDEBUG << s;
}
}
......@@ -530,9 +530,9 @@ void KoDocumentRdf::expandStatementsReferencingSubject(QSharedPointer<Soprano::M
QList<Statement> addList;
QList<Statement> allStatements = _model->listStatements().allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
QList<Statement> all = model()->listStatements(Node(), Node(), s.subject()).allElements();
foreach (Soprano::Statement e, all) {
foreach (const Soprano::Statement &e, all) {
addList << e;
}
}
......@@ -546,9 +546,9 @@ void KoDocumentRdf::expandStatementsSubjectPointsTo(QSharedPointer<Soprano::Mode
QList<Statement> addList;
QList<Statement> allStatements = _model->listStatements().allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
QList<Statement> all = model()->listStatements(s.object(), Node(), Node()).allElements();
foreach (Soprano::Statement e, all) {
foreach (const Soprano::Statement &e, all) {
RDEBUG << "ADD obj:" << s.object() << " adding:" << e;
addList << e;
}
......@@ -563,7 +563,7 @@ void KoDocumentRdf::expandStatementsSubjectPointsTo(QSharedPointer<Soprano::Mode
QList<Statement> addList;
QList<Statement> all = model()->listStatements(n, Node(), Node()).allElements();
foreach (Soprano::Statement e, all) {
foreach (const Soprano::Statement &e, all) {
RDEBUG << "n:" << n << " adding:" << e;
addList << e;
}
......@@ -583,7 +583,7 @@ void KoDocumentRdf::expandStatementsToIncludeRdfListsRecurse(QSharedPointer<Sopr
addList << all;
all = model()->listStatements(n, rdfRest, Node()).allElements();
addList << all;
foreach (Soprano::Statement s, all) {
foreach (const Soprano::Statement &s, all) {
expandStatementsToIncludeRdfListsRecurse(_model, addList, s.object());
}
}
......@@ -596,7 +596,7 @@ void KoDocumentRdf::expandStatementsToIncludeRdfLists(QSharedPointer<Soprano::Mo
QList<Statement> addList;
QList<Statement> allStatements = model->listStatements().allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
expandStatementsToIncludeRdfListsRecurse(model, addList, s.subject());
}
RDEBUG << "model.sz:" << model->statementCount();
......@@ -611,9 +611,9 @@ void KoDocumentRdf::expandStatementsToIncludeOtherPredicates(QSharedPointer<Sopr
QList<Statement> addList;
QList<Statement> allStatements = _model->listStatements().allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
QList<Statement> all = model()->listStatements(s.subject(), Node(), Node()).allElements();
foreach (Soprano::Statement e, all) {
foreach (const Soprano::Statement &e, all) {
addList << e;
}
}
......@@ -1088,7 +1088,7 @@ QStringList KoDocumentRdf::idrefList() const
}
QList<Statement> allStatements = it.allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
idrefs << s.object().toString();
}
return idrefs;
......
......@@ -18,22 +18,26 @@
*/
#include "KoDocumentRdfEditWidget.h"
#include <ui_KoDocumentRdfEditWidget.h>
#include "KoDocumentRdf.h"
#include "KoRdfSemanticItemRegistry.h"
#include "KoRdfPrefixMapping.h"
#include "../KoDocument.h"
#include "KoSopranoTableModelDelegate.h"
#include "KoSopranoTableModel.h"
#include "KoRdfSemanticTreeWidgetItem.h"
#include "../KoGlobal.h"
// main
#include <KoDocument.h>
#include <KoGlobal.h>
// KDE
#include <kdebug.h>
#include <QComboBox>
#include <QSortFilterProxyModel>
#include <kmenu.h>
#include <kmessagebox.h>
#include <klocale.h>
// Qt
#include <QComboBox>
#include <QSortFilterProxyModel>
static const char SemanticItemClassId[] = "Ko_semanticItemClass";
......@@ -185,23 +189,22 @@ public:
m_ui->m_tripleView->selectRow(row);
}
void selectTriples(QModelIndex mi,
void selectTriples(const QModelIndex &mi,
QItemSelectionModel::SelectionFlags command = QItemSelectionModel::Select) {
m_ui->m_tripleView->selectionModel()->select(mi, command | QItemSelectionModel::Rows);
}
void selectTriples(QModelIndexList ml,
void selectTriples(const QModelIndexList &ml,
QItemSelectionModel::SelectionFlags command = QItemSelectionModel::Select) {
Q_UNUSED(command);
QModelIndex mi;
foreach (mi, ml) {
foreach (const QModelIndex &mi, ml) {
selectTriples(mi);
}
}
QModelIndexList mapFromSource(QModelIndexList mil) const {
QModelIndexList ret;
foreach (QModelIndex idx, mil) {
foreach (const QModelIndex &idx, mil) {
QModelIndex pidx = m_tripleProxyModel->mapFromSource(idx);
ret << pidx;
}
......@@ -220,7 +223,7 @@ public:
QModelIndexList mapToSource(const QModelIndexList proxyList) const {
QModelIndexList ret;
foreach (QModelIndex idx, proxyList) {
foreach (const QModelIndex &idx, proxyList) {
QModelIndex sidx = m_tripleProxyModel->mapToSource(idx);
ret << sidx;
}
......
......@@ -139,7 +139,7 @@ void KoRdfPrefixMapping::load(QSharedPointer<Soprano::Model> model)
Soprano::Node ListHeadSubject = Node::createResourceNode(QUrl(nodePrefix + "list"));
QList<Statement> listNodes = KoTextRdfCore::loadList(model, ListHeadSubject);
//kDebug(30015) << "found count:" << listNodes.size();
foreach (Soprano::Statement s, listNodes) {
foreach (const Soprano::Statement &s, listNodes) {
Soprano::Node dataBNode = s.object();
QString prefix = KoTextRdfCore::getObject(model, dataBNode,
Node::createResourceNode(QUrl(nodePrefix + "prefix"))).toString();
......
......@@ -79,7 +79,7 @@ QStringList KoRdfSemanticItem::xmlIdList() const
Node(),
documentRdf()->manifestRdfNode());
QList<Statement> allStatements = it.allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
QString xmlid = s.object().toString();
ret << xmlid;
}
......@@ -113,7 +113,7 @@ void KoRdfSemanticItem::updateTriple_remove(const Soprano::LiteralValue &toModif
StatementIterator it = m->listStatements(explicitLinkingSubject, pred, Node());
QList<Statement> removeList;
QList<Statement> allStatements = it.allElements();
foreach (Soprano::Statement s, allStatements) {
foreach (const Soprano::Statement &s, allStatements) {
kDebug(30015) << "typeless remove, s:" << s.object().toString();
kDebug(30015) << "typeless remove, tm:" << Node::createLiteralNode(toModify).toString();
......@@ -457,7 +457,7 @@ void KoRdfSemanticItem::loadUserStylesheets(QSharedPointer<Soprano::Model> model
Soprano::Node ListHeadSubject = Node::createResourceNode(QUrl(nodePrefix + "list"));
QList<Statement> listNodes = KoTextRdfCore::loadList(model, ListHeadSubject);
kDebug(30015) << "semanticClass:" << semanticClass << " listNodes.sz:" << listNodes.size();
foreach (Soprano::Statement s, listNodes) {
foreach (const Soprano::Statement &s, listNodes) {
Soprano::Node dataBNode = s.object();
QString uuid = KoTextRdfCore::getObject(model, dataBNode,
......
......@@ -19,11 +19,13 @@
#include "KoRdfSemanticItemViewSite.h"
#include "KoDocumentRdf.h"
#include "KoCanvasBase.h"
#include "KoCanvasResourceManager.h"
#include "KoToolProxy.h"
#include "KoText.h"
#include "KoTextEditor.h"
// main
#include <KoCanvasBase.h>
#include <KoCanvasResourceManager.h>
#include <KoToolProxy.h>
#include <KoText.h>
#include <KoTextEditor.h>
// KDE
#include <kdebug.h>
using namespace Soprano;
......
......@@ -23,9 +23,10 @@
#include "KoRdfSemanticItemRegistry.h"
#include "KoDocumentRdf.h"
#include "KoRdfSemanticTreeWidgetItem.h"
// KDE
#include <kdebug.h>
#include <klocale.h>
// Qt
#include <QSet>
class KoRdfSemanticTreePrivate : public QSharedData
......
......@@ -20,18 +20,18 @@
#include "KoRdfSemanticTreeWidgetItem.h"
#include "KoDocumentRdf.h"
// main
#include <KoCanvasBase.h>
#include <KoToolProxy.h>
#include <KoDocumentResourceManager.h>
#include <KoTextEditor.h>
// KDE
#include <kactionmenu.h>
#include <QVBoxLayout>
#include <kpagedialog.h>
#include <kdebug.h>
#include <klocale.h>
// Qt
#include <QVBoxLayout>
using namespace Soprano;
......
......@@ -18,15 +18,17 @@
*/
#include "KoSemanticStylesheet.h"
#include <QCoreApplication>
#include <kdebug.h>
#include "KoDocumentRdf.h"
#include "../KoDocument.h"
#include "KoChangeTrackerDisabledRAII.h"
// main
#include <KoDocument.h>
#include <KoTextDocument.h>
#include <KoTextEditor.h>
// KDE
#include <kdebug.h>
// Qt
#include <QCoreApplication>
#include "KoChangeTrackerDisabledRAII.h"
class KoSemanticStylesheetPrivate
{
......@@ -38,7 +40,7 @@ public:
bool m_isMutable;
KoSemanticStylesheetPrivate(const QString &uuid, const QString &name, const QString &templateString,
const QString &type = "System", bool isMutable = false)
const QString &type = QLatin1String("System"), bool isMutable = false)
:
m_uuid(uuid),
m_name(name),
......@@ -164,11 +166,11 @@ void KoSemanticStylesheet::format(hKoRdfSemanticItem obj, KoTextEditor *editor,
QString KoSemanticStylesheet::stylesheetTypeSystem()
{
return "System";
return QLatin1String("System");
}
QString KoSemanticStylesheet::stylesheetTypeUser()
{
return "User";
return QLatin1String("User");
}
......@@ -82,7 +82,7 @@ public:
void templateString(const QString &v);
signals:
void nameChanging(hKoSemanticStylesheet, QString oldName, QString newName);
void nameChanging(hKoSemanticStylesheet, const QString &oldName, const QString &newName);
};
#include <QMetaType>
......
......@@ -18,8 +18,10 @@
*/
#include "KoSopranoTableModel.h"
#include "KoDocumentRdf.h"
#include "KoRdfPrefixMapping.h"
// KDE
#include <kdebug.h>
#include <klocale.h>
......@@ -143,7 +145,7 @@ QVariant KoSopranoTableModel::headerData(int section, Qt::Orientation orientatio
return QVariant();
}
bool KoSopranoTableModel::isInlineRdf(Soprano::Statement st) const
bool KoSopranoTableModel::isInlineRdf(const Soprano::Statement &st) const
{
return (st.context().toString() == m_rdf->inlineRdfContext().toString());
}
......@@ -174,7 +176,7 @@ Qt::ItemFlags KoSopranoTableModel::flags(const QModelIndex &index) const
* The internal m_statementIndex int->statement is updated
* as well as the dataChanged signal emitted
*/
bool KoSopranoTableModel::setDataUpdateTriple(const QModelIndex &index, Soprano::Statement &old, Soprano::Statement &n)
bool KoSopranoTableModel::setDataUpdateTriple(const QModelIndex &index, const Soprano::Statement &old, const Soprano::Statement &n)
{
model()->addStatement(n);
model()->removeStatement(old);
......@@ -242,7 +244,7 @@ bool KoSopranoTableModel::setData(const QModelIndex &index, const QVariant &valu
/**
* Add the statement 'st' to the model as the new last row.
*/
int KoSopranoTableModel::insertStatement(Soprano::Statement st)
int KoSopranoTableModel::insertStatement(const Soprano::Statement &st)
{
QModelIndex parent;
int newRowNumber = rowCount();
......@@ -340,7 +342,7 @@ QModelIndexList KoSopranoTableModel::invalidStatementList() const
{
QModelIndexList ret;
for (int r = 0; r < m_statementIndex.size(); ++r) {
Soprano::Statement s = m_statementIndex[ r ];
const Soprano::Statement &s = m_statementIndex.at(r);
if (!s.isValid()) {
int col = ColSubj;
if (!s.subject().isValid()) {
......
......@@ -49,7 +49,7 @@ class KoSopranoTableModel : public QAbstractTableModel
/**
* True if the statement is stored in content.xml
*/
bool isInlineRdf(Soprano::Statement st) const;
bool isInlineRdf(const Soprano::Statement &st) const;
public:
......@@ -94,13 +94,13 @@ public:
* The internal m_statementIndex int->statement is updated
* as well as the dataChanged signal emitted
*/
bool setDataUpdateTriple(const QModelIndex &index, Soprano::Statement &old, Soprano::Statement &n);
bool setDataUpdateTriple(const QModelIndex &index, const Soprano::Statement &old, const Soprano::Statement &n);
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
/**
* Add the statement 'st' to the model as the new last row.
*/
int insertStatement(Soprano::Statement st);
int insertStatement(const Soprano::Statement &st);
/**
* Copy all the triples in srclist to be new rows in the model.
......
......@@ -18,12 +18,15 @@
*/
#include "KoSopranoTableModelDelegate.h"
#include "KoSopranoTableModel.h"
// lib
#include "KoSopranoTableModel.h"
#include "KoDocumentRdf.h"
#include "../KoDocument.h"
// main
#include <KoDocument.h>
// KDE
#include <klocale.h>
// Qt
#include <QComboBox>
KoSopranoTableModelDelegate::KoSopranoTableModelDelegate(QObject *parent)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment