Browse Source

Tools for inserting Fb2TextElement

Kandrashin Denis 13 years ago
parent
commit
b81806c33d
2 changed files with 25 additions and 1 deletions
  1. 24 1
      source/fb2html.cpp
  2. 1 0
      source/fb2html.h

+ 24 - 1
source/fb2html.cpp

@@ -64,10 +64,13 @@ FbTextElement::Sublist::Sublist(const TypeList &list, const QString &name)
     : m_list(list)
     , m_pos(list.begin())
 {
+    TypeList::const_iterator empty = list.end();
     while (m_pos != list.end()) {
         if (m_pos->name() == name) break;
+        if (m_pos->name().isEmpty()) empty = m_pos;
         m_pos++;
     }
+    if (m_pos == list.end()) m_pos = empty;
 }
 
 FbTextElement::Sublist::operator bool() const
@@ -89,6 +92,15 @@ bool FbTextElement::Sublist::operator <(const QWebElement &element) const
     return false;
 }
 
+bool FbTextElement::Sublist::operator >=(const QWebElement &element) const
+{
+    const QString name = element.attribute("class");
+    for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
+        if (it->name() == name) return it >= m_pos || element.isNull();
+    }
+    return false;
+}
+
 //---------------------------------------------------------------------------
 //  FbTextElement
 //---------------------------------------------------------------------------
@@ -112,7 +124,7 @@ void FbTextElement::getChildren(FbElementList &list)
 const FbTextElement::TypeList * FbTextElement::subtypes() const
 {
     static Scheme scheme;
-    return scheme[tagName().toLower()];
+    return scheme[attribute("class").toLower()];
 }
 
 FbTextElement::TypeList::const_iterator FbTextElement::subtype(const TypeList &list, const QString &style)
@@ -136,6 +148,17 @@ FbTextElement FbTextElement::insertInside(const QString &style, const QString &h
         prependInside(html);
         return firstChild();
     }
+
+    while (!child.isNull()) {
+        FbTextElement subling = child.nextSibling();
+        if (sublist >= child && sublist < subling) {
+            child.appendOutside(html);
+            return child.nextSibling();
+        }
+        child = subling;
+    }
+
+    return FbTextElement();
 }
 
 QString FbTextElement::location()

+ 1 - 0
source/fb2html.h

@@ -47,6 +47,7 @@ private:
         operator bool() const;
         bool operator !() const;
         bool operator <(const QWebElement &element) const;
+        bool operator >=(const QWebElement &element) const;
     private:
         const TypeList &m_list;
         TypeList::const_iterator m_pos;