Commit 6b0ddf4c authored by Alexander A. Maly's avatar Alexander A. Maly

Astyled DocBookViewer

parent 51f174af
Pipeline #2579 failed with stages
in 2 minutes and 4 seconds
......@@ -6,7 +6,6 @@
#include <kumir2/editorinterface.h>
#include <kumir2-libs/widgets/iconprovider.h>
#include <QUrl>
#include <QMenu>
#include <QScrollBar>
#include <QApplication>
......
......@@ -3,7 +3,6 @@
#include "contentrenderer.h"
#include <QtGlobal>
#include <QTextBrowser>
class QMenu;
......
#ifndef DOCBOOKFACTORY_H
#define DOCBOOKFACTORY_H
#include "docbookview.h"
#include "document.h"
#include "docbookmodel.h"
// Qt includes
#include <QXmlDefaultHandler>
#include <QXmlSimpleReader>
#include <QUrl>
#ifdef DOCBOOKVIEWER_LIBRARY
......@@ -17,76 +13,76 @@
#define EXTERN Q_DECL_IMPORT
#endif
namespace DocBookViewer {
namespace DocBookViewer
{
class EXTERN DocBookFactory
: public QXmlDefaultHandler
class EXTERN DocBookFactory : public QXmlDefaultHandler
{
public:
static DocBookFactory* self();
Document parseDocument(const QMap<ModelType,QString> roleValues, const QUrl & url, QString * error = 0) const;
static ModelPtr createListOfEntries(ModelPtr root,
ModelType resType,
ModelType findType
);
static QMap<QString,ModelPtr> &
updateListOfAlgorithms(ModelPtr root, QMap<QString,ModelPtr> &result);
static DocBookFactory *self();
Document parseDocument(const QMap<ModelType, QString> roleValues, const QUrl &url, QString *error = 0) const;
static ModelPtr createListOfEntries(ModelPtr root,
ModelType resType,
ModelType findType
);
static QMap<QString, ModelPtr> &
updateListOfAlgorithms(ModelPtr root, QMap<QString, ModelPtr> &result);
static QMap<QString,ModelPtr> &
updateListOfKeywords(ModelPtr root, QMap<QString,ModelPtr> &result);
static QMap<QString, ModelPtr> &
updateListOfKeywords(ModelPtr root, QMap<QString, ModelPtr> &result);
Document createNamedSet(const QString &name, const QList<Document> documents) const;
void setConfigurationName(const QString & configurationName);
Document createNamedSet(const QString &name, const QList<Document> documents) const;
void setConfigurationName(const QString &configurationName);
private /*methods*/:
ModelPtr parseDocument(
const QMap<ModelType,QString> & roles,
QIODevice * stream,
const QUrl & url,
QString * error = 0) const;
explicit DocBookFactory();
bool startDocument();
bool startElement(const QString &namespaceURI,
const QString &localName,
const QString &qName,
const QXmlAttributes &atts);
bool characters(const QString &ch);
bool skippedEntity(const QString &name);
bool endElement(const QString &namespaceURI,
const QString &localName,
const QString &qName);
bool error(const QXmlParseException &exception);
bool fatalError(const QXmlParseException &exception);
bool warning(const QXmlParseException &exception);
void filterByOs(ModelPtr root) const;
void filterByRoles(const QMap<ModelType,QString> & roles,
ModelPtr root) const;
void filterByConfiguration(ModelPtr root) const;
static QList<ModelPtr> findEntriesOfType(ModelPtr root,
ModelType findType
);
static QByteArray loadAndPreprocessSvg(const QString & fileName);
static QImage loadAndPreprocessPng(const QString & fileName);
ModelPtr parseDocument(
const QMap<ModelType, QString> &roles,
QIODevice *stream,
const QUrl &url,
QString *error = 0) const;
explicit DocBookFactory();
bool startDocument();
bool startElement(const QString &namespaceURI,
const QString &localName,
const QString &qName,
const QXmlAttributes &atts);
bool characters(const QString &ch);
bool skippedEntity(const QString &name);
bool endElement(const QString &namespaceURI,
const QString &localName,
const QString &qName);
bool error(const QXmlParseException &exception);
bool fatalError(const QXmlParseException &exception);
bool warning(const QXmlParseException &exception);
void filterByOs(ModelPtr root) const;
void filterByRoles(const QMap<ModelType, QString> &roles,
ModelPtr root) const;
void filterByConfiguration(ModelPtr root) const;
static QList<ModelPtr> findEntriesOfType(ModelPtr root,
ModelType findType
);
static QByteArray loadAndPreprocessSvg(const QString &fileName);
static QImage loadAndPreprocessPng(const QString &fileName);
private /*fields*/:
mutable QXmlSimpleReader* reader_;
mutable ModelPtr doc_;
mutable QUrl url_;
mutable QMap<ModelType,QString> roles_;
ModelPtr root_;
QString buffer_;
QString configurationName_;
mutable QXmlSimpleReader *reader_;
mutable ModelPtr doc_;
mutable QUrl url_;
mutable QMap<ModelType, QString> roles_;
ModelPtr root_;
QString buffer_;
QString configurationName_;
};
......
#include "docbookmodel.h"
#include "contentrenderer.h"
#include <QImage>
#include <QPainter>
namespace DocBookViewer {
namespace DocBookViewer
{
DocBookModel::DocBookModel(ModelPtr parent, const ModelType modelType)
: parent_(parent)
, modelType_(modelType)
, sectionLevel_(0)
: parent_(parent)
, modelType_(modelType)
, sectionLevel_(0)
{
updateSectionLevel();
updateSectionLevel();
}
quint8 DocBookModel::sectionLevel() const
{
return sectionLevel_;
return sectionLevel_;
}
ModelType DocBookModel::modelType() const
{
return modelType_;
return modelType_;
}
const QString& DocBookModel::id() const
const QString &DocBookModel::id() const
{
return id_;
return id_;
}
const QString& DocBookModel::title() const
const QString &DocBookModel::title() const
{
return title_;
return title_;
}
QString DocBookModel::titleAbbrev() const
{
if (titleAbbrev_.isEmpty())
return title_;
else
return titleAbbrev_;
if (titleAbbrev_.isEmpty()) {
return title_;
} else {
return titleAbbrev_;
}
}
const QString& DocBookModel::subtitle() const
const QString &DocBookModel::subtitle() const
{
return subtitle_;
return subtitle_;
}
const QString& DocBookModel::text() const
const QString &DocBookModel::text() const
{
return text_;
return text_;
}
const QString& DocBookModel::role() const
const QString &DocBookModel::role() const
{
return role_;
return role_;
}
const QString& DocBookModel::xrefLinkEnd() const
const QString &DocBookModel::xrefLinkEnd() const
{
return xrefLinkEnd_;
return xrefLinkEnd_;
}
const QString& DocBookModel::xrefEndTerm() const
const QString &DocBookModel::xrefEndTerm() const
{
return xrefEndTerm_;
return xrefEndTerm_;
}
const QString DocBookModel::format() const
{
return format_.toLower().trimmed();
return format_.toLower().trimmed();
}
const QUrl& DocBookModel::href() const
const QUrl &DocBookModel::href() const
{
return href_;
return href_;
}
ModelPtr DocBookModel::parent() const
{
return parent_;
return parent_;
}
ModelPtr DocBookModel::indexParent() const
{
return indexParent_;
return indexParent_;
}
ModelPtr DocBookModel::findChildrenOfType(const ModelType modelType) const
{
ModelPtr result;
foreach (ModelPtr child, children_) {
if (modelType == child->modelType()) {
result = child;
}
else {
result = child->findChildrenOfType(modelType);
}
if (result) break;
}
return result;
ModelPtr result;
foreach (ModelPtr child, children_) {
if (modelType == child->modelType()) {
result = child;
} else {
result = child->findChildrenOfType(modelType);
}
if (result) {
break;
}
}
return result;
}
const QList<ModelPtr>& DocBookModel::children() const
const QList<ModelPtr> &DocBookModel::children() const
{
return children_;
return children_;
}
ModelPtr DocBookModel::self() const
{
ModelPtr result;
if (parent()) {
foreach (ModelPtr child, parent()->children()) {
if (child.data() == this) {
result = child;
break;
}
}
}
if (!result) foreach (ModelPtr child, children()) {
if (child->parent().data() == this) {
result = child->parent();
break;
}
}
return result;
ModelPtr result;
if (parent()) {
foreach (ModelPtr child, parent()->children()) {
if (child.data() == this) {
result = child;
break;
}
}
}
if (!result)
foreach (ModelPtr child, children()) {
if (child->parent().data() == this) {
result = child->parent();
break;
}
}
return result;
}
bool DocBookModel::isSectioningNode() const
{
if (title_.length() == 0) {
return false;
}
else if (modelType_ == Section) {
return sectionLevel_ <= MAX_SECTION_LEVEL_IN_TOC;
}
else {
return modelType_ == Book ||
modelType_ == Article ||
modelType_ == Set ||
modelType_ == Chapter ||
modelType_ == Preface ||
modelType_ == Reference ||
modelType_ == Abstract;
}
if (title_.length() == 0) {
return false;
} else if (modelType_ == Section) {
return sectionLevel_ <= MAX_SECTION_LEVEL_IN_TOC;
} else {
return
modelType_ == Book ||
modelType_ == Article ||
modelType_ == Set ||
modelType_ == Chapter ||
modelType_ == Preface ||
modelType_ == Reference ||
modelType_ == Abstract;
}
}
void DocBookModel::updateSectionLevel()
{
if (modelType_ != Section) {
sectionLevel_ = 0u;
}
else {
ModelPtr p = parent_;
sectionLevel_ = 1u;
while (p && p->modelType_ == Section) {
p = p->parent();
sectionLevel_ ++;
}
}
foreach (ModelPtr child, children_) {
child->updateSectionLevel();
}
}
const QImage& DocBookModel::imageData() const
{
if (svgRenderer_ && cachedImage_.isNull()) {
const QSize size = svgRenderer_->defaultSize();
QImage img(size, QImage::Format_ARGB32);
img.fill(0);
QPainter painter(&img);
svgRenderer_->render(&painter);
cachedImage_ = img;
}
return cachedImage_;
if (modelType_ != Section) {
sectionLevel_ = 0u;
} else {
ModelPtr p = parent_;
sectionLevel_ = 1u;
while (p && p->modelType_ == Section) {
p = p->parent();
sectionLevel_ ++;
}
}
foreach (ModelPtr child, children_) {
child->updateSectionLevel();
}
}
const QImage &DocBookModel::imageData() const
{
if (svgRenderer_ && cachedImage_.isNull()) {
const QSize size = svgRenderer_->defaultSize();
QImage img(size, QImage::Format_ARGB32);
img.fill(0);
QPainter painter(&img);
svgRenderer_->render(&painter);
cachedImage_ = img;
}
return cachedImage_;
}
}
......@@ -5,10 +5,7 @@
#include "modeltype.h"
// Qt includes
#include <QtGlobal>
#include <QString>
#include <QUrl>
#include <QObject>
#include <QSharedPointer>
#include <QSvgRenderer>
#include <QImage>
......
......@@ -4,144 +4,145 @@
#include <QResizeEvent>
#include <QDebug>
namespace DocBookViewer {
namespace DocBookViewer
{
DocBookView::DocBookView(QWidget *parent)
: QWidget(parent)
, pImpl_(new DocBookViewImpl(this))
: QWidget(parent)
, pImpl_(new DocBookViewImpl(this))
{
}
void DocBookView::updateSettings(ExtensionSystem::SettingsPtr settings, const QString &prefix)
{
pImpl_->updateSettings(settings, prefix);
pImpl_->updateSettings(settings, prefix);
}
void DocBookView::closeEvent(QCloseEvent * event)
void DocBookView::closeEvent(QCloseEvent *event)
{
if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
}
QWidget::closeEvent(event);
if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
}
QWidget::closeEvent(event);
}
void DocBookView::hideEvent(QHideEvent * event)
void DocBookView::hideEvent(QHideEvent *event)
{
if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
}
QWidget::hideEvent(event);
if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
}
QWidget::hideEvent(event);
}
void DocBookView::showEvent(QShowEvent * event)
void DocBookView::showEvent(QShowEvent *event)
{
if (pImpl_->settings_) {
pImpl_->restoreState(pImpl_->settings_, pImpl_->settingsPrefix_);
}
QWidget::showEvent(event);
if (pImpl_->settings_) {
pImpl_->restoreState(pImpl_->settings_, pImpl_->settingsPrefix_);
}
QWidget::showEvent(event);
}
void DocBookView::resizeEvent(QResizeEvent * event)
void DocBookView::resizeEvent(QResizeEvent *event)
{
if (event->size().width() < minimumWidth() ||
event->size().height() < minimumHeight()) {
event->ignore();
}
else {
event->accept();
pImpl_->setSize(event->size());
}
if (event->size().width() < minimumWidth() ||
event->size().height() < minimumHeight()) {
event->ignore();
} else {
event->accept();
pImpl_->setSize(event->size());
}
}
DocBookView::~DocBookView()
{
delete pImpl_;
delete pImpl_;
}
QAction * DocBookView::viewerAction(const DocBookViewAction type) const
QAction *DocBookView::viewerAction(const DocBookViewAction type) const
{
return pImpl_->viewerAction(type);
return pImpl_->viewerAction(type);
}
Document DocBookView::addDocument(const QUrl &url, QString *error)
{
return pImpl_->addDocument(url, error);
return pImpl_->addDocument(url, error);
}
Document DocBookView::addDocuments(const QString &groupName, const QList<QUrl> &urls, QString *error)
{
return pImpl_->addDocuments(groupName, urls, error);
return pImpl_->addDocuments(groupName, urls, error);
}
void DocBookView::removeDocument(const Document & existingDocument)
void DocBookView::removeDocument(const Document &existingDocument)
{
pImpl_->removeDocument(existingDocument);
pImpl_->removeDocument(existingDocument);
}
QSize DocBookView::minimumSizeHint() const
{
return pImpl_->minimumSizeHint();
return pImpl_->minimumSizeHint();
}
QSize DocBookView::sizeHint() const
{
return pImpl_->sizeHint();
return pImpl_->sizeHint();