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

« back to all changes in this revision

Viewing changes to libs/main/rdf/KoRdfSemanticItem.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:
100
100
        const QString &predString,
101
101
        const Soprano::Node &explicitLinkingSubject)
102
102
{
103
 
    Soprano::Model *m = const_cast<Soprano::Model*>(documentRdf()->model());
 
103
    QSharedPointer<Soprano::Model> m = documentRdf()->model();
104
104
    Node pred = Node::createResourceNode(QUrl(predString));
105
105
    m->removeStatement(explicitLinkingSubject,pred, Node::createLiteralNode(toModify));
106
106
    kDebug(30015) << "Rdf.del subj:" << explicitLinkingSubject;
140
140
                                       const QString &predString,
141
141
                                       const Soprano::Node &explicitLinkingSubject)
142
142
{
143
 
    Soprano::Model *m = const_cast<Soprano::Model*>(documentRdf()->model());
 
143
    QSharedPointer<Soprano::Model> m = documentRdf()->model();
144
144
    Node pred = Node::createResourceNode(QUrl(predString));
145
145
 
146
146
    kDebug(30015) << "Rdf.add subj:" << explicitLinkingSubject;
180
180
 
181
181
void KoRdfSemanticItem::setRdfType(const QString &t)
182
182
{
183
 
    Soprano::Model *m = const_cast<Soprano::Model*>(documentRdf()->model());
 
183
    QSharedPointer<Soprano::Model> m = documentRdf()->model();
184
184
    Q_ASSERT(m);
185
185
    Node pred = Node::createResourceNode(QUrl("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
186
186
    m->addStatement(linkingSubject(), pred, Node::createResourceNode(t), context());
202
202
    delete objectEditor;
203
203
 
204
204
    if (rdf) {
205
 
        rdf->emitSemanticObjectAdded(this);
 
205
        rdf->emitSemanticObjectAdded(hKoRdfSemanticItem(this));
206
206
    }
207
207
}
208
208
 
242
242
    KoChangeTrackerDisabledRAII disableChangeTracker(ktd.changeTracker());
243
243
    Q_UNUSED(disableChangeTracker);
244
244
 
 
245
//    int originalpos = editor->position();
245
246
    KoTextMeta *startmark = new KoTextMeta(editor->document());
246
247
    editor->insertInlineObject(startmark);
247
248
    KoTextInlineRdf *inlineRdf(new KoTextInlineRdf((QTextDocument*)editor->document(), startmark));
253
254
    inlineRdf->setXmlId(newID);
254
255
    startmark->setInlineRdf(inlineRdf);
255
256
 
 
257
    // we could do a paragraph relayout to update the position() values
 
258
    // of the start and end, but this is more efficient.
 
259
    startmark->updatePosition( (QTextDocument*)editor->document(),
 
260
                               startmark->position()-1,
 
261
                               QTextCharFormat() );
256
262
    if (documentRdf()) {
257
263
        Soprano::Statement st(
258
264
            linkingSubject(),
259
265
            Node::createResourceNode(QUrl("http://docs.oasis-open.org/opendocument/meta/package/common#idref")),
260
266
            Node::createLiteralNode(newID),
261
267
            documentRdf()->manifestRdfNode());
262
 
        const_cast<Soprano::Model*>(documentRdf()->model())->addStatement(st);
 
268
        documentRdf()->model()->addStatement(st);
263
269
        kDebug(30015) << "KoRdfSemanticItem::insert() HAVE documentRdf(), linking statement:" << st;
264
270
 
265
 
        Soprano::Model* model(Soprano::createModel());
 
271
        QSharedPointer<Soprano::Model> model(Soprano::createModel());
266
272
        const_cast<KoDocumentRdf*>(documentRdf())->addStatements(model, newID);
267
273
        kDebug(30015) << "KoRdfSemanticItem::insert() returned model size:" << model->statementCount();
268
274
        const_cast<KoDocumentRdf*>(documentRdf())->rememberNewInlineRdfObject(inlineRdf);
269
 
        delete model;
270
275
    } else {
271
276
        kDebug(30015) << "KoRdfSemanticItem::insert() documentRdf() is not set!";
272
277
    }
287
292
    startmark->setEndBookmark(endmark);
288
293
 
289
294
    editor->setPosition(editor->position() - 1, QTextCursor::MoveAnchor);
290
 
    KoSemanticStylesheet *ss = defaultStylesheet();
291
 
    KoRdfSemanticItemViewSite vs(this, newID);
 
295
    // let the RDF docker know about this new object too.
 
296
    KoCanvasResourceManager *provider = host->resourceManager();
 
297
    provider->setResource(KoText::CurrentTextPosition, editor->position() - 1);
 
298
 
 
299
    hKoSemanticStylesheet ss = defaultStylesheet();
 
300
    KoRdfSemanticItemViewSite vs(hKoRdfSemanticItem(this), newID);
292
301
    vs.applyStylesheet(editor, ss);
293
302
 
294
303
}
302
311
    return ret;
303
312
}
304
313
 
305
 
KoRdfSemanticItem *KoRdfSemanticItem::createSemanticItem(QObject *parent, const KoDocumentRdf *m_rdf, const QString &semanticClass)
 
314
hKoRdfSemanticItem KoRdfSemanticItem::createSemanticItem(QObject *parent, const KoDocumentRdf *m_rdf, const QString &semanticClass)
306
315
{
307
316
    if (semanticClass == "Contact") {
308
 
        return new KoRdfFoaF(parent, m_rdf);
 
317
        return hKoRdfSemanticItem(new KoRdfFoaF(parent, m_rdf));
309
318
    }
310
319
    if (semanticClass == "Event") {
311
 
        return new KoRdfCalendarEvent(parent, m_rdf);
 
320
        return hKoRdfSemanticItem(new KoRdfCalendarEvent(parent, m_rdf));
312
321
    }
313
322
    if (semanticClass == "Location") {
314
 
        return new KoRdfLocation(parent, m_rdf);
 
323
        return hKoRdfSemanticItem(new KoRdfLocation(parent, m_rdf));
315
324
    }
316
 
    return 0;
 
325
    return hKoRdfSemanticItem(0);
317
326
}
318
327
 
319
 
QList<KoSemanticStylesheet*> KoRdfSemanticItem::userStylesheets() const
 
328
QList<hKoSemanticStylesheet> KoRdfSemanticItem::userStylesheets() const
320
329
{
321
330
    return documentRdf()->userStyleSheetList(className());
322
331
}
323
332
 
324
333
 
325
 
KoSemanticStylesheet *KoRdfSemanticItem::findStylesheetByUuid(const QString &id) const
 
334
hKoSemanticStylesheet KoRdfSemanticItem::findStylesheetByUuid(const QString &id) const
326
335
{
327
 
    KoSemanticStylesheet *ret = 0;
 
336
    hKoSemanticStylesheet ret = hKoSemanticStylesheet(0);
328
337
    if (id.isEmpty()) {
329
338
        return ret;
330
339
    }
331
 
    foreach (KoSemanticStylesheet *ss, stylesheets()) {
 
340
    foreach (hKoSemanticStylesheet ss, stylesheets()) {
332
341
        if (ss->uuid() == id) {
333
342
            return ss;
334
343
        }
335
344
    }
336
 
    foreach (KoSemanticStylesheet *ss, userStylesheets()) {
 
345
    foreach (hKoSemanticStylesheet ss, userStylesheets()) {
337
346
        if (ss->uuid() == id) {
338
347
            return ss;
339
348
        }
341
350
    return ret;
342
351
}
343
352
 
344
 
KoSemanticStylesheet *KoRdfSemanticItem::findStylesheetByName(const QList<KoSemanticStylesheet*> &ssheets,
 
353
hKoSemanticStylesheet KoRdfSemanticItem::findStylesheetByName(const QList<hKoSemanticStylesheet> &ssheets,
345
354
        const QString &n) const
346
355
{
347
 
    KoSemanticStylesheet *ret = 0;
348
 
    foreach (KoSemanticStylesheet *ss, ssheets) {
 
356
    hKoSemanticStylesheet ret = hKoSemanticStylesheet(0);
 
357
    foreach (hKoSemanticStylesheet ss, ssheets) {
349
358
        if (ss->name() == n) {
350
359
            return ss;
351
360
        }
353
362
    return ret;
354
363
}
355
364
 
356
 
KoSemanticStylesheet *KoRdfSemanticItem::findStylesheetByName(const QString &sheetType, const QString &n) const
 
365
hKoSemanticStylesheet KoRdfSemanticItem::findStylesheetByName(const QString &sheetType, const QString &n) const
357
366
{
358
367
    if (sheetType == "System") {
359
368
        return findStylesheetByName(stylesheets(), n);
361
370
    return findStylesheetByName(userStylesheets(), n);
362
371
}
363
372
 
364
 
KoSemanticStylesheet *KoRdfSemanticItem::defaultStylesheet() const
 
373
hKoSemanticStylesheet KoRdfSemanticItem::defaultStylesheet() const
365
374
{
366
375
    QString semanticClass = metaObject()->className();
367
 
    Soprano::Model *m = const_cast<Soprano::Model*>(documentRdf()->model());
 
376
    QSharedPointer<Soprano::Model> m = documentRdf()->model();
368
377
    QString name = KoTextRdfCore::getProperty(m,
369
378
                                              Node::createResourceNode(QUrl("http://calligra.org/rdf/document/" + semanticClass)),
370
379
                                              Node::createResourceNode(QUrl("http://calligra.org/rdf/stylesheet")),
378
387
                                              Node::createResourceNode(QUrl("http://calligra.org/rdf/stylesheet-uuid")),
379
388
                                              QString());
380
389
    kDebug(30015) << "name:" << name << " type:" << type << "\n uuid:" << uuid;
381
 
    KoSemanticStylesheet *ret = findStylesheetByUuid(uuid);
 
390
    hKoSemanticStylesheet ret = findStylesheetByUuid(uuid);
382
391
    if (!ret) {
383
392
        ret = findStylesheetByName(type, name);
384
393
    }
390
399
    return ret;
391
400
}
392
401
 
393
 
void KoRdfSemanticItem::defaultStylesheet(KoSemanticStylesheet *ss)
 
402
void KoRdfSemanticItem::defaultStylesheet(hKoSemanticStylesheet ss)
394
403
{
395
404
    const KoDocumentRdf *rdf = documentRdf();
396
 
    Soprano::Model *m = const_cast<Soprano::Model*>(documentRdf()->model());
 
405
    QSharedPointer<Soprano::Model> m = documentRdf()->model();
397
406
    QString uuid = ss->uuid();
398
407
    QString name = ss->name();
399
408
    QString semanticClass = metaObject()->className();
 
409
    
400
410
    m->removeAllStatements(
401
411
        Statement(Node::createResourceNode(QUrl("http://calligra.org/rdf/document/" + semanticClass)),
402
412
                  Node::createResourceNode(QUrl("http://calligra.org/rdf/stylesheet")),
423
433
                    rdf->manifestRdfNode());
424
434
}
425
435
 
426
 
KoSemanticStylesheet *KoRdfSemanticItem::createUserStylesheet(const QString &name, const QString &templateString)
 
436
hKoSemanticStylesheet KoRdfSemanticItem::createUserStylesheet(const QString &name, const QString &templateString)
427
437
{
428
438
    bool isMutable = true;
429
 
    KoSemanticStylesheet *ss =
430
 
        new KoSemanticStylesheet(QUuid::createUuid().toString(),
431
 
                                 name, templateString,
432
 
                                 KoSemanticStylesheet::stylesheetTypeUser(),
433
 
                                 isMutable);
434
 
    QList<KoSemanticStylesheet*> userSheets = userStylesheets();
 
439
    hKoSemanticStylesheet ss =
 
440
        hKoSemanticStylesheet(
 
441
            new KoSemanticStylesheet(QUuid::createUuid().toString(),
 
442
                                     name, templateString,
 
443
                                     KoSemanticStylesheet::stylesheetTypeUser(),
 
444
                                     isMutable));
 
445
    QList<hKoSemanticStylesheet> userSheets = userStylesheets();
435
446
    userSheets << ss;
436
447
    const_cast<KoDocumentRdf*>(documentRdf())->setUserStyleSheetList(className(),userSheets);
437
 
    connect(ss, SIGNAL(nameChanging(KoSemanticStylesheet*, QString, QString)),
438
 
            this, SLOT(onUserStylesheetRenamed(KoSemanticStylesheet*, QString, QString)));
 
448
    connect(ss.data(), SIGNAL(nameChanging(hKoSemanticStylesheet, QString, QString)),
 
449
            this, SLOT(onUserStylesheetRenamed(hKoSemanticStylesheet, QString, QString)));
439
450
    return ss;
440
451
}
441
452
 
442
 
void KoRdfSemanticItem::onUserStylesheetRenamed(KoSemanticStylesheet *ss, const QString &oldName, const QString &newName)
 
453
void KoRdfSemanticItem::onUserStylesheetRenamed(hKoSemanticStylesheet ss, const QString &oldName, const QString &newName)
443
454
{
444
455
    Q_UNUSED(ss);
445
456
    Q_UNUSED(oldName);
446
457
    Q_UNUSED(newName);
447
458
}
448
459
 
449
 
void KoRdfSemanticItem::destroyUserStylesheet(KoSemanticStylesheet *ss)
 
460
void KoRdfSemanticItem::destroyUserStylesheet(hKoSemanticStylesheet ss)
450
461
{
451
 
    QList<KoSemanticStylesheet*> userSheets = userStylesheets();
 
462
    QList<hKoSemanticStylesheet> userSheets = userStylesheets();
452
463
    userSheets.removeAll(ss);
453
464
    const_cast<KoDocumentRdf*>(documentRdf())->setUserStyleSheetList(className(),userSheets);
454
465
}
455
466
 
456
 
void KoRdfSemanticItem::loadUserStylesheets(Soprano::Model *model)
 
467
void KoRdfSemanticItem::loadUserStylesheets(QSharedPointer<Soprano::Model> model)
457
468
{
458
469
    QString semanticClass = metaObject()->className();
459
470
    QString nodePrefix = "http://calligra.org/rdf/user-stylesheets/" + semanticClass + "/";
481
492
        }
482
493
 
483
494
        bool isMutable = true;
484
 
        KoSemanticStylesheet *ss =
485
 
            new KoSemanticStylesheet(uuid, name, templateString,
486
 
                                   KoSemanticStylesheet::stylesheetTypeUser(),
487
 
                                   isMutable);
488
 
        QList<KoSemanticStylesheet*> userSheets = userStylesheets();
 
495
        hKoSemanticStylesheet ss =
 
496
            hKoSemanticStylesheet(
 
497
                new KoSemanticStylesheet(uuid, name, templateString,
 
498
                                         KoSemanticStylesheet::stylesheetTypeUser(),
 
499
                                         isMutable));
 
500
        QList<hKoSemanticStylesheet> userSheets = userStylesheets();
489
501
        userSheets << ss;
490
502
        const_cast<KoDocumentRdf*>(documentRdf())->setUserStyleSheetList(className(),userSheets);
491
 
        connect(ss, SIGNAL(nameChanging(KoSemanticStylesheetPtr, QString, QString)),
 
503
        connect(ss.data(), SIGNAL(nameChanging(hKoSemanticStylesheet, QString, QString)),
492
504
                this, SLOT(onUserStylesheetRenamed(KoSemanticStylesheetPtr, QString, QString)));
493
505
    }
494
506
}
495
507
 
496
 
void KoRdfSemanticItem::saveUserStylesheets(Soprano::Model *model, const Soprano::Node &context) const
 
508
void KoRdfSemanticItem::saveUserStylesheets(QSharedPointer<Soprano::Model> model, const Soprano::Node &context) const
497
509
{
498
510
    QString semanticClass = metaObject()->className();
499
511
    QString nodePrefix = "http://calligra.org/rdf/user-stylesheets/" + semanticClass + "/";
504
516
    Soprano::Node dataBNode = model->createBlankNode();
505
517
    QList< Soprano::Node > dataBNodeList;
506
518
 
507
 
    QList<KoSemanticStylesheet*> ssl = userStylesheets();
508
 
    foreach (KoSemanticStylesheet *ss, ssl) {
 
519
    QList<hKoSemanticStylesheet> ssl = userStylesheets();
 
520
    foreach (hKoSemanticStylesheet ss, ssl) {
509
521
        kDebug(30015) << "saving sheet:" << ss->name();
510
522
 
511
523
        dataBNode = model->createBlankNode();