~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to libs/main/rdf/KoDocumentRdf.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This file is part of the KDE project
2
2
   Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com>
3
 
   Copyright (C) 2011 Ben Martin hacking for fun!
 
3
   Copyright (C) 2011,2012 Ben Martin hacking for fun!
4
4
 
5
5
   This library is free software; you can redistribute it and/or
6
6
   modify it under the terms of the GNU Library General Public
71
71
using namespace Soprano;
72
72
 
73
73
 
 
74
 
74
75
class KoDocumentRdfPrivate
75
76
{
76
77
public:
77
78
 
78
79
    KoDocumentRdfPrivate()
79
 
            : model(0)
 
80
            : model(Soprano::createModel())
80
81
            , prefixMapping(0)
81
82
    {
82
 
        model = Soprano::createModel();
83
83
    }
84
84
 
85
85
    ~KoDocumentRdfPrivate()
88
88
        model->deleteLater();
89
89
    }
90
90
 
91
 
    Soprano::Model *model; ///< Main Model containing all Rdf for doc
 
91
    QSharedPointer<Soprano::Model> model; ///< Main Model containing all Rdf for doc
92
92
    QMap<QString, QWeakPointer<KoTextInlineRdf> > inlineRdfObjects;  ///< Cache of weak pointers to inline Rdf
93
93
    KoRdfPrefixMapping *prefixMapping;     ///< prefix -> URI mapping
94
94
 
95
 
    QList<KoRdfFoaF*> foafObjects;
96
 
    QList<KoRdfCalendarEvent*> calObjects;
97
 
    QList<KoRdfLocation*> locObjects;
 
95
    QList<hKoRdfFoaF> foafObjects;
 
96
    QList<hKoRdfCalendarEvent> calObjects;
 
97
    QList<hKoRdfLocation> locObjects;
98
98
 
99
 
    QMap<QString,QList<KoSemanticStylesheet*> > userStylesheets;
 
99
    QMap<QString,QList<hKoSemanticStylesheet> > userStylesheets;
100
100
};
101
101
 
102
102
 
116
116
    delete d;
117
117
}
118
118
 
119
 
const Soprano::Model *KoDocumentRdf::model() const
 
119
QSharedPointer<Soprano::Model> KoDocumentRdf::model() const
120
120
{
121
121
    return d->model;
122
122
}
150
150
    return Node(QUrl(rdfPathContextPrefix() + "manifest.rdf"));
151
151
}
152
152
 
153
 
void KoDocumentRdf::freshenBNodes(Soprano::Model *m)
 
153
void KoDocumentRdf::freshenBNodes(QSharedPointer<Soprano::Model> m)
154
154
{
155
155
    Q_ASSERT(m);
156
156
    Q_ASSERT(d->model);
203
203
 
204
204
bool KoDocumentRdf::loadRdf(KoStore *store, const Soprano::Parser *parser, const QString &fileName)
205
205
{
206
 
    Soprano::Model *tmpmodel(Soprano::createModel());
 
206
    QSharedPointer<Soprano::Model> tmpmodel(Soprano::createModel());
207
207
    if (!d->model || !tmpmodel) {
208
208
        kWarning(30003) << "No soprano model";
209
209
        return false;
247
247
 
248
248
        QStringList classNames = KoRdfSemanticItem::classNames();
249
249
        foreach (const QString &semanticClass, classNames) {
250
 
            KoRdfSemanticItem *si = KoRdfSemanticItem::createSemanticItem(this, this, semanticClass);
 
250
            hKoRdfSemanticItem si = KoRdfSemanticItem::createSemanticItem(this, this, semanticClass);
251
251
            si->loadUserStylesheets(d->model);
252
252
        }
253
253
    }
254
 
    delete tmpmodel;
255
254
    store->close();
256
255
    return ok;
257
256
}
330
329
 
331
330
        QStringList classNames = KoRdfSemanticItem::classNames();
332
331
        foreach (const QString &semanticClass, classNames) {
333
 
            KoRdfSemanticItem *si = KoRdfSemanticItem::createSemanticItem(qobject_cast<QObject*>(const_cast<KoDocumentRdf*>(this)), this, semanticClass);
 
332
            hKoRdfSemanticItem si = KoRdfSemanticItem::createSemanticItem(qobject_cast<QObject*>(const_cast<KoDocumentRdf*>(this)), this, semanticClass);
334
333
            si->saveUserStylesheets(d->model, context);
335
334
        }
336
335
    }
