Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lintest/fb2edit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKandrashin Denis <mail@lintest.ru>2012-10-04 17:39:39 +0400
committerKandrashin Denis <mail@lintest.ru>2012-10-04 17:39:39 +0400
commit9512d129a9d763e6ea330022e428e4a6dd8b1e31 (patch)
treec5b048b5fa8025debb8759aa4b150f44f3fa4b13
parente91fdcc531d6c7a78ed5065a93f3e9e93e5b09dd (diff)
Remove tag <DIV>
-rw-r--r--source/fb2html.cpp35
-rw-r--r--source/fb2html.h8
-rw-r--r--source/fb2tree.cpp14
3 files changed, 30 insertions, 27 deletions
diff --git a/source/fb2html.cpp b/source/fb2html.cpp
index 4eb0c6d..a6e1b83 100644
--- a/source/fb2html.cpp
+++ b/source/fb2html.cpp
@@ -83,33 +83,39 @@ bool FbTextElement::Sublist::operator!() const
return m_pos == m_list.end();
}
-bool FbTextElement::Sublist::operator <(const QWebElement &element) const
+bool FbTextElement::Sublist::operator <(const FbTextElement &element) const
{
- const QString name = element.attribute("class");
+ const QString name = element.nodeName();
for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
if (it->name() == name) return m_pos < it || element.isNull();
}
return false;
}
-bool FbTextElement::Sublist::operator >=(const QWebElement &element) const
+bool FbTextElement::Sublist::operator >=(const FbTextElement &element) const
{
- const QString name = element.attribute("class");
+ const QString name = element.nodeName();
for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
if (it->name() == name) return m_pos >= it || element.isNull();
}
return false;
}
-bool FbTextElement::Sublist::operator !=(const QWebElement &element) const
+bool FbTextElement::Sublist::operator !=(const FbTextElement &element) const
{
- return element.isNull() || m_pos->name() != element.attribute("class");
+ return element.isNull() || m_pos->name() != element.nodeName();
}
//---------------------------------------------------------------------------
// FbTextElement
//---------------------------------------------------------------------------
+QString FbTextElement::nodeName() const
+{
+ QString n = tagName().toLower();
+ return n.left(3) == "fb:" ? n.mid(3) : n;
+}
+
void FbTextElement::getChildren(FbElementList &list)
{
FbTextElement child = firstChild();
@@ -140,7 +146,7 @@ bool FbTextElement::hasScheme() const
const FbTextElement::TypeList * FbTextElement::subtypes() const
{
static Scheme scheme;
- return scheme[attribute("class").toLower()];
+ return scheme[nodeName()];
}
bool FbTextElement::hasSubtype(const QString &style) const
@@ -202,35 +208,30 @@ bool FbTextElement::hasChild(const QString &style) const
{
FbTextElement child = firstChild();
while (!child.isNull()) {
- if (child.tagName() == "DIV" && child.attribute("class").toLower() == style) return true;
+ if (child.nodeName() == style) return true;
child = child.nextSibling();
}
return false;
}
-bool FbTextElement::isDiv(const QString &style) const
-{
- return tagName() == "DIV" && attribute("class").toLower() == style;
-}
-
bool FbTextElement::isBody() const
{
- return isDiv("body");
+ return nodeName() == "body";
}
bool FbTextElement::isSection() const
{
- return isDiv("section");
+ return nodeName() == "section";
}
bool FbTextElement::isTitle() const
{
- return isDiv("title");
+ return nodeName() == "title";
}
bool FbTextElement::isStanza() const
{
- return isDiv("stanza");
+ return nodeName() == "stanza";
}
bool FbTextElement::hasTitle() const
diff --git a/source/fb2html.h b/source/fb2html.h
index 4c3db84..f006927 100644
--- a/source/fb2html.h
+++ b/source/fb2html.h
@@ -46,9 +46,9 @@ private:
Sublist(const TypeList &list, const QString &name);
operator bool() const;
bool operator !() const;
- bool operator <(const QWebElement &element) const;
- bool operator >=(const QWebElement &element) const;
- bool operator !=(const QWebElement &element) const;
+ bool operator <(const FbTextElement &element) const;
+ bool operator >=(const FbTextElement &element) const;
+ bool operator !=(const FbTextElement &element) const;
private:
const TypeList &m_list;
TypeList::const_iterator m_pos;
@@ -60,6 +60,7 @@ public:
FbTextElement &operator=(const QWebElement &x) { QWebElement::operator=(x); return *this; }
FbTextElement insertInside(const QString &style, const QString &html);
FbTextElement child(int index) const;
+ QString nodeName() const;
void getChildren(FbElementList &list);
bool hasSubtype(const QString &style) const;
bool hasScheme() const;
@@ -68,7 +69,6 @@ public:
public:
bool hasChild(const QString &style) const;
- bool isDiv(const QString &style) const;
bool isBody() const;
bool isSection() const;
bool isTitle() const;
diff --git a/source/fb2tree.cpp b/source/fb2tree.cpp
index c4f7feb..c891378 100644
--- a/source/fb2tree.cpp
+++ b/source/fb2tree.cpp
@@ -535,20 +535,22 @@ void FbTreeView::contextMenu(const QPoint &pos)
QMenu menu;
menu.addAction(actionSection);
- if (e.isBody()) {
+ QString n = e.nodeName();
+
+ if (n == "body") {
if (!e.hasChild("image")) menu.addAction(actionImage);
if (!e.hasChild("title")) menu.addAction(actionTitle);
menu.addAction(actionEpigraph);
}
- if (e.isSection()) {
+ if (n == "section") {
if (!e.hasChild("title")) menu.addAction(actionTitle);
menu.addAction(actionEpigraph);
if (!e.hasChild("image")) menu.addAction(actionImage);
if (!e.hasChild("annotetion")) menu.addAction(actionAnnot);
}
- if (e.isDiv("poem")) {
+ if (n == "poem") {
if (!e.hasChild("title")) menu.addAction(actionTitle);
menu.addAction(actionEpigraph);
menu.addAction(actionStanza);
@@ -556,15 +558,15 @@ void FbTreeView::contextMenu(const QPoint &pos)
if (!e.hasChild("date")) menu.addAction(actionDate);
}
- if (e.isDiv("stanza")) {
+ if (n == "stanza") {
if (!e.hasChild("title")) menu.addAction(actionTitle);
}
- if (e.isDiv("epigraph")) {
+ if (n == "epigraph") {
menu.addAction(actionAuthor);
}
- if (e.isDiv("cite")) {
+ if (n == "cite") {
menu.addAction(actionAuthor);
}