XML Mill  1.0.0
A GUI based XML editor with a memory.
gcdomtreewidget.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 GCDOMTREEWIDGET_H
00030 #define GCDOMTREEWIDGET_H
00031 
00032 #include <QTreeWidget>
00033 #include <QDomComment>
00034 
00035 class GCTreeWidgetItem;
00036 class QDomDocument;
00037 class QDomElement;
00038 class QDomNode;
00039 
00041 
00049 class GCDomTreeWidget : public QTreeWidget
00050 {
00051 Q_OBJECT
00052 public:
00054   GCDomTreeWidget( QWidget* parent = 0 );
00055 
00057   ~GCDomTreeWidget();
00058 
00060   GCTreeWidgetItem* gcCurrentItem() const;
00061 
00065   QList< GCTreeWidgetItem* > includedTreeWidgetItems() const;
00066 
00069   const QList< GCTreeWidgetItem* >& allTreeWidgetItems() const;
00070 
00074   int itemPositionRelativeToIdenticalSiblings( const QString& nodeText, int itemIndex ) const;
00075 
00077   QDomNode cloneDocument() const;
00078 
00080   QString toString() const;
00081 
00085   QString rootName() const;
00086 
00090   QString activeCommentValue() const;
00091 
00095   void setActiveCommentValue( const QString& value );
00096 
00101   bool setContent( const QString& text, QString* errorMsg = 0, int* errorLine = 0, int* errorColumn = 0 );
00102 
00104   bool empty() const;
00105 
00109   bool currentItemIsRoot() const;
00110 
00114   bool matchesRootName( const QString& elementName ) const;
00115 
00117   bool documentCompatible() const;
00118 
00120   bool batchProcessSuccess() const;
00121 
00124   void rebuildTreeWidget();
00125 
00131   void appendSnippet( GCTreeWidgetItem* parentItem, QDomElement childElement );
00132 
00136   void replaceItemsWithComment( const QList< int >& indices, const QString& comment );
00137 
00139   void updateItemNames( const QString& oldName, const QString& newName );
00140 
00148   void populateFromDatabase( const QString& baseElementName = QString() );
00149 
00156   void addItem( const QString& element, bool toParent = false );
00157 
00164   void insertItem( const QString& elementName, int index, bool toParent = false );
00165 
00167   void setAllCheckStates( Qt::CheckState state );
00168 
00170   void setShowTreeItemsVerbose( bool verbose );
00171 
00173   void clearAndReset();
00174 
00175 public slots:
00179   void setCurrentItemFromIndex( int index );
00180 
00181 signals:
00185   void gcCurrentItemSelected( GCTreeWidgetItem* item, int column );
00186 
00190   void gcCurrentItemChanged( GCTreeWidgetItem* item, int column );
00191 
00192 protected:
00194   void dropEvent( QDropEvent* event );
00195 
00197   void keyPressEvent( QKeyEvent* event );
00198 
00199 private slots:
00201   void currentGcItemChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous );
00202 
00206   void emitGcCurrentItemSelected( QTreeWidgetItem* item, int column );
00207 
00210   void emitGcCurrentItemChanged( QTreeWidgetItem* item, int column );
00211 
00217   void renameItem();
00218 
00222   void removeItem();
00223 
00226   void stepUp();
00227 
00230   void stepDown();
00231 
00234   void expand();
00235 
00238   void collapse();
00239 
00240 private:
00246   void processElement( GCTreeWidgetItem* parentItem, QDomElement element );
00247 
00253   void processElementFromDatabase( const QString& element );
00254 
00257   bool parentTreeAlreadyContainsElement( const GCTreeWidgetItem* item, const QString& element );
00258 
00260   void populateCommentList( QDomNode node );
00261 
00265   void updateIndices();
00266 
00268   GCTreeWidgetItem* gcItemFromNode( QDomNode element );
00269 
00271   void removeFromList( GCTreeWidgetItem* item );
00272 
00273   GCTreeWidgetItem* m_activeItem;
00274   QDomDocument* m_domDoc;
00275   QDomComment m_commentNode;
00276   bool m_isEmpty;
00277   bool m_busyIterating;
00278   bool m_itemBeingManipulated;
00279 
00280   QList< GCTreeWidgetItem* > m_items;
00281   QList< QDomComment > m_comments;
00282 };
00283 
00284 #endif // GCDOMTREEWIDGET_H