425
424
 
426
425
}
427
426
 
428
 
QList<KoRdfFoaF*> KoDocumentRdf::foaf(Soprano::Model *m)
 
427
QList<hKoRdfFoaF> KoDocumentRdf::foaf(QSharedPointer<Soprano::Model> m)
429
428
{
430
429
    if (!m) {
431
430
        m = d->model;
454
453
    // lastKnownObjects is used to perform a sematic set diff
455
454
    // at return time d->foafObjects will have any new objects and
456
455
    // ones that are no longer available will be removed.
457
 
    QList<KoRdfFoaF*> lastKnownObjects = d->foafObjects;
 
456
    QList<hKoRdfFoaF> lastKnownObjects = d->foafObjects;
458
457
 
459
458
    // uniqfilter is needed because soprano is not honouring
460
459
    // the DISTINCT sparql keyword
467
466
            continue;
468
467
        uniqfilter += n;
469
468
 
470
 
        KoRdfFoaF *newItem = new KoRdfFoaF(this, this, it);
 
469
        hKoRdfFoaF newItem(new KoRdfFoaF(0, this, it));
471
470
        QString newItemLs = newItem->linkingSubject().toString();
472
 
        foreach (KoRdfFoaF *semItem, lastKnownObjects) {
 
471
        foreach (hKoRdfFoaF semItem, lastKnownObjects) {
473
472
            if (newItemLs == semItem->linkingSubject().toString()) {
474
473
                lastKnownObjects.removeAll(semItem);
475
 
                delete newItem;
476
474
                newItem = 0;
477
475
                break;
478
476
            }
483
481
        }
484
482
    }
485
483
 
486
 
    foreach (KoRdfFoaF *semItem, lastKnownObjects) {
 
484
    foreach (hKoRdfFoaF semItem, lastKnownObjects) {
487
485
        d->foafObjects.removeAll(semItem);
488
486
    }
489
487
 
503
501
    return d->foafObjects;
504
502
}
505
503
 
506
 
QList<KoRdfCalendarEvent*> KoDocumentRdf::calendarEvents(Soprano::Model *m)
 
504
QList<hKoRdfCalendarEvent> KoDocumentRdf::calendarEvents(QSharedPointer<Soprano::Model> m)
507
505
{
508
506
    if (!m) {
509
507
        m = d->model;
529
527
                          "              } \n"
530
528
                          "    } \n"
531
529
                          "  } \n";
 
530
 
532
531
    Soprano::QueryResultIterator it =
533
532
        m->executeQuery(sparqlQuery,
534
533
                        Soprano::Query::QueryLanguageSparql);
535
 
    QList<KoRdfCalendarEvent*> lastKnownObjects = d->calObjects;
 
534
    QList<hKoRdfCalendarEvent> lastKnownObjects = d->calObjects;
536
535
    // uniqfilter is needed because soprano is not honouring
537
536
    // the DISTINCT sparql keyword
538
537
    QSet<QString> uniqfilter;
544
543
        RDEBUG << " g:" << it.binding("g").toString();
545
544
        RDEBUG << " uid:" << it.binding("uid").toString();
546
545
 
547
 
        KoRdfCalendarEvent *newItem(new KoRdfCalendarEvent(this, this, it));
 
546
        hKoRdfCalendarEvent newItem(new KoRdfCalendarEvent(0, this, it));
548
547
        QString newItemLs = newItem->linkingSubject().toString();
549
 
        foreach (KoRdfCalendarEvent *semItem, lastKnownObjects) {
 
548
        foreach (hKoRdfCalendarEvent semItem, lastKnownObjects) {
550
549
            if (newItemLs == semItem->linkingSubject().toString()) {
551
550
                lastKnownObjects.removeAll(semItem);
552
 
                delete newItem;
553
551
                newItem = 0;
554
552
                break;
555
553
            }
558
556
            d->calObjects << newItem;
559
557
        }
560
558
    }
561
 
    foreach (KoRdfCalendarEvent *semItem, lastKnownObjects) {
 
559
    foreach (hKoRdfCalendarEvent semItem, lastKnownObjects) {
562
560
        d->calObjects.removeAll(semItem);
563
561
    }
564
562
    RDEBUG << "calendarEvents() size:" << d->calObjects.size() << endl;
599
597
};
600
598
 
601
599
 
602
 
void KoDocumentRdf::addLocations(Soprano::Model *m, QList<KoRdfLocation*> &ret, bool isGeo84,
 
600
void KoDocumentRdf::addLocations(QSharedPointer<Soprano::Model> m, QList<hKoRdfLocation> &ret, bool isGeo84,
603
601
                                 const QString &sparqlQuery)
604
602
{
605
603
    Soprano::QueryResultIterator it = m->executeQuery(sparqlQuery,
610
608
        if (uniqFilter.shouldSkip(it))
611
609
            continue;
612
610
 
613
 
        KoRdfLocation *semObj(new KoRdfLocation(this, this, it, isGeo84));
 
611
        hKoRdfLocation semObj(new KoRdfLocation(0, this, it, isGeo84));
614
612
        ret << semObj;
615
613
    }
616
614
    RDEBUG << "addLocations() size:" << ret.size() << endl;
617
615
}
618
616
 
619
 
QList<KoRdfLocation*> KoDocumentRdf::locations(Soprano::Model *m)
 
617
QList<hKoRdfLocation> KoDocumentRdf::locations(QSharedPointer<Soprano::Model> m)
620
618
{
621
619
    if (!m) {
622
620
        m = d->model;
624
622
    }
625
623
    RDEBUG << "locations(top) full-model.sz:" << d->model->statementCount();
626
624
    RDEBUG << " passed model.size:" << m->statementCount();
627
 
    QList<KoRdfLocation*> currentKoRdfLocations;
 
625
    QList<hKoRdfLocation> currentKoRdfLocations;
628
626
    addLocations(m, currentKoRdfLocations, false,
629
627
        " prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  \n"
630
628
        " prefix foaf: <http://xmlns.com/foaf/0.1/>  \n"
669
667
    // Creating a list of locations each time similifies the query and discovery process
670
668
    // at the expense of this little mess to merge the new and old with explicit pointer
671
669
    // and object lifetime handling
672
 
    QList<KoRdfLocation*> removeSet;
673
 
    foreach (KoRdfLocation *oldItem, d->locObjects) {
 
670
    QList<hKoRdfLocation> removeSet;
 
671
    foreach (hKoRdfLocation oldItem, d->locObjects) {
674
672
        QString oldItemLs = oldItem->linkingSubject().toString();
675
673
        bool found = false;
676
 
        foreach (KoRdfLocation *newItem, currentKoRdfLocations) {
 
674
        foreach (hKoRdfLocation newItem, currentKoRdfLocations) {
677
675
            if (oldItemLs == newItem->linkingSubject().toString()) {
678
676
                found = true;
679
677
                break;
684
682
        }
685
683
    }
686
684
 
687
 
    foreach (KoRdfLocation *item, removeSet) {
 
685
    foreach (hKoRdfLocation item, removeSet) {
688
686
        d->locObjects.removeAll(item);
689
687
    }
690
688
 
691
 
    QList<KoRdfLocation*> addedSet;
692
 
    foreach (KoRdfLocation *newItem, currentKoRdfLocations) {
 
689
    foreach (hKoRdfLocation newItem, currentKoRdfLocations) {
693
690
        QString newItemLs = newItem->linkingSubject().toString();
694
691
        bool found = false;
695
 
        foreach (KoRdfLocation *oldItem, d->locObjects) {
 
692
        foreach (hKoRdfLocation oldItem, d->locObjects) {
696
693
            if (newItemLs == oldItem->linkingSubject().toString()) {
697
694
                found = true;
698
695
                break;
700
697
        }
701
698
        if (!found) {
702
699
            d->locObjects << newItem;
703
 
            addedSet << newItem;
704
700
        }
705
701
    }
706
 
    foreach (KoRdfLocation *item, addedSet) {
707
 
        currentKoRdfLocations.removeAll(item);
708
 
    }
709
702
 
710
 
    RDEBUG << "locations(end) deleting duplicates size:" << currentKoRdfLocations.size() << endl;
711
 
    qDeleteAll(currentKoRdfLocations);
712
703
    RDEBUG << "locations(end) size:" << d->locObjects.size() << endl;
713
704
    return d->locObjects;
714
705
}
715
706
 
716
 
void KoDocumentRdf::dumpModel(const QString &msg, Soprano::Model *m) const
 
707
void KoDocumentRdf::dumpModel(const QString &msg, QSharedPointer<Soprano::Model> m) const
717
708
{
718
709
    if (!m) {
719
710
        return;
759
750
    return ret;
760
751
}
761
752
 
762
 
void KoDocumentRdf::addStatements(Soprano::Model *model, const QString &xmlid)
 
753
void KoDocumentRdf::addStatements(QSharedPointer<Soprano::Model> model, const QString &xmlid)
763
754
{
764
755
    Q_ASSERT(model);
765
756
    Q_ASSERT(d->model);
794
785
    }
795
786
}
796
787
 
797
 
void KoDocumentRdf::expandStatementsReferencingSubject(Soprano::Model *_model) const
 
788
void KoDocumentRdf::expandStatementsReferencingSubject(QSharedPointer<Soprano::Model> _model) const
798
789
{
799
790
    Q_ASSERT(_model);
800
791
    Q_ASSERT(d->model);
810
801
    _model->addStatements(addList);
811
802
}
812
803
 
813
 
void KoDocumentRdf::expandStatementsSubjectPointsTo(Soprano::Model *_model) const
 
804
void KoDocumentRdf::expandStatementsSubjectPointsTo(QSharedPointer<Soprano::Model> _model) const
814
805
{
815
806
    Q_ASSERT(_model);
816
807
    Q_ASSERT(d->model);
827
818
    _model->addStatements(addList);
828
819
}
829
820
 
830
 
void KoDocumentRdf::expandStatementsSubjectPointsTo(Soprano::Model *_model, const Soprano::Node &n) const
 
821
void KoDocumentRdf::expandStatementsSubjectPointsTo(QSharedPointer<Soprano::Model> _model, const Soprano::Node &n) const
831
822
{
832
823
    Q_ASSERT(_model);
833
824
    Q_ASSERT(d->model);
841
832
    _model->addStatements(addList);
842
833
}
843
834
 
844
 
void KoDocumentRdf::expandStatementsToIncludeRdfListsRecurse(Soprano::Model *_model,
 
835
void KoDocumentRdf::expandStatementsToIncludeRdfListsRecurse(QSharedPointer<Soprano::Model> _model,
845
836
        QList<Statement> &addList, const Soprano::Node &n) const
846
837
{
847
838
    Q_ASSERT(_model);
860
851
}
861
852
 
862
853
 
863
 
void KoDocumentRdf::expandStatementsToIncludeRdfLists(Soprano::Model *model) const
 
854
void KoDocumentRdf::expandStatementsToIncludeRdfLists(QSharedPointer<Soprano::Model> model) const
864
855
{
865
856
    Q_ASSERT(model);
866
857
    RDEBUG << "model.sz:" << model->statementCount();
875
866
    model->addStatements(addList);
876
867
}
877
868
 
878
 
void KoDocumentRdf::expandStatementsToIncludeOtherPredicates(Soprano::Model *_model) const
 
869
void KoDocumentRdf::expandStatementsToIncludeOtherPredicates(QSharedPointer<Soprano::Model> _model) const
879
870
{
880
871
    Q_ASSERT(_model);
881
872
    Q_ASSERT(d->model);
891
882
    _model->addStatements(addList);
892
883
}
893
884
 
894
 
void KoDocumentRdf::expandStatements(Soprano::Model *model) const
 
885
void KoDocumentRdf::expandStatements(QSharedPointer<Soprano::Model> model) const
895
886
{
896
887
    Q_ASSERT(model);
897
888
    expandStatementsReferencingSubject(model);
919
910
    KoTextInlineRdf *obj = findInlineRdfByID(xmlid);
920
911
    if (obj) {
921
912
        QPair<int, int> ret = obj->findExtent();
922
 
        RDEBUG << "have inline obj, extent:" << ret;
 
913
        RDEBUG << "(Semantic) have inline obj, extent:" << ret;
923
914
        return ret;
924
915
    }
925
916
    return QPair<int, int>(0, 0);
1054
1045
 
1055
1046
 
1056
1047
 
1057
 
Soprano::Model *KoDocumentRdf::findStatements(const QString &xmlid, int depth)
 
1048
QSharedPointer<Soprano::Model> KoDocumentRdf::findStatements(const QString &xmlid, int depth)
1058
1049
{
1059
 
    Soprano::Model *ret(Soprano::createModel());
 
1050
    QSharedPointer<Soprano::Model> ret(Soprano::createModel());
1060
1051
    Q_ASSERT(ret);
1061
1052
    addStatements(ret, xmlid);
1062
1053
    for (int i = 1; i < depth; ++i) {
1065
1056
    return ret;
1066
1057
}
1067
1058
 
1068
 
Soprano::Model *KoDocumentRdf::findStatements(KoTextEditor *handler, int depth)
 
1059
QSharedPointer<Soprano::Model> KoDocumentRdf::findStatements(KoTextEditor *handler, int depth)
1069
1060
{
1070
1061
    Q_ASSERT(d->model);
1071
1062
 
1072
 
    Soprano::Model *ret(Soprano::createModel());
 
1063
    QSharedPointer<Soprano::Model> ret(Soprano::createModel());
1073
1064
    Q_ASSERT(ret);
1074
1065
 
1075
1066
    QString xmlid = findXmlId(handler);
1183
1174
    RDEBUG << "done";
1184
1175
}
1185
1176
 
1186
 
void KoDocumentRdf::emitSemanticObjectAdded(KoRdfSemanticItem *item) const
1187
 
{
1188
 
    emit semanticObjectAdded(item);
1189
 
}
1190
 
 
1191
 
void KoDocumentRdf::emitSemanticObjectAddedConst(KoRdfSemanticItem *const item) const
1192
 
{
1193
 
    emit semanticObjectAdded(item);
1194
 
}
1195
 
 
1196
 
void KoDocumentRdf::emitSemanticObjectUpdated(KoRdfSemanticItem *item)
1197
 
{
1198
 
    RDEBUG << "item:" << item;
 
1177
void KoDocumentRdf::emitSemanticObjectAdded(hKoRdfSemanticItem item) const
 
1178
{
 
1179
    emit semanticObjectAdded(item);
 
1180
}
 
1181
 
 
1182
void KoDocumentRdf::emitSemanticObjectAddedConst(hKoRdfSemanticItem const item) const
 
1183
{
 
1184
    emit semanticObjectAdded(item);
 
1185
}
 
1186
 
 
1187
void KoDocumentRdf::emitSemanticObjectUpdated(hKoRdfSemanticItem item)
 
1188
{
1199
1189
    if (item) {
1200
1190
        //
1201
1191
        // reflow the formatting for each view of the semanticItem, in reverse document order
1211
1201
    emit semanticObjectUpdated(item);
1212
1202
}
1213
1203
 
1214
 
void KoDocumentRdf::emitSemanticObjectViewSiteUpdated(KoRdfSemanticItem *item, const QString &xmlid)
 
1204
void KoDocumentRdf::emitSemanticObjectViewSiteUpdated(hKoRdfSemanticItem item, const QString &xmlid)
1215
1205
{
1216
 
    RDEBUG << "item:" << item;
1217
1206
    if (item) {
1218
1207
        RDEBUG << "xmlid:" << xmlid << " reflow item:" << item->name();
1219
1208
        emit semanticObjectViewSiteUpdated(item, xmlid);
1231
1220
    return true;
1232
1221
}
1233
1222
 
1234
 
KoDocumentRdf::reflowItem::reflowItem(KoRdfSemanticItem *si, const QString &xmlid, KoSemanticStylesheet *ss, const QPair< int, int > &extent)
 
1223
KoDocumentRdf::reflowItem::reflowItem(hKoRdfSemanticItem si, const QString &xmlid, hKoSemanticStylesheet ss, const QPair< int, int > &extent)
1235
1224
        : m_si(si)
1236
1225
        , m_ss(ss)
1237
1226
        , m_xmlid(xmlid)
1239
1228
{
1240
1229
}
1241
1230
 
1242
 
void KoDocumentRdf::insertReflow(QMap<int, reflowItem> &col, KoRdfSemanticItem *obj, KoSemanticStylesheet *ss)
 
1231
void KoDocumentRdf::insertReflow(QMap<int, reflowItem> &col, hKoRdfSemanticItem obj, hKoSemanticStylesheet ss)
1243
1232
{
1244
1233
    RDEBUG << "reflowing object:" << obj->name();
1245
1234
    QStringList xmlidlist = obj->xmlIdList();
1251
1240
    }
1252
1241
}
1253
1242
 
1254
 
void KoDocumentRdf::insertReflow(QMap<int, reflowItem> &col, KoRdfSemanticItem *obj,
 
1243
void KoDocumentRdf::insertReflow(QMap<int, reflowItem> &col, hKoRdfSemanticItem obj,
1255
1244
                                 const QString &sheetType, const QString &stylesheetName)
1256
1245
{
1257
 
    KoSemanticStylesheet *ss = obj->findStylesheetByName(sheetType, stylesheetName);
 
1246
    hKoSemanticStylesheet ss = obj->findStylesheetByName(sheetType, stylesheetName);
1258
1247
    insertReflow(col, obj, ss);
1259
1248
}
1260
1249
 
1261
 
void KoDocumentRdf::insertReflow(QMap<int, reflowItem> &col, KoRdfSemanticItem *obj)
 
1250
void KoDocumentRdf::insertReflow(QMap<int, reflowItem> &col, hKoRdfSemanticItem obj)
1262
1251
{
1263
1252
    RDEBUG << "reflowing object:" << obj->name();
1264
1253
    foreach (const QString &xmlid, obj->xmlIdList()) {
1265
1254
        QPair<int, int> extent = findExtent(xmlid);
1266
1255
        RDEBUG << "format(), adding reflow xmlid location:" << xmlid << " extent:" << extent;
1267
 
        reflowItem item(obj, xmlid, 0, extent);
 
1256
        reflowItem item(obj, xmlid, hKoSemanticStylesheet(0), extent);
1268
1257
        col.insert(extent.first, item);
1269
1258
    }
1270
1259
}
1287
1276
    }
1288
1277
}
1289
1278
 
1290
 
QList<KoSemanticStylesheet*> KoDocumentRdf::userStyleSheetList(const QString& className) const
 
1279
QList<hKoSemanticStylesheet> KoDocumentRdf::userStyleSheetList(const QString& className) const
1291
1280
{
1292
1281
    return d->userStylesheets[className];
1293
1282
}
1294
1283
 
1295
 
void KoDocumentRdf::setUserStyleSheetList(const QString& className,const QList<KoSemanticStylesheet*>& l)
 
1284
void KoDocumentRdf::setUserStyleSheetList(const QString& className,const QList<hKoSemanticStylesheet>& l)
1296
1285
{
1297
1286
    d->userStylesheets[className] = l;
1298
1287
}