Commit 08067b4f authored by Victor Yacovlev's avatar Victor Yacovlev

DocBookViewer: Implemented List of Tables

parent 034d4d16
......@@ -14,11 +14,15 @@ ContentView::ContentView(QWidget *parent)
this, SLOT(handleInternalLink(QUrl)));
}
QSize ContentView::minimumSizeHint() const
{
return QSize(640, 400);
}
void ContentView::reset()
{
loadedModel_.clear();
clear();
counters_.example = counters_.figure = counters_.table = 0u;
clear();
}
void ContentView::renderData(ModelPtr data)
......@@ -165,6 +169,9 @@ QString ContentView::renderElement(ModelPtr data) const
else if (data == DocBookModel::ListOfExamples) {
return renderListOfExamples(data);
}
else if (data == DocBookModel::ListOfTables) {
return renderListOfTables(data);
}
else {
return "";
}
......@@ -352,21 +359,37 @@ QString ContentView::renderTable(ModelPtr data) const
{
QString result;
const QString & title = data->title();
counters_.table ++;
const QString index = chapterNumber(data) > 0
? QString("%1.%2").arg(chapterNumber(data)).arg(counters_.example)
: QString::number(counters_.example);
result += "<table width='100%'>\n";
result += "<tr><td height='10'>&nbsp;</td></tr>\n";
result += "<tr><td align='left'><b>";
result += tr("Table&nbsp;%1. ").arg(index);
result += "</b>" + title + "</td></tr>\n";
result += "<tr><td>\n";
result += renderTableContent(data);
result += "</td></tr>\n";
result += "<tr><td height='10'>&nbsp;</td></tr>\n";
result += "</table>\n";
? QString("%1.%2")
.arg(chapterNumber(data))
.arg(elementNumber(data))
: QString::number(elementNumber(data));
if (loadedModel_ == DocBookModel::ListOfTables) {
result += "<a name='" + modelToLink(data) + "'>\n";
result += "<h2>" +
tr("Table&nbsp;%1. ").arg(index) +
normalizeText(title) +
"</h2>\n";
result += renderItemContextLink(data);
result += "<br/>";
result += renderTableContent(data);
result += "</a>";
}
else {
result += "<a name='" + modelToLink(data) + "'>\n";
result += "<table width='100%'>\n";
result += "<tr><td height='10'>&nbsp;</td></tr>\n";
result += "<tr><td align='left'><b>";
result += tr("Table&nbsp;%1. ").arg(index);
result += "</b>" + title + "</td></tr>\n";
result += "<tr><td>\n";
result += renderTableContent(data);
result += "</td></tr>\n";
result += "<tr><td height='10'>&nbsp;</td></tr>\n";
result += "</table>\n";
}
return result;
}
......@@ -478,7 +501,6 @@ QString ContentView::renderExample(ModelPtr data) const
{
QString result;
const QString & title = data->title();
counters_.example ++;
const QString index = chapterNumber(data) > 0
? QString("%1.%2")
......@@ -589,6 +611,14 @@ QString ContentView::renderListOfExamples(ModelPtr data) const
return result;
}
QString ContentView::renderListOfTables(ModelPtr data) const
{
QString result;
result += renderTOC(data);
result += renderChilds(data);
return result;
}
QVariant ContentView::loadResource(int type, const QUrl &name)
{
QVariant result;
......
......@@ -21,6 +21,7 @@ public:
void reset();
void renderData(ModelPtr data);
QSize minimumSizeHint() const;
signals:
void itemRequest(ModelPtr model);
......@@ -100,11 +101,6 @@ private:
private /*fields*/:
ModelPtr loadedModel_;
mutable struct Counters {
quint32 example;
quint32 figure;
quint32 table;
} counters_;
private slots:
void handleInternalLink(const QUrl & url);
......
......@@ -346,30 +346,34 @@ bool DocBookFactory::warning(const QXmlParseException &exception)
return true;
}
QList<ModelPtr> DocBookFactory::findExamples(ModelPtr root)
QList<ModelPtr> DocBookFactory::findEntriesOfType(
ModelPtr root,
DocBookModel::ModelType findType
)
{
QList<ModelPtr> result;
if (root->modelType() == DocBookModel::Example) {
if (root->modelType() == findType) {
result += root;
}
else {
foreach (ModelPtr child, root->children()) {
result += findExamples(child);
result += findEntriesOfType(child, findType);
}
}
return result;
}
ModelPtr DocBookFactory::createListOfExamples(ModelPtr root)
ModelPtr DocBookFactory::createListOfEntries(ModelPtr root,
DocBookModel::ModelType resType,
DocBookModel::ModelType findType)
{
ModelPtr result;
QList<ModelPtr> examples = findExamples(root);
if (examples.size() > 0) {
result = ModelPtr(new DocBookModel(ModelPtr(),
DocBookModel::ListOfExamples));
foreach (ModelPtr example, examples) {
result->children_.append(example);
example->indexParent_ = result;
QList<ModelPtr> entries = findEntriesOfType(root, findType);
if (entries.size() > 0) {
result = ModelPtr(new DocBookModel(ModelPtr(), resType));
foreach (ModelPtr entry, entries) {
result->children_.append(entry);
entry->indexParent_ = result;
}
result->title_ = root->title();
result->subtitle_ = root->subtitle();
......
......@@ -2,6 +2,7 @@
#define DOCBOOKFACTORY_H
#include "document.h"
#include "docbookmodel.h"
// Qt includes
#include <QXmlDefaultHandler>
......@@ -17,7 +18,10 @@ class DocBookFactory
public:
static DocBookFactory* self();
Document parseDocument(const QUrl & url, QString * error = 0) const;
static ModelPtr createListOfExamples(ModelPtr root);
static ModelPtr createListOfEntries(ModelPtr root,
DocBookModel::ModelType resType,
DocBookModel::ModelType findType
);
......@@ -44,7 +48,9 @@ private /*methods*/:
void filterByOs(ModelPtr root) const;
static QList<ModelPtr> findExamples(ModelPtr root);
static QList<ModelPtr> findEntriesOfType(ModelPtr root,
DocBookModel::ModelType findType
);
private /*fields*/:
......
......@@ -50,6 +50,7 @@ void SidePanel::addDocument(Document document)
item->setToolTip(0, model->subtitle());
createNavigationItems(item, model);
createListOfExamples(model);
createListOfTables(model);
modelsOfItems_[item] = model;
itemsOfModels_[model] = item;
}
......@@ -179,7 +180,11 @@ void SidePanel::createNavigationItems(QTreeWidgetItem *item,
void SidePanel::createListOfExamples(ModelPtr root)
{
ModelPtr listOfExamples = DocBookFactory::createListOfExamples(root);
ModelPtr listOfExamples = DocBookFactory::createListOfEntries(
root,
DocBookModel::ListOfExamples,
DocBookModel::Example
);
if (listOfExamples) {
QTreeWidgetItem * topLevelItem =
new QTreeWidgetItem(ui->examplesNavigator);
......@@ -201,6 +206,34 @@ void SidePanel::createListOfExamples(ModelPtr root)
}
}
void SidePanel::createListOfTables(ModelPtr root)
{
ModelPtr listOfTables = DocBookFactory::createListOfEntries(
root,
DocBookModel::ListOfTables,
DocBookModel::Table
);
if (listOfTables) {
QTreeWidgetItem * topLevelItem =
new QTreeWidgetItem(ui->tablesNavigator);
topLevelItem->setText(0, listOfTables->title());
topLevelItem->setToolTip(0, tr("List of tables in \"%1\"")
.arg(listOfTables->title()));
ui->tablesNavigator->addTopLevelItem(topLevelItem);
itemsOfModels_[listOfTables] = topLevelItem;
modelsOfItems_[topLevelItem] = listOfTables;
foreach (ModelPtr table, listOfTables->children()) {
QTreeWidgetItem * item = new QTreeWidgetItem(topLevelItem);
item->setText(0, table->title());
item->setToolTip(0, table->subtitle());
modelsOfItems_[item] = table;
itemsOfModels_[table] = item;
topLevelItem->addChild(item);
topLevelItem->setExpanded(true);
}
}
}
void SidePanel::selectTreeWidgetItem(QTreeWidgetItem *item)
......
......@@ -35,6 +35,7 @@ signals:
private:
void createNavigationItems(QTreeWidgetItem * item, ModelPtr model);
void createListOfExamples(ModelPtr root);
void createListOfTables(ModelPtr root);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment