1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/* This file is part of the KDE project
Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __rdf_KoSopranoTableModel_h__
#define __rdf_KoSopranoTableModel_h__
#include <QAbstractTableModel>
#include <Soprano/Soprano>
class KoDocumentRdf;
/**
* @short custom TableModel for editing a Soprano::Model
* @author Ben Martin <ben.martin@kogmbh.com>
* @see KoDocumentRdf
*
* Various columns are exposed to allow editing of not only
* the triple itself but also the object type, data type,
* and storage location of the triple.
*/
class KoSopranoTableModel : public QAbstractTableModel
{
KoDocumentRdf *m_rdf;
/**
* Because we need to be able to lookup triples by
* row number, a QList is created giving efficient index
* lookup for statements. Note that Soprano::Statement
* uses pimpl so we are not really copying statements here.
*/
QList<Soprano::Statement> m_statementIndex;
/**
* True if the statement is stored in content.xml
*/
bool isInlineRdf(Soprano::Statement st) const;
public:
KoSopranoTableModel(KoDocumentRdf* rdf);
/**
* Get the RDF model we this class is showing.
* You should not delete the return value.
*/
Soprano::Model *model() const;
enum {
ColIsValid = 0, // Is this triple valid
ColSubj, // subject
ColPred, // predicate
ColObj, // object
ColObjType, // string for type, eg, URI, Literal, Blank Node
ColObjXsdType, // XSD type URI for object
ColCtx, // Graph context for triple
ColCount // NOT A COLUMN but the size.
};
/**
* Convenience method, same as m_rdf->getPrefixMapping()
*/
QString URItoPrefexedLocalname(const QString &uri) const;
/**
* Convenience method, same as m_rdf->getPrefixMapping()
*/
QString PrefexedLocalnameToURI(const QString &pname);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
/**
* You MUST use this method if you want to change a Statement.
*
* Used by setData() to remove the old statement and replace it with the new 'n' one.
* 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 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);
/**
* 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 copyTriples(const QModelIndexList &srclist);
/**
* Delete all the triples in srclist from the model.
*/
void deleteTriples(const QModelIndexList &srclist);
/**
* Find the statement at the given row.
*/
Soprano::Statement statementAtIndex(const QModelIndex &mi) const;
/**
* The number of statements that have been partially or invalidly
* edited.
*
* @see invalidStatementList()
*/
int invalidStatementCount() const;
/**
* All the statements in the UI which are not valid Soprano::Statements
*
* @see invalidStatementCount()
*/
QModelIndexList invalidStatementList() const;
};
#endif
|