/** * Copy all the triples in srclist to be new rows in the model. * Note that the object value is modified to contain a unique * postfix so that the new triple copies can be inserted into * the Rdf model. It is a copy in a looser sense of the word. */ QModelIndexList KoSopranoTableModel::copyTriples(const QModelIndexList &srclist) { QModelIndexList ret; int FirstNewRowNumber = rowCount(); int LastNewRowNumber = FirstNewRowNumber + srclist.size() - 1; int currentNewRowNum = FirstNewRowNumber; beginInsertRows(QModelIndex(), FirstNewRowNumber, LastNewRowNumber); kDebug(30015) << " m_statementIndex.sz:" << m_statementIndex.size(); kDebug(30015) << " srclist.size():" << srclist.size(); kDebug(30015) << " first:" << FirstNewRowNumber; kDebug(30015) << " last:" << LastNewRowNumber; foreach (const QModelIndex &src, srclist) { int r = src.row(); kDebug(30015) << "r:" << r; Soprano::Statement st = m_statementIndex[ r ]; // // Append a bnode to the object to ensure the "copy" // is unique relative to the original. // Soprano::Node obj(QUrl(st.object().toString() + '-' + model()->createBlankNode().toString())); Soprano::Statement n(st.subject(), st.predicate(), obj, st.context()); model()->addStatement(n); m_statementIndex << n; QModelIndex newIdx = index(currentNewRowNum, ColSubj); ret << newIdx; ++currentNewRowNum; }
bool KoSopranoTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { Q_UNUSED(role); if (!index.isValid()) { return false; } int r = index.row(); Soprano::Statement st = m_statementIndex[r]; QString uri = PrefexedLocalnameToURI(value.toString()); Soprano::Statement n(st.subject(), st.predicate(), st.object(), st.context()); switch (index.column()) { case ColSubj: n.setSubject(Soprano::Node(QUrl(uri))); return setDataUpdateTriple(index, st, n); case ColPred: n.setPredicate(Soprano::Node(QUrl(uri))); return setDataUpdateTriple(index, st, n); case ColObj: { if (st.object().isLiteral()) { n.setObject( Soprano::Node( Soprano::LiteralValue(value.toString()))); } else { n.setObject(Soprano::Node(QUrl(uri))); } return setDataUpdateTriple(index, st, n); } case ColObjType: { QString v = value.toString(); if (v == "URI") { n.setObject(Soprano::Node(QUrl(st.object().toString()))); } else if (v == "Literal") { n.setObject( Soprano::Node( Soprano::LiteralValue(st.object().toString()))); } else { n.setObject(Soprano::Node(QString(st.object().toString()))); } return setDataUpdateTriple(index, st, n); } case ColCtx: { QString v = value.toString(); if (v == "inline") { QString InternalContext = m_rdf->rdfInternalMetadataWithoutSubjectURI(); n.setContext(Soprano::Node(QUrl(InternalContext))); } else { if (!v.endsWith(".rdf")) v = v + ".rdf"; n.setContext(Soprano::Node(QUrl(m_rdf->rdfPathContextPrefix() + v))); } return setDataUpdateTriple(index, st, n); } } return false; }
void Soprano::ModelMonitor::slotStatementRemoved( const Soprano::Statement& s ) { // we do not use Statement::matches here since we want to match empty nodes on both sides. // not only in the pattern. This is because some backends do not emit the statementRemoved // signal on each single statement but on the pattern used. if ( ( d->pattern.subject().isEmpty() || s.subject().isEmpty() || d->pattern.subject() == s.subject() ) && ( d->pattern.predicate().isEmpty() || s.predicate().isEmpty() || d->pattern.predicate() == s.predicate() ) && ( d->pattern.object().isEmpty() || s.object().isEmpty() || d->pattern.object() == s.object() ) && ( d->pattern.context().isEmpty() || s.context().isEmpty() || d->pattern.context() == s.context() ) ) { QTextStream outStream( stdout ); outStream << QString( "%1 | " ).arg( d->addedCnt + d->removedCnt++, 4, 10, QChar('0') ) << "Removed: " << s << endl; } }
QVariant KoSopranoTableModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } Soprano::Statement st = m_statementIndex[index.row()]; if (index.column() == ColIsValid && role == Qt::CheckStateRole) { return st.isValid(); } if (role == Qt::BackgroundRole) { if (!m_statementIndex[index.row()].isValid()) { return QColor("#BB0000"); } } if (role != Qt::DisplayRole && role != Qt::EditRole) { return QVariant(); } switch (index.column()) { case ColIsValid: return QVariant(); case ColSubj: return URItoPrefexedLocalname(st.subject().toString()); case ColPred: return URItoPrefexedLocalname(st.predicate().toString()); case ColObj: if (st.object().type() == Soprano::Node::ResourceNode) return URItoPrefexedLocalname(st.object().toString()); return st.object().toString(); case ColObjType: switch (st.object().type()) { case Soprano::Node::EmptyNode: return i18n("Empty"); case Soprano::Node::ResourceNode: return i18n("URI"); case Soprano::Node::LiteralNode: return i18n("Literal"); case Soprano::Node::BlankNode: return i18n("Blank"); } return QString(); case ColObjXsdType: return st.object().dataType().toString(); case ColCtx: { QString ctx = st.context().toString(); QString RdfPathContextPrefix = m_rdf->rdfPathContextPrefix(); QString InternalContext = m_rdf->inlineRdfContext().toString(); kDebug(30015) << "InternalContext:" << InternalContext; kDebug(30015) << "ctx:" << ctx; if (ctx.startsWith(RdfPathContextPrefix)) { ctx = ctx.mid(RdfPathContextPrefix.size()); } if (isInlineRdf(st)) { ctx = "inline"; } return ctx; } } return QVariant(); }
bool KoSopranoTableModel::isInlineRdf(Soprano::Statement st) const { return (st.context().toString() == m_rdf->inlineRdfContext().toString()); }
foreach (Soprano::Statement s, allStatements) { // RDEBUG << "HAVE:" << s; QVERIFY (s.object().toString() == "CDC474D4-1393-11D7-9A2C-000393914268"); QVERIFY (s.context().toString() == rdf->RDF_PATH_CONTEXT_PREFIX + "geo1.rdf"); }