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,36 +13,36 @@
#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 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> &
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);
void setConfigurationName(const QString &configurationName);
private /*methods*/:
ModelPtr parseDocument(
const QMap<ModelType,QString> & roles,
QIODevice * stream,
const QUrl & url,
QString * error = 0) const;
const QMap<ModelType, QString> &roles,
QIODevice *stream,
const QUrl &url,
QString *error = 0) const;
explicit DocBookFactory();
......@@ -66,7 +62,7 @@ private /*methods*/:
bool warning(const QXmlParseException &exception);
void filterByOs(ModelPtr root) const;
void filterByRoles(const QMap<ModelType,QString> & roles,
void filterByRoles(const QMap<ModelType, QString> &roles,
ModelPtr root) const;
void filterByConfiguration(ModelPtr root) const;
......@@ -74,15 +70,15 @@ private /*methods*/:
ModelType findType
);
static QByteArray loadAndPreprocessSvg(const QString & fileName);
static QImage loadAndPreprocessPng(const QString & fileName);
static QByteArray loadAndPreprocessSvg(const QString &fileName);
static QImage loadAndPreprocessPng(const QString &fileName);
private /*fields*/:
mutable QXmlSimpleReader* reader_;
mutable QXmlSimpleReader *reader_;
mutable ModelPtr doc_;
mutable QUrl url_;
mutable QMap<ModelType,QString> roles_;
mutable QMap<ModelType, QString> roles_;
ModelPtr root_;
QString buffer_;
......
#include "docbookmodel.h"
#include "contentrenderer.h"
#include <QImage>
#include <QPainter>
namespace DocBookViewer {
namespace DocBookViewer
{
DocBookModel::DocBookModel(ModelPtr parent, const ModelType modelType)
: parent_(parent)
......@@ -25,45 +24,46 @@ ModelType DocBookModel::modelType() const
return modelType_;
}
const QString& DocBookModel::id() const
const QString &DocBookModel::id() const
{
return id_;
}
const QString& DocBookModel::title() const
const QString &DocBookModel::title() const
{
return title_;
}
QString DocBookModel::titleAbbrev() const
{
if (titleAbbrev_.isEmpty())
if (titleAbbrev_.isEmpty()) {
return title_;
else
} else {
return titleAbbrev_;
}
}
const QString& DocBookModel::subtitle() const
const QString &DocBookModel::subtitle() const
{
return subtitle_;
}
const QString& DocBookModel::text() const
const QString &DocBookModel::text() const
{
return text_;
}
const QString& DocBookModel::role() const
const QString &DocBookModel::role() const
{
return role_;
}
const QString& DocBookModel::xrefLinkEnd() const
const QString &DocBookModel::xrefLinkEnd() const
{
return xrefLinkEnd_;
}
const QString& DocBookModel::xrefEndTerm() const
const QString &DocBookModel::xrefEndTerm() const
{
return xrefEndTerm_;
}
......@@ -73,7 +73,7 @@ const QString DocBookModel::format() const
return format_.toLower().trimmed();
}
const QUrl& DocBookModel::href() const
const QUrl &DocBookModel::href() const
{
return href_;
}
......@@ -94,16 +94,17 @@ ModelPtr DocBookModel::findChildrenOfType(const ModelType modelType) const
foreach (ModelPtr child, children_) {
if (modelType == child->modelType()) {
result = child;
}
else {
} else {
result = child->findChildrenOfType(modelType);
}
if (result) break;
if (result) {
break;
}
}
return result;
}
const QList<ModelPtr>& DocBookModel::children() const
const QList<ModelPtr> &DocBookModel::children() const
{
return children_;
}
......@@ -119,7 +120,8 @@ ModelPtr DocBookModel::self() const
}
}
}
if (!result) foreach (ModelPtr child, children()) {
if (!result)
foreach (ModelPtr child, children()) {
if (child->parent().data() == this) {
result = child->parent();
break;
......@@ -132,12 +134,11 @@ bool DocBookModel::isSectioningNode() const
{
if (title_.length() == 0) {
return false;
}
else if (modelType_ == Section) {
} else if (modelType_ == Section) {
return sectionLevel_ <= MAX_SECTION_LEVEL_IN_TOC;
}
else {
return modelType_ == Book ||
} else {
return
modelType_ == Book ||
modelType_ == Article ||
modelType_ == Set ||
modelType_ == Chapter ||
......@@ -151,8 +152,7 @@ void DocBookModel::updateSectionLevel()
{
if (modelType_ != Section) {
sectionLevel_ = 0u;
}
else {
} else {
ModelPtr p = parent_;
sectionLevel_ = 1u;
while (p && p->modelType_ == Section) {
......@@ -165,7 +165,7 @@ void DocBookModel::updateSectionLevel()
}
}
const QImage& DocBookModel::imageData() const
const QImage &DocBookModel::imageData() const
{
if (svgRenderer_ && cachedImage_.isNull()) {
const QSize size = svgRenderer_->defaultSize();
......
......@@ -5,10 +5,7 @@
#include "modeltype.h"
// Qt includes
#include <QtGlobal>
#include <QString>
#include <QUrl>
#include <QObject>
#include <QSharedPointer>
#include <QSvgRenderer>
#include <QImage>
......
......@@ -4,7 +4,8 @@
#include <QResizeEvent>
#include <QDebug>
namespace DocBookViewer {
namespace DocBookViewer
{
DocBookView::DocBookView(QWidget *parent)
: QWidget(parent)
......@@ -18,7 +19,7 @@ void DocBookView::updateSettings(ExtensionSystem::SettingsPtr settings, const QS
pImpl_->updateSettings(settings, prefix);
}
void DocBookView::closeEvent(QCloseEvent * event)
void DocBookView::closeEvent(QCloseEvent *event)
{
if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
......@@ -26,7 +27,7 @@ void DocBookView::closeEvent(QCloseEvent * event)
QWidget::closeEvent(event);
}
void DocBookView::hideEvent(QHideEvent * event)
void DocBookView::hideEvent(QHideEvent *event)
{
if (pImpl_->settings_) {
pImpl_->saveState(pImpl_->settings_, pImpl_->settingsPrefix_);
......@@ -34,7 +35,7 @@ void DocBookView::hideEvent(QHideEvent * event)
QWidget::hideEvent(event);
}
void DocBookView::showEvent(QShowEvent * event)
void DocBookView::showEvent(QShowEvent *event)
{
if (pImpl_->settings_) {
pImpl_->restoreState(pImpl_->settings_, pImpl_->settingsPrefix_);
......@@ -42,13 +43,12 @@ void DocBookView::showEvent(QShowEvent * event)
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 {
} else {
event->accept();
pImpl_->setSize(event->size());
}
......@@ -60,7 +60,7 @@ DocBookView::~DocBookView()
delete pImpl_;
}
QAction * DocBookView::viewerAction(const DocBookViewAction type) const
QAction *DocBookView::viewerAction(const DocBookViewAction type) const
{
return pImpl_->viewerAction(type);
}
......@@ -75,7 +75,7 @@ Document DocBookView::addDocuments(const QString &groupName, const QList<QUrl> &
return pImpl_->addDocuments(groupName, urls, error);
}
void DocBookView::removeDocument(const Document & existingDocument)
void DocBookView::removeDocument(const Document &existingDocument)
{
pImpl_->removeDocument(existingDocument);
}
......@@ -95,7 +95,7 @@ bool DocBookView::hasAlgorithm(const QString &name) const
return pImpl_->hasAlgorithm(name);
}
void DocBookView::navigateToApiFunction(const QString &package, const QString & function)
void DocBookView::navigateToApiFunction(const QString &package, const QString &function)
{
pImpl_->navigateToApiFunction(package, function);
}
......@@ -108,10 +108,11 @@ void DocBookView::navigateToIndex(const QString &index)
void DocBookView::navigateFromQuickReference(const int topicType, const QString &name)
{
qDebug() << "navigateFromQuickReference(" << topicType << ", " << name << ")";
if (2 == topicType)
if (2 == topicType) {
navigateToApiFunction("", name);
else
} else {
navigateToIndex(name);
}
}
void DocBookView::clearNavigationFilters()
......
......@@ -12,7 +12,6 @@
#include <QString>
#include <QWidget>
#include <QUrl>
#include <QSettings>
#ifdef DOCBOOKVIEWER_LIBRARY
#define EXTERN_LIB Q_DECL_EXPORT
......@@ -20,10 +19,10 @@
#define EXTERN_LIB Q_DECL_IMPORT
#endif
namespace DocBookViewer {
namespace DocBookViewer
{
class EXTERN_LIB DocBookView
: public QWidget
class EXTERN_LIB DocBookView : public QWidget
{
Q_OBJECT
public:
......@@ -33,21 +32,21 @@ public:
ShowPrintDialog
};
explicit DocBookView(QWidget * parent = 0);
QAction * viewerAction(const DocBookViewAction type) const;
explicit DocBookView(QWidget *parent = 0);
QAction *viewerAction(const DocBookViewAction type) const;
QStringList booksList() const;
void activateBookIndex(int index);
void updateSettings(ExtensionSystem::SettingsPtr settings, const QString & prefix);
bool hasAlgorithm(const QString & name) const;
void navigateToApiFunction(const QString & package, const QString & function);
void navigateToIndex(const QString & index);
void updateSettings(ExtensionSystem::SettingsPtr settings, const QString &prefix);
bool hasAlgorithm(const QString &name) const;
void navigateToApiFunction(const QString &package, const QString &function);
void navigateToIndex(const QString &index);
void navigateFromQuickReference(const int topicType, const QString &name);
void clearNavigationFilters();
void setInitialView();
void setRole(ModelType category, const QString & value);
void setRole(ModelType category, const QString &value);
QString role(ModelType category) const;
QSize minimumSizeHint() const;
......@@ -55,10 +54,10 @@ public:
~DocBookView();
Document addDocument(const QUrl & url, QString * error = 0);
Document addDocuments(const QString & groupName, const QList<QUrl> & urls, QString * error = 0);
Document addDocument(const QUrl &url, QString *error = 0);
Document addDocuments(const QString &groupName, const QList<QUrl> &urls, QString *error = 0);
void removeDocument(const Document & existingDocument);
void removeDocument(const Document &existingDocument);
protected:
void showEvent(QShowEvent *);
......@@ -67,7 +66,7 @@ protected:
void resizeEvent(QResizeEvent *);
private:
class DocBookViewImpl* pImpl_;
class DocBookViewImpl *pImpl_;
};
}
......
// Self includes
#include "docbookview_impl.h"
#include "contentview.h"
#include "document.h"
#include "docbookfactory.h"
#include "docbookmodel.h"
#include "printdialog.h"
......@@ -9,14 +8,14 @@
#include "sidepanel.h"
// Qt includes
#include <QtCore>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
#include <QSplitter>
#include <QLabel>
#include <QStackedWidget>
#include <QLayout>
#include <QAction>
namespace DocBookViewer {
namespace DocBookViewer
{
DocBookViewImpl::DocBookViewImpl(DocBookView *pClass)
: QObject(pClass)
......@@ -86,7 +85,7 @@ void DocBookViewImpl::updateToggleSideBarButton()
static const QString Hide = tr("Hide side bar");
static const QString Show = tr("Show side bar");
const QString & text = isSideBarVisible() ? Hide : Show;
const QString &text = isSideBarVisible() ? Hide : Show;
const QString action = isSideBarVisible() ? "#hide" : "#show";
const QString html = QString("<a href=\"%1\">%2</a>").arg(action).arg(text);
......@@ -104,10 +103,9 @@ bool DocBookViewImpl::isSideBarVisible() const
void DocBookViewImpl::handleShowSideBarButton(const QString &action)
{
if (action=="#show") {
if (action == "#show") {
showSidePanel();
}
else if (action=="#hide") {
} else if (action == "#hide") {
hideSidePanel();
}
}
......@@ -124,8 +122,7 @@ void DocBookViewImpl::setSize(const QSize &size)
background_->resize(size);
if (size.width() < minWidth) {
// switchToCompactMode();
}
else {
} else {
switchToEnoughtSizeMode();
}
updateToggleSideBarButton();
......@@ -133,8 +130,9 @@ void DocBookViewImpl::setSize(const QSize &size)
void DocBookViewImpl::switchToCompactMode(bool force)
{
if (compactModeFlag_ && !force)
if (compactModeFlag_ && !force) {
return;
}
compactModeFlag_ = true;
splitterRightWidget_->setCurrentIndex(0);
smallSizeContainer_->layout()->addWidget(content_);
......@@ -145,8 +143,9 @@ void DocBookViewImpl::switchToCompactMode(bool force)
void DocBookViewImpl::switchToEnoughtSizeMode(bool force)
{
if (!compactModeFlag_ && !force)
if (!compactModeFlag_ && !force) {
return;
}
compactModeFlag_ = false;
splitterRightWidget_->setCurrentIndex(1);
enoughtSizeContainer_->layout()->addWidget(content_);
......@@ -157,10 +156,11 @@ void DocBookViewImpl::switchToEnoughtSizeMode(bool force)
void DocBookViewImpl::hideSidePanel()
{
if (compactModeFlag_)
if (compactModeFlag_) {
splitter_->setVisible(false);
else
} else {
sidePanel_->setVisible(false);
}
updateToggleSideBarButton();
background_->setVisible(false);
enoughtSizeContainer_->layout()->setContentsMargins(0, 24, 0, 0);
......@@ -226,10 +226,11 @@ void DocBookViewImpl::restoreState(ExtensionSystem::SettingsPtr settings, const
.toByteArray());
sidePanel_->restoreState(settings, prefix + "/SideBar");
setSize(pClass_->size());
if (settings->value(prefix + "/CompactMode").toBool())
if (settings->value(prefix + "/CompactMode").toBool()) {
switchToCompactMode(true);
else
} else {
switchToEnoughtSizeMode(true);
}
}
......@@ -243,12 +244,11 @@ void DocBookViewImpl::createActions()
this, SLOT(showPrintDialog()));
}
QAction * DocBookViewImpl::viewerAction(const DocBookView::DocBookViewAction type) const
QAction *DocBookViewImpl::viewerAction(const DocBookView::DocBookViewAction type) const
{
if (type==DocBookView::ToggleNavigationPane) {
if (type == DocBookView::ToggleNavigationPane) {
return actionToggleNavigationBar_;
}
else if (type==DocBookView::ShowPrintDialog) {
} else if (type == DocBookView::ShowPrintDialog) {
return actionShowPrintDialog_;
}
return 0;
......@@ -256,7 +256,7 @@ QAction * DocBookViewImpl::viewerAction(const DocBookView::DocBookViewAction typ
Document DocBookViewImpl::addDocument(const QUrl &url, QString *error)
{
DocBookFactory * factory = DocBookFactory::self();
DocBookFactory *factory = DocBookFactory::self();
Document doc = factory->parseDocument(roleValues_, url, error);
sidePanel_->addDocument(doc, true);
if (content_->isEmpty()) {
......@@ -267,17 +267,16 @@ Document DocBookViewImpl::addDocument(const QUrl &url, QString *error)
Document DocBookViewImpl::addDocuments(const QString &groupName, const QList<QUrl> &urls, QString *error)
{
DocBookFactory * factory = DocBookFactory::self();
DocBookFactory *factory = DocBookFactory::self();
QList<Document> docs;
Q_FOREACH(const QUrl & url, urls) {
Q_FOREACH (const QUrl &url, urls) {
Document doc = factory->parseDocument(roleValues_, url, error);
if (doc.root_.isNull()) {
if (error) {
error->prepend(QString("In %1: ").arg(url.toString()));
}
}
else {
} else {
docs.append(doc);
}
}
......@@ -292,7 +291,7 @@ bool DocBookViewImpl::hasAlgorithm(const QString &name) const
return ! algorithm.isNull();
}
void DocBookViewImpl::navigateToApiFunction(const QString & package, const QString &function)
void DocBookViewImpl::navigateToApiFunction(const QString &package, const QString &function)
{
const ModelPtr algorithm = sidePanel_->findApiFunction(package, function);
if (algorithm) {
......@@ -317,7 +316,7 @@ void DocBookViewImpl::clearNavigationFilters()
sidePanel_->focusToSearchLine();