[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project

src/klftools/klfpobj.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfpobj.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2010 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id: klfpobj.h 460 2010-08-24 01:16:00Z philippe $ */
00023 
00024 
00025 #ifndef KLFPOBJ_H
00026 #define KLFPOBJ_H
00027 
00028 #include <QDebug>
00029 #include <QVariant>
00030 #include <QByteArray>
00031 #include <QDataStream>
00032 #include <QTextStream>
00033 #include <QVector>
00034 #include <QList>
00035 #include <QMap>
00036 #include <QStringList>
00037 
00038 #include <klfdefs.h>
00039 
00086 class KLF_EXPORT KLFPropertizedObject
00087 {
00088 public:
00092   explicit KLFPropertizedObject(const QString& propertyNameSpace);
00093   virtual ~KLFPropertizedObject();
00094 
00103   virtual QVariant property(const QString& propName) const;
00113   virtual QVariant property(int propId) const;
00114 
00123   QList<int> propertyIdList() const;
00124 
00131   QStringList propertyNameList() const;
00132 
00137   QMap<QString,QVariant> allProperties() const;
00138 
00145   void setAllProperties(const QMap<QString, QVariant>& propValues);
00146   
00147 
00152   QByteArray allPropertiesToByteArray() const;
00153 
00158   void setAllPropertiesFromByteArray(const QByteArray& data);
00159 
00162   enum ToStringFlag {
00163     ToStringUseHtml = 0x0001, 
00164     ToStringUseHtmlDiv = 0x0002, 
00165     ToStringQuoteValues = 0x0004, 
00166     ToStringAllProperties = 0x0008 
00167   };
00172   virtual QString toString(uint toStringFlags = 0) const;
00173 
00175 
00177   int propertyMaxId() const;
00179 
00182   bool propertyIdRegistered(int propId) const;
00184 
00187   bool propertyNameRegistered(const QString& propertyName) const;
00189 
00192   int propertyIdForName(const QString& propertyName) const;
00194 
00197   QString propertyNameForId(int propId) const;
00199 
00202   QList<int> registeredPropertyIdList() const;
00204 
00207   QStringList registeredPropertyNameList() const;
00209 
00212   QMap<QString, int> registeredProperties() const;
00213 
00214 protected:
00215 
00225   virtual void propertyValueChanged(int propId, const QVariant& oldValue,
00226                                     const QVariant& newValue);
00227 
00228 
00231   virtual void setProperty(const QString& propname, const QVariant& value);
00232 
00235   virtual void setProperty(int propId, const QVariant& value);
00236 
00242   virtual int loadProperty(const QString& propname, const QVariant& value);
00243 
00247   void registerBuiltInProperty(int propId, const QString& propName) const;
00248 
00253   int registerProperty(const QString& propertyName) const;
00254 
00304   static void registerBuiltInProperty(const QString& propNameSpace, int propId,
00305                                       const QString& name);
00306 
00320   static int registerProperty(const QString& propNameSpace, const QString& propertyName);
00321 
00329   static int propertyMaxId(const QString& propNameSpace);
00330 
00338   static bool propertyIdRegistered(const QString& propNameSpace, int propId);
00339 
00347   static bool propertyNameRegistered(const QString& propNameSpace, const QString& propertyName);
00348 
00361   static int propertyIdForName(const QString& propNameSpace, const QString& propertyName);
00362 
00370   static QString propertyNameForId(const QString& propNameSpace, int propId);
00371 
00378   static QList<int> registeredPropertyIdList(const QString& propNameSpace);
00379 
00386   static QStringList registeredPropertyNameList(const QString& propNameSpace);
00387 
00394   static QMap<QString, int> registeredProperties(const QString& propNameSpace);
00395 
00396   QString propertyNameSpace() const { return pPropNameSpace; }
00397 
00398   QVector<QVariant> propertyVector() const { return pProperties; }
00399 
00400 private:
00402   KLFPropertizedObject() { }
00403 
00404   QString pPropNameSpace;
00405 
00406   QVector<QVariant> pProperties;
00407 
00411   static int internalRegisterProperty(const QString& propNameSpace, const QString& name,
00412                                       int propId = -1);
00413   static QMap<QString, QMap<QString, int> > pRegisteredProperties;
00414   static QMap<QString, int> pRegisteredPropertiesMaxId;
00415 
00416   friend bool operator==(const KLFPropertizedObject& a, const KLFPropertizedObject& b);
00417 };
00418 
00422 bool operator==(const KLFPropertizedObject& a, const KLFPropertizedObject& b);
00423 
00424 KLF_EXPORT QDataStream& operator<<(QDataStream& stream, const KLFPropertizedObject& obj);
00425 KLF_EXPORT QDataStream& operator>>(QDataStream& stream, KLFPropertizedObject& obj);
00426 
00427 KLF_EXPORT QTextStream& operator<<(QTextStream& stream, const KLFPropertizedObject& obj);
00428 
00429 KLF_EXPORT QDebug& operator<<(QDebug& stream, const KLFPropertizedObject& obj);
00430 
00431 
00432 
00433 
00434 #endif

Generated by doxygen 1.7.3