XML Mill  1.0.0
A GUI based XML editor with a memory.
gcdatabaseinterface.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 GCDATABASEINTERFACE_H
00030 #define GCDATABASEINTERFACE_H
00031 
00032 #include <QObject>
00033 #include <QMap>
00034 #include <QtSql/QSqlQuery>
00035 
00036 class QDomDocument;
00037 
00039 
00066 class GCDataBaseInterface : public QObject
00067 {
00068 Q_OBJECT
00069 
00070 public:
00072   static GCDataBaseInterface* instance();
00073 
00076   bool isInitialised() const;
00077 
00081   bool batchProcessDomDocument( const QDomDocument* domDoc ) const;
00082 
00088   bool addElement( const QString& element, const QStringList& children, const QStringList& attributes ) const;
00089 
00093   bool addRootElement( const QString& root ) const;
00094 
00102   bool updateElementChildren( const QString& element, const QStringList& children, bool replace = false ) const;
00103 
00111   bool updateElementAttributes( const QString& element, const QStringList& attributes, bool replace = false ) const;
00112 
00122   bool updateAttributeValues( const QString& element, const QString& attribute, const QStringList& attributeValues, bool replace = false ) const;
00123 
00125   bool removeElement( const QString& element ) const;
00126 
00128   bool removeRootElement( const QString& element ) const;
00129 
00132   bool removeChildElement( const QString& element, const QString& child ) const;
00133 
00136   bool removeAttribute( const QString& element, const QString& attribute ) const;
00137 
00140   bool hasActiveSession() const;
00141 
00143   bool isProfileEmpty() const;
00144 
00146   bool containsKnownRootElement( const QString& dbName, const QString& root ) const;
00147 
00150   bool isUniqueChildElement( const QString& parentElement, const QString& element ) const;
00151 
00154   bool isDocumentCompatible( const QDomDocument* doc ) const;
00155 
00158   QStringList knownElements() const;
00159 
00162   QStringList children( const QString& element ) const;
00163 
00168   QStringList attributes( const QString& element ) const;
00169 
00173   QStringList attributeValues( const QString& element, const QString& attribute ) const;
00174 
00177   QStringList knownRootElements() const;
00178 
00180   QStringList connectionList() const;
00181 
00183   const QString& lastError() const;
00184 
00187   QString activeSessionName() const;
00188 
00189   public slots:
00191   bool setActiveDatabase( const QString& dbName );
00192 
00194   bool addDatabase( const QString& dbName );
00195 
00197   bool removeDatabase( const QString& dbName );
00198 
00199 private:
00200   static GCDataBaseInterface* m_instance;
00201 
00203   GCDataBaseInterface();
00204 
00206   GCDataBaseInterface( const GCDataBaseInterface& );
00207 
00209   GCDataBaseInterface& operator=( const GCDataBaseInterface& );
00210 
00212   QStringList knownAttributeKeys() const;
00213 
00216   QSqlQuery selectElement( const QString& element ) const;
00217 
00219   QSqlQuery selectAllElements() const;
00220 
00223   QSqlQuery selectAttribute( const QString& attribute, const QString& associatedElement ) const;
00224 
00226   QSqlQuery selectAllAttributes() const;
00227 
00229   QStringList knownRootElements( QSqlDatabase db ) const;
00230 
00235   bool removeDuplicatesFromFields() const;
00236 
00239   bool openConnection( const QString& dbConName );
00240 
00242   bool createTables() const;
00243 
00245   void saveDatabaseFile() const;
00246 
00247   QSqlDatabase m_sessionDB;
00248   mutable QString m_lastErrorMsg;
00249   bool m_hasActiveSession;
00250   bool m_initialised;
00251   QMap< QString/*connection name*/, QString /*file name*/ > m_dbMap;
00252 };
00253 
00254 #endif // GCDATABASEINTERFACE_H