Procházet zdrojové kódy

Edit header fields data

Kandrashin Denis před 12 roky
rodič
revize
5125bc42f7
4 změnil soubory, kde provedl 55 přidání a 12 odebrání
  1. 51 9
      source/fb2head.cpp
  2. 2 1
      source/fb2head.hpp
  3. 1 1
      source/fb2tree.cpp
  4. 1 1
      source/fb2tree.hpp

+ 51 - 9
source/fb2head.cpp

@@ -66,6 +66,24 @@ void FbScheme::items(QStringList &list) const
     }
 }
 
+bool FbScheme::hasItems() const
+{
+    FbScheme child = typeScheme().firstChildElement();
+    while (!child.isNull()) {
+        switch (toKeyword(child.tagName())) {
+            case XsElement:
+                return true;
+            case XsChoice:
+            case XsComplexType:
+            case XsSequence:
+                if (child.hasItems()) return true;
+            default: ;
+        }
+        child = child.nextSiblingElement();
+    }
+    return false;
+}
+
 FbScheme FbScheme::typeScheme() const
 {
     QString typeName = type();
@@ -202,7 +220,6 @@ FbHeadItem::FbHeadItem(QWebElement &element, FbHeadItem *parent)
         if (m_name == "history") return;
     } else if (m_name == "img") {
         m_name = "image";
-        m_text = element.attribute("alt");
     }
     addChildren(element);
 }
@@ -260,10 +277,11 @@ QString FbHeadItem::text(int col) const
     switch (col) {
         case 0: return QString("<%1> %2").arg(m_name).arg(hint());
         case 1: return value();
-        case 2: return scheme().info();
-        case 3: return scheme().type();
-        case 4: return scheme().attribute("minOccurs");
-        case 5: return scheme().attribute("maxOccurs");
+        case 2: return scheme().hasItems() ? "Yes" : "No";
+        case 3: return scheme().info();
+        case 4: return scheme().type();
+        case 5: return scheme().attribute("minOccurs");
+        case 6: return scheme().attribute("maxOccurs");
     }
     return QString();
 }
@@ -382,7 +400,7 @@ int FbHeadModel::columnCount(const QModelIndex &parent) const
 {
     Q_UNUSED(parent);
 #ifdef QT_DEBUG
-    return 6;
+    return 7;
 #else
     return 2;
 #endif
@@ -440,6 +458,13 @@ QVariant FbHeadModel::headerData(int section, Qt::Orientation orientation, int r
         switch (section) {
             case 0: return tr("Key");
             case 1: return tr("Value");
+        #ifdef QT_DEBUG
+            case 2: return tr("Has items");
+            case 3: return tr("Info");
+            case 4: return tr("Type");
+            case 5: return tr("Min");
+            case 6: return tr("Max");
+        #endif
         }
     }
     return QVariant();
@@ -447,7 +472,7 @@ QVariant FbHeadModel::headerData(int section, Qt::Orientation orientation, int r
 
 void FbHeadItem::setText(const QString &text)
 {
-    m_text = text;
+    m_element.setPlainText(text);
 }
 
 bool FbHeadModel::setData(const QModelIndex &index, const QVariant &value, int role)
@@ -464,7 +489,13 @@ Qt::ItemFlags FbHeadModel::flags(const QModelIndex &index) const
 {
     if (!index.isValid()) return 0;
     Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-    if (index.column() == 1) flags |= Qt::ItemIsEditable;
+    if (index.column() == 1) {
+        if (FbHeadItem * i = item(index)) {
+            if (!i->scheme().hasItems()) {
+                flags |= Qt::ItemIsEditable;
+            }
+        }
+    }
     return flags;
 }
 
@@ -510,6 +541,11 @@ FbHeadView::FbHeadView(FbTextEdit *view, QWidget *parent)
 //    connect(actionModify, SIGNAL(triggered()), SLOT(editCurrent()));
 }
 
+FbHeadModel * FbHeadView::model() const
+{
+    return qobject_cast<FbHeadModel*>(QTreeView::model());
+}
+
 void FbHeadView::initToolbar(QToolBar &toolbar)
 {
     toolbar.addSeparator();
@@ -540,7 +576,13 @@ void FbHeadView::editCurrent(const QModelIndex &index)
 
 void FbHeadView::activated(const QModelIndex &index)
 {
-    if (index.isValid() && index.column() == 1) edit(index);
+    if (index.isValid() && index.column() == 1) {
+        if (FbHeadItem * i = model()->item(index)) {
+            if (!i->scheme().hasItems()) {
+                edit(index);
+            }
+        }
+    }
     showStatus(index);
 }
 

+ 2 - 1
source/fb2head.hpp

@@ -44,6 +44,7 @@ public:
     static const QDomDocument & fb2();
     FbScheme element(const QString &name) const;
     void items(QStringList &list) const;
+    bool hasItems() const;
     QString info() const;
     QString type() const;
 
@@ -121,7 +122,6 @@ private:
     QWebElement m_element;
     FbHeadItem * m_parent;
     QString m_name;
-    QString m_text;
 };
 
 class FbHeadModel: public QAbstractItemModel
@@ -158,6 +158,7 @@ class FbHeadView : public QTreeView
 public:
     explicit FbHeadView(FbTextEdit *view, QWidget *parent = 0);
     void initToolbar(QToolBar &toolbar);
+    FbHeadModel * model() const;
 
 signals:
     void status(const QString &text);

+ 1 - 1
source/fb2tree.cpp

@@ -710,7 +710,7 @@ void FbTreeView::deleteNode()
     }
 }
 
-FbTreeModel * FbTreeView::model()
+FbTreeModel * FbTreeView::model() const
 {
     return qobject_cast<FbTreeModel*>(QTreeView::model());
 }

+ 1 - 1
source/fb2tree.hpp

@@ -167,7 +167,7 @@ protected:
 
 private:
     void moveCurrent(int dx, int dy);
-    FbTreeModel * model();
+    FbTreeModel * model() const;
 
 private:
     FbTextEdit & m_view;