XML Mill  1.0.0
A GUI based XML editor with a memory.
gcbatchprocessorhelper.h
00001 /* Copyright (c) 2012 - 2013 by William Hallatt.
00002  *
00003  * This file forms part of "XML Mill".
00004  *
00005  * The official website for this project is <http://www.goblincoding.com> and,
00006  * although not compulsory, it would be appreciated if all works of whatever
00007  * nature using this source code (in whole or in part) include a reference to
00008  * this site.
00009  *
00010  * Should you wish to contact me for whatever reason, please do so via:
00011  *
00012  *                 <http://www.goblincoding.com/contact>
00013  *
00014  * This program is free software: you can redistribute it and/or modify it under
00015  * the terms of the GNU General Public License as published by the Free Software
00016  * Foundation, either version 3 of the License, or (at your option) any later
00017  * version.
00018  *
00019  * This program is distributed in the hope that it will be useful, but WITHOUT
00020  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00021  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License along with
00024  * this program (GNUGPL.txt).  If not, see
00025  *
00026  *                    <http://www.gnu.org/licenses/>
00027  */
00028 
00029 #ifndef GCBATCHPROCESSORHELPER_H
00030 #define GCBATCHPROCESSORHELPER_H
00031 
00032 #include <QMap>
00033 #include <QMultiHash>
00034 #include <QStringList>
00035 #include <QVariantList>
00036 
00037 class QDomDocument;
00038 class QDomElement;
00039 
00041 
00057 class GCBatchProcessorHelper
00058 {
00059 public:
00076   GCBatchProcessorHelper( const QDomDocument* domDoc,
00077                           const QString& stringSeparator,
00078                           const QStringList& knownElements,
00079                           const QStringList& knownAttributes );
00080 
00084   const QVariantList& newElementsToAdd() const;
00085 
00097   const QVariantList& newElementChildrenToAdd() const;
00098 
00110   const QVariantList& newElementAttributesToAdd() const;
00111 
00115   const QVariantList& elementsToUpdate() const;
00116 
00128   const QVariantList& elementChildrenToUpdate() const;
00129 
00141   const QVariantList& elementAttributesToUpdate() const;
00142 
00146   const QVariantList& newAttributeKeysToAdd() const;
00147 
00155   const QVariantList& newAssociatedElementsToAdd() const;
00156 
00166   const QVariantList& newAttributeValuesToAdd() const;
00167 
00171   const QVariantList& attributeKeysToUpdate() const;
00172 
00180   const QVariantList& associatedElementsToUpdate() const;
00181 
00191   const QVariantList& attributeValuesToUpdate() const;
00192 
00193 private:
00197   void processElement( const QDomElement& parentElement );
00198 
00202   void createRecord( const QDomElement& element );
00203 
00207   void sortRecords();
00208 
00210   void createVariantLists();
00211 
00212   QString m_stringListSeparator;
00213 
00214   QStringList m_knownElements;
00215   QStringList m_knownAttributeKeys;
00216 
00217   QVariantList m_newElementsToAdd;
00218   QVariantList m_newElementChildrenToAdd;
00219   QVariantList m_newElementAttributesToAdd;
00220 
00221   QVariantList m_elementsToUpdate;
00222   QVariantList m_elementChildrenToUpdate;
00223   QVariantList m_elementAttributesToUpdate;
00224 
00225   QVariantList m_newAttributeKeysToAdd;
00226   QVariantList m_newAssociatedElementsToAdd;
00227   QVariantList m_newAttributeValuesToAdd;
00228 
00229   QVariantList m_attributeKeysToUpdate;
00230   QVariantList m_associatedElementsToUpdate;
00231   QVariantList m_attributeValuesToUpdate;
00232 
00235   struct ElementRecord
00236   {
00237     QStringList children;
00238     QMap< QString/*name*/, QStringList /*values*/ > attributes;
00239 
00240     ElementRecord()
00241     : children  (),
00242       attributes() {}
00243   };
00244 
00245   QMultiHash< QString/*element*/, ElementRecord > m_unsorted;
00246   QMap< QString/*element*/, ElementRecord > m_records;
00247 };
00248 
00249 #endif // GCBATCHPROCESSORHELPER_H