Warning, file /office/calligra/libs/rdf/KoDocumentRdfEditWidget.cpp 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 #include "KoDocumentRdfEditWidget.h"
0021 
0022 #include <ui_KoDocumentRdfEditWidget.h>
0023 
0024 #include "KoDocumentRdf.h"
0025 #include "KoRdfSemanticItemRegistry.h"
0026 #include "KoRdfPrefixMapping.h"
0027 #include "KoSopranoTableModelDelegate.h"
0028 #include "KoSopranoTableModel.h"
0029 #include "KoRdfSemanticTreeWidgetItem.h"
0030 // main
0031 #include <KoDocument.h>
0032 #include <KoIcon.h>
0033 // KF5
0034 #include <kdebug.h>
0035 #include <kmenu.h>
0036 #include <kmessagebox.h>
0037 #include <klocalizedstring.h>
0038 // Qt
0039 #include <QComboBox>
0040 #include <QPointer>
0041 #include <QSortFilterProxyModel>
0042 
0043 
0044 static const char SemanticItemClassId[] = "Ko_semanticItemClass";
0045 
0046 /**
0047  * Helper class to maintain a single row in the namespace editing
0048  * widget. This allows prefixes to be edited and updates the internal
0049  * data structures accordingly.
0050  */
0051 class KoRdfPrefixMappingTreeWidgetItem : public QTreeWidgetItem
0052 {
0053     KoRdfPrefixMapping *m_mapping;
0054     QString m_key;
0055 public:
0056     enum {
0057         ColKey = 0,
0058         ColValue = 1,
0059         ColSize
0060     };
0061     KoRdfPrefixMappingTreeWidgetItem(KoRdfPrefixMapping *mapping, const QString &key, int type = Type)
0062         : QTreeWidgetItem(type)
0063         , m_mapping(mapping)
0064         , m_key(key) {
0065         setFlags(QTreeWidgetItem::flags() | Qt::ItemIsEditable);
0066     }
0067     virtual void setData(int column, int role, const QVariant &value) {
0068         m_mapping->dump();
0069         kDebug(30015) << "m_key:" << m_key << " value:" << value;
0070         if (column == ColKey) {
0071             QString url = m_mapping->prefexToURI(m_key);
0072             m_mapping->remove(m_key);
0073             m_key = value.toString();
0074             m_mapping->insert(m_key, url);
0075         } else if (column == ColValue) {
0076             m_mapping->remove(m_key);
0077             m_mapping->insert(m_key, value.toString());
0078         }
0079         QTreeWidgetItem::setData(column, role, value);
0080     }
0081     virtual QVariant data(int column, int role) const {
0082         if (role != Qt::DisplayRole && role != Qt::EditRole) {
0083             return QVariant();
0084         }
0085         if (column == ColKey) {
0086             return m_key;
0087         } else if (column == ColValue) {
0088             QString url = m_mapping->prefexToURI(m_key);
0089             return url;
0090         }
0091         return QTreeWidgetItem::data(column, role);
0092     }
0093     void removeFromMapping() {
0094         m_mapping->remove(m_key);
0095     }
0096 };
0097 
0098 class KoDocumentRdfEditWidget::KoDocumentRdfEditWidgetPrivate
0099 {
0100 public:
0101     QWidget *m_widget;
0102     KoDocumentRdf *m_rdf;
0103     Ui::KoDocumentRdfEditWidget *m_ui;
0104     QHash<QString, QComboBox*> m_defaultStylesheetComboBoxMap;
0105     KoSopranoTableModel *m_tripleModel;
0106     KoSopranoTableModel *m_sparqlResultModel;
0107     QSortFilterProxyModel *m_tripleProxyModel;
0108     KoRdfSemanticTree m_semanticItemsTree;
0109     QList<hKoSemanticStylesheet> m_stylesheets;
0110 
0111     KoDocumentRdfEditWidgetPrivate(KoDocumentRdf *m_rdf)
0112         : m_rdf(m_rdf)
0113         , m_tripleProxyModel(0)
0114     {
0115         m_ui = new Ui::KoDocumentRdfEditWidget();
0116         m_widget = new QWidget();
0117         m_ui->setupUi(m_widget);
0118     }
0119     ~KoDocumentRdfEditWidgetPrivate() {
0120         delete m_ui;
0121     }
0122 
0123     void setupWidget()
0124     {
0125         // setup triple view page
0126         m_tripleModel = new KoSopranoTableModel(m_rdf);
0127         m_tripleProxyModel = new QSortFilterProxyModel(m_widget);
0128         m_tripleProxyModel->setSourceModel(m_tripleModel);
0129         m_ui->m_tripleView->setModel(m_tripleProxyModel);
0130         m_ui->m_tripleView->setSelectionBehavior(QAbstractItemView::SelectRows);
0131         m_ui->m_tripleView->hideColumn(KoSopranoTableModel::ColIsValid);
0132         m_ui->m_tripleView->hideColumn(KoSopranoTableModel::ColObjXsdType);
0133         m_ui->m_tripleView->horizontalHeader()->setResizeMode(KoSopranoTableModel::ColSubj, QHeaderView::Stretch);
0134         m_ui->m_tripleView->horizontalHeader()->setResizeMode(KoSopranoTableModel::ColPred, QHeaderView::Stretch);
0135         m_ui->m_tripleView->horizontalHeader()->setResizeMode(KoSopranoTableModel::ColObj,  QHeaderView::Stretch);
0136         m_ui->m_tripleView->horizontalHeader()->setResizeMode(KoSopranoTableModel::ColCtx,  QHeaderView::Stretch);
0137         m_ui->m_tripleView->setItemDelegate(new KoSopranoTableModelDelegate(m_tripleProxyModel));
0138         // setup namespace page
0139         QTreeWidget *v = m_ui->m_namespaceView;
0140         v->setColumnCount(KoRdfPrefixMappingTreeWidgetItem::ColSize);
0141         v->sortItems(KoRdfPrefixMappingTreeWidgetItem::ColValue, Qt::DescendingOrder);
0142         v->header()->setResizeMode(KoRdfPrefixMappingTreeWidgetItem::ColKey,
0143                                    QHeaderView::ResizeToContents);
0144         KoRdfPrefixMapping *mapping = m_rdf->prefixMapping();
0145         const QMap<QString,QString> &m = m_rdf->prefixMapping()->mappings();
0146         for (QMap<QString,QString>::const_iterator mi = m.begin(); mi != m.end(); ++mi) {
0147             KoRdfPrefixMappingTreeWidgetItem *item =
0148                     new KoRdfPrefixMappingTreeWidgetItem(mapping, mi.key());
0149             v->addTopLevelItem(item);
0150         }
0151         // setup semantic page
0152         v = m_ui->m_semanticView;
0153         m_semanticItemsTree = KoRdfSemanticTree::createTree(v);
0154         m_semanticItemsTree.update(m_rdf);
0155     }
0156 
0157     void buildComboBox(QComboBox *w, hKoRdfSemanticItem si) {
0158         if (!si) {
0159             return;
0160         }
0161         hKoSemanticStylesheet activeSheet = si->defaultStylesheet();
0162         int activeSheetIndex = 0;
0163         kDebug(30015) << "format(), activeSheet:" << activeSheet->name();
0164 
0165         foreach (hKoSemanticStylesheet ss, si->stylesheets()) {
0166             m_stylesheets << ss;
0167             QVariant ud = QVariant::fromValue(ss.data());
0168             w->addItem(ss->name(), ud);
0169             if (activeSheet->name() == ss->name()) {
0170                 activeSheetIndex = w->count() - 1;
0171             }
0172         }
0173         foreach (hKoSemanticStylesheet ss, si->userStylesheets()) {
0174             m_stylesheets << ss;
0175             QVariant ud = QVariant::fromValue(ss.data());
0176             w->addItem(ss->name(), ud);
0177             if (activeSheet->name() == ss->name()) {
0178                 activeSheetIndex = w->count() - 1;
0179             }
0180         }
0181         kDebug(30015) << "format(), active:" << activeSheetIndex;
0182         w->setCurrentIndex(activeSheetIndex);
0183     }
0184 
0185     void clearTriplesSelection() {
0186         m_ui->m_tripleView->selectionModel()->clear();
0187     }
0188 
0189     void selectTriples(int row) {
0190         m_ui->m_tripleView->selectRow(row);
0191     }
0192 
0193     void selectTriples(const QModelIndex &mi,
0194                        QItemSelectionModel::SelectionFlags command = QItemSelectionModel::Select) {
0195         m_ui->m_tripleView->selectionModel()->select(mi, command | QItemSelectionModel::Rows);
0196     }
0197 
0198     void selectTriples(const QModelIndexList &ml,
0199                        QItemSelectionModel::SelectionFlags command = QItemSelectionModel::Select) {
0200         Q_UNUSED(command);
0201         foreach (const QModelIndex &mi, ml) {
0202             selectTriples(mi);
0203         }
0204     }
0205 
0206     QModelIndexList mapFromSource(QModelIndexList mil) const {
0207         QModelIndexList ret;
0208         foreach (const QModelIndex &idx, mil) {
0209             QModelIndex pidx = m_tripleProxyModel->mapFromSource(idx);
0210             ret << pidx;
0211         }
0212         return ret;
0213     }
0214 
0215     QModelIndex mapFromSource(QModelIndex idx) const {
0216         QModelIndex pidx = m_tripleProxyModel->mapFromSource(idx);
0217         return pidx;
0218     }
0219 
0220     QModelIndex mapToSource(const QModelIndex proxyIndex) const {
0221         QModelIndex sidx = m_tripleProxyModel->mapToSource(proxyIndex);
0222         return sidx;
0223     }
0224 
0225     QModelIndexList mapToSource(const QModelIndexList proxyList) const {
0226         QModelIndexList ret;
0227         foreach (const QModelIndex &idx, proxyList) {
0228             QModelIndex sidx = m_tripleProxyModel->mapToSource(idx);
0229             ret << sidx;
0230         }
0231         return ret;
0232     }
0233 };
0234 
0235 
0236 KoDocumentRdfEditWidget::KoDocumentRdfEditWidget( KoDocumentRdf *docRdf)
0237     : d(new KoDocumentRdfEditWidgetPrivate(docRdf))
0238 {
0239     d->setupWidget();
0240 
0241     // setup stylesheet UI
0242     const QString buttonText = i18n("Set For All Existing");
0243     QGridLayout *styleSheetsGridLayout = d->m_ui->m_styleSheetsGridLayout;
0244     int row = 0;
0245     foreach (const QString &semanticItemName, KoRdfSemanticItemRegistry::instance()->classNames()) {
0246         if (KoRdfSemanticItemRegistry::instance()->isBasic(semanticItemName)) {
0247             continue;
0248         }
0249 
0250         QLabel *semanticItemLabel =
0251             new QLabel(KoRdfSemanticItemRegistry::instance()->classDisplayName(semanticItemName));
0252         styleSheetsGridLayout->addWidget(semanticItemLabel, row, 0, Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
0253 
0254         QComboBox *defaultStylesheetComboBox = new QComboBox;
0255         d->m_defaultStylesheetComboBoxMap.insert(semanticItemName, defaultStylesheetComboBox);
0256         styleSheetsGridLayout->addWidget(defaultStylesheetComboBox, row, 1);
0257 
0258         QPushButton *setStylesheetButton = new QPushButton(buttonText);
0259         setStylesheetButton->setProperty(SemanticItemClassId, semanticItemName);
0260         styleSheetsGridLayout->addWidget(setStylesheetButton, row, 2);
0261         connect(setStylesheetButton, SIGNAL(clicked()), SLOT(onDefaultSheetButtonClicked()));
0262 
0263     hKoRdfSemanticItem templateItem(static_cast<KoRdfSemanticItem *>(
0264         docRdf->createSemanticItem(semanticItemName, this).data()));
0265         d->buildComboBox(defaultStylesheetComboBox, templateItem);
0266 
0267         ++row;
0268     }
0269     QPushButton *setAllStylesheetsButton = new QPushButton(buttonText);
0270     // no semantic item plugins installed?
0271     if (row == 0) {
0272         setAllStylesheetsButton->setEnabled(false);
0273     }
0274     styleSheetsGridLayout->addWidget(setAllStylesheetsButton, row, 2);
0275     connect(setAllStylesheetsButton, SIGNAL(clicked()), SLOT(onDefaultAllSheetButtonClicked()));
0276 
0277 
0278     connect(d->m_ui->newTripleButton, SIGNAL(clicked()), this, SLOT(addTriple()));
0279     connect(d->m_ui->copyTripleButton, SIGNAL(clicked()), this, SLOT(copyTriples()));
0280     connect(d->m_ui->deleteTripleButton, SIGNAL(clicked()), this, SLOT(deleteTriples()));
0281     connect(d->m_ui->newNamespaceButton, SIGNAL(clicked()), this, SLOT(addNamespace()));
0282     connect(d->m_ui->deleteNamespaceButton, SIGNAL(clicked()), this, SLOT(deleteNamespace()));
0283     d->m_ui->m_semanticView->setContextMenuPolicy(Qt::CustomContextMenu);
0284     connect(d->m_ui->m_semanticView, SIGNAL(customContextMenuRequested(QPoint)),
0285             this, SLOT(showSemanticViewContextMenu(QPoint)));
0286     connect(d->m_ui->m_sparqlExecute, SIGNAL(clicked()), this, SLOT(sparqlExecute()));
0287 
0288     connect(docRdf, SIGNAL(semanticObjectUpdated(hKoRdfBasicSemanticItem)),
0289             this, SLOT(semanticObjectUpdated(hKoRdfBasicSemanticItem)));
0290 }
0291 
0292 KoDocumentRdfEditWidget::~KoDocumentRdfEditWidget()
0293 {
0294     delete d;
0295 }
0296 
0297 
0298 QWidget* KoDocumentRdfEditWidget::widget()
0299 {
0300     return d->m_widget;
0301 }
0302 
0303 bool KoDocumentRdfEditWidget::shouldDialogCloseBeVetoed()
0304 {
0305     bool ret = false;
0306     if (int invalidCount = d->m_tripleModel->invalidStatementCount()) {
0307         kDebug(30015) << "invalidCount:" << invalidCount;
0308         int dialogRet = KMessageBox::warningContinueCancel(
0309                     this, i18ncp("statement is an Rdf related term",
0310                                  "<qt>Edits will be lost.<p>There is %1 invalid statement left.</qt>",
0311                                  "<qt>Edits will be lost.<p>There are %1 invalid statements left.</qt>",
0312                                  invalidCount),
0313                     i18nc("statement is an Rdf related term", "Discard invalid statements?"),
0314                     KStandardGuiItem::cont(),
0315                     KStandardGuiItem::cancel(),
0316                     "InvalidTriplesInDocInfoDialog");
0317         if (dialogRet == KMessageBox::Cancel) {
0318             ret = true;
0319             QModelIndexList invalidList = d->m_tripleModel->invalidStatementList();
0320             if (!invalidList.isEmpty()) {
0321                 d->m_ui->m_tripleView->selectionModel()->clear();
0322                 foreach (QModelIndex idx, invalidList) {
0323                     QModelIndex pidx = d->mapFromSource(idx);
0324                     d->m_ui->m_tripleView->selectionModel()->select(
0325                                 pidx, QItemSelectionModel::Select);
0326                 }
0327 
0328                 QModelIndex pidx = d->mapFromSource(invalidList.first());
0329                 d->m_ui->m_tripleView->scrollTo(pidx);
0330             }
0331         }
0332         kDebug(30015) << "dialogRet:" << dialogRet << " ret:" << ret;
0333     }
0334     return ret;
0335 }
0336 
0337 void KoDocumentRdfEditWidget::apply()
0338 {
0339     KoDocumentRdf *rdf = d->m_rdf;
0340 
0341     QHash<QString, QComboBox*>::ConstIterator it = d->m_defaultStylesheetComboBoxMap.constBegin();
0342     QHash<QString, QComboBox*>::ConstIterator end = d->m_defaultStylesheetComboBoxMap.constEnd();
0343     for( ; it != end; ++it) {
0344         const QString &semanticClass = it.key();
0345         QComboBox *comboBox = it.value();
0346     hKoRdfSemanticItem si(static_cast<KoRdfSemanticItem *>(
0347         rdf->createSemanticItem(semanticClass).data()));
0348         si->defaultStylesheet(stylesheetFromComboBox(comboBox));
0349     }
0350 }
0351 
0352 QString KoDocumentRdfEditWidget::name() const
0353 {
0354     return i18n("Rdf");
0355 }
0356 
0357 QString KoDocumentRdfEditWidget::iconName() const
0358 {
0359     return koIconName("text-rdf");
0360 }
0361 
0362 void KoDocumentRdfEditWidget::semanticObjectUpdated(hKoRdfBasicSemanticItem item)
0363 {
0364     Q_UNUSED(item);
0365     kDebug(30015) << "updating the sem item list view";
0366     d->m_semanticItemsTree.update(d->m_rdf);
0367 }
0368 
0369 void KoDocumentRdfEditWidget::showSemanticViewContextMenu(const QPoint &position)
0370 {
0371     QPointer<KMenu> menu = new KMenu(0);
0372     QList<QAction*> actions;
0373     if (QTreeWidgetItem *baseitem = d->m_ui->m_semanticView->itemAt(position)) {
0374         if (KoRdfSemanticTreeWidgetItem *item = dynamic_cast<KoRdfSemanticTreeWidgetItem*>(baseitem)) {
0375             actions = item->actions(menu);
0376         }
0377     }
0378     if (actions.count() > 0) {
0379         foreach (QAction *a, actions) {
0380             menu->addAction(a);
0381         }
0382         menu->exec(d->m_ui->m_semanticView->mapToGlobal(position));
0383     }
0384     delete menu;
0385 }
0386 
0387 void KoDocumentRdfEditWidget::addTriple()
0388 {
0389     KoDocumentRdf *m_rdf = d->m_rdf;
0390     //
0391     // We have to make sure the new triple is unique, so the object
0392     // is set to a bnode value. Because the user most likely doesn't
0393     // want to create a bnode, we change it to a URI first.
0394     //
0395     Soprano::Node obj(QUrl(m_rdf->model()->createBlankNode().toString()));
0396     Soprano::Statement st(Soprano::Node(QUrl("http://calligra.org/new-node")),
0397                           Soprano::Node(QUrl("http://calligra.org/new-node")),
0398                           obj,
0399                           m_rdf->manifestRdfNode());
0400     int newRowNumber = d->m_tripleModel->insertStatement(st);
0401     QModelIndex pidx = d->mapFromSource(d->m_tripleModel->index(newRowNumber, 0));
0402     // select newrow
0403     d->clearTriplesSelection();
0404     d->selectTriples(pidx.row());
0405     d->m_ui->m_tripleView->scrollTo(pidx);
0406 }
0407 
0408 void KoDocumentRdfEditWidget::copyTriples()
0409 {
0410     QModelIndexList col = d->m_ui->m_tripleView->selectionModel()->selectedRows();
0411     QModelIndexList newRowsBackend = d->m_tripleModel->copyTriples(d->mapToSource(col));
0412     QModelIndexList newRows = d->mapFromSource(newRowsBackend);
0413     d->clearTriplesSelection();
0414     d->selectTriples(newRows);
0415     if (!newRows.isEmpty()) {
0416         d->m_ui->m_tripleView->scrollTo(newRows.first());
0417     }
0418 }
0419 
0420 void KoDocumentRdfEditWidget::deleteTriples()
0421 {
0422     QModelIndexList col = d->m_ui->m_tripleView->selectionModel()->selectedRows();
0423     d->m_tripleModel->deleteTriples(d->mapToSource(col));
0424 }
0425 
0426 void KoDocumentRdfEditWidget::addNamespace()
0427 {
0428     KoDocumentRdf *m_rdf = d->m_rdf;
0429     QTreeWidget *v = d->m_ui->m_namespaceView;
0430     QString key = QString("newnamespace%1").arg(QDateTime::currentDateTime().toTime_t());
0431     QString value = "http://www.example.com/fixme#";
0432     KoRdfPrefixMapping *mapping = m_rdf->prefixMapping();
0433     mapping->insert(key, value);
0434     kDebug(30015) << "adding key:" << key << " value:" << value;
0435     KoRdfPrefixMappingTreeWidgetItem* item =
0436             new KoRdfPrefixMappingTreeWidgetItem(mapping, key);
0437     v->addTopLevelItem(item);
0438     v->setCurrentItem(item);
0439     v->editItem(item);
0440 }
0441 
0442 void KoDocumentRdfEditWidget::deleteNamespace()
0443 {
0444     QTreeWidget *v = d->m_ui->m_namespaceView;
0445     QList<QTreeWidgetItem *> sel = v->selectedItems();
0446     kDebug(30015) << "selection.sz:" << sel.size();
0447     foreach (QTreeWidgetItem *item, sel) {
0448         if (KoRdfPrefixMappingTreeWidgetItem *ritem
0449                 = dynamic_cast<KoRdfPrefixMappingTreeWidgetItem *>(item)) {
0450             ritem->removeFromMapping();
0451         }
0452         v->invisibleRootItem()->removeChild(item);
0453     }
0454 }
0455 
0456 void KoDocumentRdfEditWidget::sparqlExecute()
0457 {
0458     d->m_ui->m_sparqlResultView->selectionModel()->clear();
0459     QString sparql = d->m_ui->m_sparqlQuery->toPlainText();
0460     QSharedPointer<Soprano::Model> m = d->m_rdf->model();
0461     kDebug(30015) << "running SPARQL query:" << sparql;
0462     Soprano::QueryResultIterator qrIter =
0463             m->executeQuery(sparql, Soprano::Query::QueryLanguageSparql);
0464     QList<Soprano::BindingSet> bindings = qrIter.allBindings();
0465     QTableWidget *tableWidget = d->m_ui->m_sparqlResultView;
0466     tableWidget->setSortingEnabled(false);
0467     tableWidget->setRowCount(bindings.size());
0468     int row = 0;
0469     int column = 0;
0470     QListIterator<Soprano::BindingSet> it(bindings);
0471     for (; it.hasNext(); column = 0, row++) {
0472         Soprano::BindingSet bs = it.next();
0473         QStringList bindingNames = bs.bindingNames();
0474         kDebug(30015) << "bindings.sz:" << bindingNames.size();
0475         if (row == 0) {
0476             tableWidget->setColumnCount(bindingNames.size());
0477             tableWidget->setHorizontalHeaderLabels(bindingNames);
0478         }
0479         foreach (const QString &b, bindingNames) {
0480             QString cellText = bs[b].toString();
0481             QTableWidgetItem *newItem = new QTableWidgetItem(cellText);
0482             tableWidget->setItem(row, column, newItem);
0483             kDebug(30015) << "r:" << row << " c:" << column << " data:" << cellText;
0484             ++column;
0485         }
0486     }
0487     tableWidget->setSortingEnabled(true);
0488 }
0489 
0490 hKoSemanticStylesheet KoDocumentRdfEditWidget::stylesheetFromComboBox(QComboBox *w) const
0491 {
0492     QAbstractItemModel *m = w->model();
0493     QVariant ud = m->data(m->index(w->currentIndex(), 0), Qt::UserRole);
0494     KoSemanticStylesheet *ss = ud.value<KoSemanticStylesheet*>();
0495     hKoSemanticStylesheet ret(ss);
0496     return ret;
0497 }
0498 
0499 void KoDocumentRdfEditWidget::applyStylesheetFromComboBox(QComboBox *comboBox) const
0500 {
0501     KoDocumentRdf *rdf = d->m_rdf;
0502     Q_ASSERT(rdf);
0503     QString stylesheetName = comboBox->currentText();
0504     kDebug(30015) << "changing default stylesheet to:" << stylesheetName;
0505     hKoSemanticStylesheet ss = stylesheetFromComboBox(comboBox);
0506     const QString semanticItemClass = comboBox->property(SemanticItemClassId).toString();
0507     hKoRdfSemanticItem si(static_cast<KoRdfSemanticItem *>(
0508     rdf->createSemanticItem(semanticItemClass).data()));
0509     if (si) {
0510         si->defaultStylesheet(ss);
0511     }
0512 
0513     QMap<int, KoDocumentRdf::reflowItem> reflowCol;
0514     const QList<hKoRdfSemanticItem> semanticItems = KoRdfSemanticItem::fromList(rdf->semanticItems(semanticItemClass));
0515     foreach (hKoRdfSemanticItem semanticItem, semanticItems) {
0516         rdf->insertReflow(reflowCol, semanticItem, ss);
0517     }
0518     rdf->applyReflow(reflowCol);
0519 }
0520 
0521 //
0522 // build a map end-pos -> { extent, semitem*, xmlid }
0523 // and apply in reverse order.
0524 //
0525 void KoDocumentRdfEditWidget::onDefaultSheetButtonClicked()
0526 {
0527     QPushButton *pushButton = qobject_cast<QPushButton*>(sender());
0528     Q_ASSERT(pushButton);
0529     const QString semanticItemClass = pushButton->property(SemanticItemClassId).toString();
0530     QComboBox *comboBox = d->m_defaultStylesheetComboBoxMap.value(semanticItemClass);
0531     Q_ASSERT(comboBox);
0532     applyStylesheetFromComboBox(comboBox);
0533 }
0534 
0535 void KoDocumentRdfEditWidget::onDefaultAllSheetButtonClicked()
0536 {
0537     foreach(QComboBox* comboBox, d->m_defaultStylesheetComboBoxMap) {
0538         applyStylesheetFromComboBox(comboBox);
0539     }
0540 }
0541 
0542 #include <KoDocumentRdfEditWidget.moc>