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 @@ ...@@ -6,7 +6,6 @@
#include <kumir2/editorinterface.h> #include <kumir2/editorinterface.h>
#include <kumir2-libs/widgets/iconprovider.h> #include <kumir2-libs/widgets/iconprovider.h>
#include <QUrl>
#include <QMenu> #include <QMenu>
#include <QScrollBar> #include <QScrollBar>
#include <QApplication> #include <QApplication>
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "contentrenderer.h" #include "contentrenderer.h"
#include <QtGlobal>
#include <QTextBrowser> #include <QTextBrowser>
class QMenu; class QMenu;
......
#ifndef DOCBOOKFACTORY_H #ifndef DOCBOOKFACTORY_H
#define DOCBOOKFACTORY_H #define DOCBOOKFACTORY_H
#include "docbookview.h"
#include "document.h" #include "document.h"
#include "docbookmodel.h" #include "docbookmodel.h"
// Qt includes
#include <QXmlDefaultHandler> #include <QXmlDefaultHandler>
#include <QXmlSimpleReader>
#include <QUrl>
#ifdef DOCBOOKVIEWER_LIBRARY #ifdef DOCBOOKVIEWER_LIBRARY
...@@ -17,76 +13,76 @@ ...@@ -17,76 +13,76 @@
#define EXTERN Q_DECL_IMPORT #define EXTERN Q_DECL_IMPORT
#endif #endif
namespace DocBookViewer { namespace DocBookViewer
{
class EXTERN DocBookFactory class EXTERN DocBookFactory : public QXmlDefaultHandler
: public QXmlDefaultHandler
{ {
public: public:
static DocBookFactory* self(); static DocBookFactory *self();
Document parseDocument(const QMap<ModelType,QString> roleValues, const QUrl & url, QString * error = 0) const; Document parseDocument(const QMap<ModelType, QString> roleValues, const QUrl &url, QString *error = 0) const;
static ModelPtr createListOfEntries(ModelPtr root, static ModelPtr createListOfEntries(ModelPtr root,
ModelType resType, ModelType resType,
ModelType findType ModelType findType
); );
static QMap<QString,ModelPtr> & static QMap<QString, ModelPtr> &
updateListOfAlgorithms(ModelPtr root, QMap<QString,ModelPtr> &result); updateListOfAlgorithms(ModelPtr root, QMap<QString, ModelPtr> &result);
static QMap<QString,ModelPtr> & static QMap<QString, ModelPtr> &
updateListOfKeywords(ModelPtr root, QMap<QString,ModelPtr> &result); updateListOfKeywords(ModelPtr root, QMap<QString, ModelPtr> &result);
Document createNamedSet(const QString &name, const QList<Document> documents) const; Document createNamedSet(const QString &name, const QList<Document> documents) const;
void setConfigurationName(const QString & configurationName); void setConfigurationName(const QString &configurationName);
private /*methods*/: private /*methods*/:
ModelPtr parseDocument( ModelPtr parseDocument(
const QMap<ModelType,QString> & roles, const QMap<ModelType, QString> &roles,
QIODevice * stream, QIODevice *stream,
const QUrl & url, const QUrl &url,
QString * error = 0) const; QString *error = 0) const;
explicit DocBookFactory(); explicit DocBookFactory();
bool startDocument(); bool startDocument();
bool startElement(const QString &namespaceURI, bool startElement(const QString &namespaceURI,
const QString &localName, const QString &localName,
const QString &qName, const QString &qName,
const QXmlAttributes &atts); const QXmlAttributes &atts);
bool characters(const QString &ch); bool characters(const QString &ch);
bool skippedEntity(const QString &name); bool skippedEntity(const QString &name);
bool endElement(const QString &namespaceURI, bool endElement(const QString &namespaceURI,
const QString &localName, const QString &localName,
const QString &qName); const QString &qName);
bool error(const QXmlParseException &exception); bool error(const QXmlParseException &exception);
bool fatalError(const QXmlParseException &exception); bool fatalError(const QXmlParseException &exception);
bool warning(const QXmlParseException &exception); bool warning(const QXmlParseException &exception);
void filterByOs(ModelPtr root) const; void filterByOs(ModelPtr root) const;
void filterByRoles(const QMap<ModelType,QString> & roles, void filterByRoles(const QMap<ModelType, QString> &roles,
ModelPtr root) const; ModelPtr root) const;
void filterByConfiguration(ModelPtr root) const; void filterByConfiguration(ModelPtr root) const;
static QList<ModelPtr> findEntriesOfType(ModelPtr root, static QList<ModelPtr> findEntriesOfType(ModelPtr root,
ModelType findType ModelType findType
); );
static QByteArray loadAndPreprocessSvg(const QString & fileName); static QByteArray loadAndPreprocessSvg(const QString &fileName);
static QImage loadAndPreprocessPng(const QString & fileName); static QImage loadAndPreprocessPng(const QString &fileName);
private /*fields*/: private /*fields*/:
mutable QXmlSimpleReader* reader_; mutable QXmlSimpleReader *reader_;
mutable ModelPtr doc_; mutable ModelPtr doc_;
mutable QUrl url_; mutable QUrl url_;
mutable QMap<ModelType,QString> roles_; mutable QMap<ModelType, QString> roles_;
ModelPtr root_; ModelPtr root_;
QString buffer_; QString buffer_;
QString configurationName_; QString configurationName_;
}; };
......
#include "docbookmodel.h" #include "docbookmodel.h"
#include "contentrenderer.h"
#include <QImage>
#include <QPainter> #include <QPainter>
namespace DocBookViewer { namespace DocBookViewer
{
DocBookModel::DocBookModel(ModelPtr parent, const ModelType modelType) DocBookModel::DocBookModel(ModelPtr parent, const ModelType modelType)
: parent_(parent) : parent_(parent)
, modelType_(modelType) , modelType_(modelType)
, sectionLevel_(0) , sectionLevel_(0)
{ {
updateSectionLevel(); updateSectionLevel();
} }
quint8 DocBookModel::sectionLevel() const quint8 DocBookModel::sectionLevel() const
{ {
return sectionLevel_; return sectionLevel_;
} }
ModelType DocBookModel::modelType() const 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 QString DocBookModel::titleAbbrev() const
{ {
if (titleAbbrev_.isEmpty()) if (titleAbbrev_.isEmpty()) {
return title_; return title_;
else } else {
return titleAbbrev_; 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 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 ModelPtr DocBookModel::parent() const
{ {
return parent_; return parent_;
} }
ModelPtr DocBookModel::indexParent() const ModelPtr DocBookModel::indexParent() const
{ {
return indexParent_; return indexParent_;
} }
ModelPtr DocBookModel::findChildrenOfType(const ModelType modelType) const ModelPtr DocBookModel::findChildrenOfType(const ModelType modelType) const
{ {
ModelPtr result; ModelPtr result;
foreach (ModelPtr child, children_) { foreach (ModelPtr child, children_) {
if (modelType == child->modelType()) { if (modelType == child->modelType()) {
result = child; result = child;
} } else {
else { result = child->findChildrenOfType(modelType);
result = child->findChildrenOfType(modelType); }
} if (result) {
if (result) break; break;
} }
return result; }
return result;
} }
const QList<ModelPtr>& DocBookModel::children() const const QList<ModelPtr> &DocBookModel::children() const
{ {
return children_; return children_;
} }
ModelPtr DocBookModel::self() const ModelPtr DocBookModel::self() const
{ {
ModelPtr result; ModelPtr result;
if (parent()) { if (parent()) {
foreach (ModelPtr child, parent()->children()) { foreach (ModelPtr child, parent()->children()) {
if (child.data() == this) { if (child.data() == this) {
result = child; result = child;
break; break;
} }
} }
} }
if (!result) foreach (ModelPtr child, children()) { if (!result)
if (child->parent().data() == this) { foreach (ModelPtr child, children()) {
result = child->parent(); if (child->parent().data() == this) {
break; result = child->parent();
} break;
} }
return result; }
return result;
} }
bool DocBookModel::isSectioningNode() const bool DocBookModel::isSectioningNode() const
{ {
if (title_.length() == 0) { if (title_.length() == 0) {
return false; return false;
} } else if (modelType_ == Section) {
else if (modelType_ == Section) { return sectionLevel_ <= MAX_SECTION_LEVEL_IN_TOC;
return sectionLevel_ <= MAX_SECTION_LEVEL_IN_TOC; } else {
} return
else { modelType_ == Book ||
return modelType_ == Book || modelType_ == Article ||
modelType_ == Article || modelType_ == Set ||
modelType_ == Set || modelType_ == Chapter ||
modelType_ == Chapter || modelType_ == Preface ||
modelType_ == Preface || modelType_ == Reference ||
modelType_ == Reference || modelType_ == Abstract;
modelType_ == Abstract; }
}
} }
void DocBookModel::updateSectionLevel() void DocBookModel::updateSectionLevel()
{ {
if (modelType_ != Section) { if (modelType_ != Section) {
sectionLevel_ = 0u; sectionLevel_ = 0u;
} } else {
else { ModelPtr p = parent_;
ModelPtr p = parent_; sectionLevel_ = 1u;
sectionLevel_ = 1u; while (p && p->modelType_ == Section) {
while (p && p->modelType_ == Section) { p = p->parent();
p = p->parent(); sectionLevel_ ++;
sectionLevel_ ++; }
} }
} foreach (ModelPtr child, children_) {
foreach (ModelPtr child, children_) { child->updateSectionLevel();
child->updateSectionLevel(); }
} }
}
const QImage &DocBookModel::imageData() const
const QImage& DocBookModel::imageData() const {
{ if (svgRenderer_ && cachedImage_.isNull()) {
if (svgRenderer_ && cachedImage_.isNull()) { const QSize size = svgRenderer_->defaultSize();
const QSize size = svgRenderer_->defaultSize(); QImage img(size, QImage::Format_ARGB32);
QImage img(size, QImage::Format_ARGB32); img.fill(0);
img.fill(0); QPainter painter(&img);
QPainter painter(&img); svgRenderer_->render(&painter);
svgRenderer_->render(&painter); cachedImage_ = img;
cachedImage_ = img; }
} return cachedImage_;
return cachedImage_;
} }
} }
...@@ -5,10 +5,7 @@ ...@@ -5,10 +5,7 @@
#include "modeltype.h" #include "modeltype.h"
// Qt includes // Qt includes
#include <QtGlobal>
#include <QString>
#include <QUrl> #include <QUrl>
#include <QObject>
#include <QSharedPointer> #include <QSharedPointer>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <QImage> #include <QImage>
......
...@@ -4,144 +4,145 @@ ...@@ -4,144 +4,145 @@
#include <QResizeEvent> #include <QResizeEvent>
#include <QDebug> #include <QDebug>
namespace DocBookViewer { namespace DocBookViewer
{
DocBookView::DocBookView(QWidget *parent) DocBookView::DocBookView(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, pImpl_(new DocBookViewImpl(this)) , pImpl_(new DocBookViewImpl(this))
{ {
} }
void DocBookView::updateSettings(ExtensionSystem::SettingsPtr settings, const QString &prefix) 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_) { if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_); pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
} }
QWidget::closeEvent(event); QWidget::closeEvent(event);
} }
void DocBookView::hideEvent(QHideEvent * event) void DocBookView::hideEvent(QHideEvent *event)
{ {
if (pImpl_->settings_) { if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_); pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
}