Warning, file /office/calligra/libs/rdf/KoSopranoTableModel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef __rdf_KoSopranoTableModel_h__
0021 #define __rdf_KoSopranoTableModel_h__
0022 
0023 #include <QAbstractTableModel>
0024 #include <QSharedPointer>
0025 #include <Soprano/Soprano>
0026 
0027 class KoDocumentRdf;
0028 
0029 /**
0030  * @short custom TableModel for editing a Soprano::Model
0031  * @author Ben Martin <ben.martin@kogmbh.com>
0032  * @see KoDocumentRdf
0033  *
0034  * Various columns are exposed to allow editing of not only
0035  * the triple itself but also the object type, data type,
0036  * and storage location of the triple.
0037  */
0038 class KoSopranoTableModel : public QAbstractTableModel
0039 {
0040     KoDocumentRdf *m_rdf;
0041     /**
0042      * Because we need to be able to lookup triples by
0043      * row number, a QList is created giving efficient index
0044      * lookup for statements. Note that Soprano::Statement
0045      * uses pimpl so we are not really copying statements here.
0046      */
0047     QList<Soprano::Statement> m_statementIndex;
0048 
0049     /**
0050      * True if the statement is stored in content.xml
0051      */
0052     bool isInlineRdf(const Soprano::Statement &st) const;
0053 
0054 public:
0055 
0056     explicit KoSopranoTableModel(KoDocumentRdf *rdf);
0057 
0058     /**
0059      * Get the RDF model we this class is showing.
0060      * You should not delete the return value.
0061      */
0062     QSharedPointer<Soprano::Model> model() const;
0063 
0064     enum {
0065         ColIsValid = 0,  // Is this triple valid
0066         ColSubj,         // subject
0067         ColPred,         // predicate
0068         ColObj,          // object
0069         ColObjType,      // string for type, eg, URI, Literal, Blank Node
0070         ColObjXsdType,   // XSD type URI for object
0071         ColCtx,          // Graph context for triple
0072         ColCount         // NOT A COLUMN but the size.
0073     };
0074 
0075     /**
0076      * Convenience method, same as m_rdf->getPrefixMapping()
0077      */
0078     QString URItoPrefexedLocalname(const QString &uri) const;
0079     /**
0080      * Convenience method, same as m_rdf->getPrefixMapping()
0081      */
0082     QString PrefexedLocalnameToURI(const QString &pname);
0083 
0084     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
0085     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
0086     int columnCount(const QModelIndex &parent = QModelIndex()) const;
0087     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
0088     Qt::ItemFlags flags(const QModelIndex &index) const;
0089 
0090     /**
0091      * You MUST use this method if you want to change a Statement.
0092      *
0093      * Used by setData() to remove the old statement and replace it with the new 'n' one.
0094      * The internal m_statementIndex int->statement is updated
0095      * as well as the dataChanged signal emitted
0096      */
0097     bool setDataUpdateTriple(const QModelIndex &index, const Soprano::Statement &old, const Soprano::Statement &n);
0098     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
0099 
0100     /**
0101      * Add the statement 'st' to the model as the new last row.
0102      */
0103     int insertStatement(const Soprano::Statement &st);
0104 
0105     /**
0106      * Copy all the triples in srclist to be new rows in the model.
0107      * Note that the object value is modified to contain a unique
0108      * postfix so that the new triple copies can be inserted into
0109      * the Rdf model. It is a copy in a looser sense of the word.
0110      */
0111     QModelIndexList copyTriples(const QModelIndexList &srclist);
0112 
0113     /**
0114      * Delete all the triples in srclist from the model.
0115      */
0116     void deleteTriples(const QModelIndexList &srclist);
0117 
0118     /**
0119      * Find the statement at the given row.
0120      */
0121     Soprano::Statement statementAtIndex(const QModelIndex &mi) const;
0122 
0123     /**
0124      * The number of statements that have been partially or invalidly
0125      * edited.
0126      *
0127      * @see invalidStatementList()
0128      */
0129     int invalidStatementCount() const;
0130 
0131     /**
0132      * All the statements in the UI which are not valid Soprano::Statements
0133      *
0134      * @see invalidStatementCount()
0135      */
0136     QModelIndexList invalidStatementList() const;
0137 };
0138 
0139 #endif