فهرست منبع

Insert element <section>

Kandrashin Denis 13 سال پیش
والد
کامیت
3d6cf20b4b
3فایلهای تغییر یافته به همراه40 افزوده شده و 13 حذف شده
  1. 3 9
      CMakeLists.txt
  2. 35 1
      source/fb2tree.cpp
  3. 2 3
      source/fb2tree.hpp

+ 3 - 9
CMakeLists.txt

@@ -10,10 +10,10 @@
 cmake_minimum_required(VERSION 2.6.0)
 
 project(fb2edit)
-set(PACKAGE_VERSION "0.0.4")
-set(PACKAGE_NAME ${PROJECT_NAME})
+set(PACKAGE_VERSION "0.0.5")
 set(PACKAGE_VENDOR "LinTest")
-set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+set(PACKAGE_NAME ${PROJECT_NAME})
+set(PACKAGE_STRING "${PROJECT_NAME} ${PACKAGE_VERSION}")
 set(PACKAGE_BUGREPORT "mail@lintest.ru")
 
 message( STATUS "PACKAGE_NAME = ${PACKAGE_STRING}")
@@ -21,7 +21,6 @@ message( STATUS "PACKAGE_NAME = ${PACKAGE_STRING}")
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/cmake)
 
 find_package( Qt4 4.6.0 COMPONENTS QtCore QtGui QtNetwork QtWebkit QtXml QtXmlPatterns REQUIRED )
-find_package( QScintilla )
 find_package( LibXML2 )
 
 file( GLOB FB2_HEAD source/*.hpp     )
@@ -55,11 +54,6 @@ include_directories(${CMAKE_BINARY_DIR})
 target_link_libraries(fb2edit ${QT_LIBRARIES})
 add_definitions(${QT_DEFINITIONS})
 
-if (QSCINTILLA_FOUND) 
-    include_directories(${QSCINTILLA_INCLUDE_DIR})
-    target_link_libraries(fb2edit ${QSCINTILLA_LIBRARIES})
-endif (QSCINTILLA_FOUND) 
-
 if (LIBXML2_FOUND) 
     include_directories(${LIBXML2_INCLUDE_DIRS})
     target_link_libraries(fb2edit ${LIBXML2_LIBRARIES})

+ 35 - 1
source/fb2tree.cpp

@@ -431,8 +431,42 @@ void Fb2TreeView::updateTree()
     selectTree();
 }
 
+QModelIndex Fb2TreeModel::append(const QModelIndex &parent)
+{
+    Fb2TreeItem * owner = item(parent);
+    if (!owner || owner == m_root) return QModelIndex();
+    int row = owner->count();
+    owner->element().appendInside("<div class=section><div class=title><p><br/></p></div><p><br/></p></div>");
+    QWebElement element = owner->element().lastChild();
+    Fb2TreeItem * child = new Fb2TreeItem(element);
+    beginInsertRows(parent, row, row);
+    owner->insert(child, row);
+    endInsertRows();
+    return createIndex(row, 0, (void*)child);
+}
+
 void Fb2TreeView::insertNode()
 {
+    if (Fb2TreeModel * m = model()) {
+        QModelIndex index = currentIndex();
+        Fb2TreeItem * item = m->item(index);
+        if (!item) return;
+
+        QString n = item->name();
+        if (n != "section" && n != "body") {
+            index = m->parent(index);
+            item = item->parent();
+            n = item->name();
+            if (n != "section" && n != "body") return;
+        }
+
+        QModelIndex result = m->append(index);
+        if (!result.isValid()) return;
+        setCurrentIndex(result);
+        emit QTreeView::currentChanged(result, index);
+        emit QTreeView::activated(result);
+        scrollTo(result);
+    }
 }
 
 void Fb2TreeView::deleteNode()
@@ -443,8 +477,8 @@ void Fb2TreeView::deleteNode()
         setCurrentIndex(result);
         emit currentChanged(result, index);
         emit QTreeView::activated(result);
-        scrollTo(result);
         m->removeRow(index.row(), result);
+        scrollTo(result);
     }
 }
 

+ 2 - 3
source/fb2tree.hpp

@@ -89,6 +89,8 @@ public:
     Fb2WebView & view() { return m_view; }
     void selectText(const QModelIndex &index);
     QModelIndex move(const QModelIndex &index, int dx, int dy);
+    QModelIndex append(const QModelIndex &parent);
+    Fb2TreeItem * item(const QModelIndex &index) const;
 
 public:
     virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
@@ -98,9 +100,6 @@ public:
     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
     virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
 
-protected:
-    Fb2TreeItem * item(const QModelIndex &index) const;
-
 private:
     Fb2WebView & m_view;
     Fb2TreeItem * m_root;