[Kst] branches/work/kst/portto4/kst/src/libkst
Adam Treat
treat at kde.org
Tue Jul 17 01:09:52 CEST 2007
SVN commit 688822 by treat:
* Give these their own files to lesson the confusion
if/when we switch to real qt4 containers.
M +3 -2 kstdatasource.h
M +0 -1 kstobject.cpp
M +3 -307 kstobject.h
M +1 -0 kstobjectcollection.h
A kstobjectlist.h [License: GPL (v2+)]
A kstobjectmap.h [License: GPL (v2+)]
A kstobjecttag.h [License: GPL (v2+)]
M +2 -0 kstprimitive.h
M +2 -0 kststring.h
--- branches/work/kst/portto4/kst/src/libkst/kstdatasource.h #688821:688822
@@ -27,9 +27,10 @@
#include <qsettings.h>
+#include "kst_export.h"
+#include "kstobject.h"
#include "kstdateparser.h"
-#include "kstobject.h"
-#include "kst_export.h"
+#include "kstobjectlist.h"
class QXmlStreamWriter;
--- branches/work/kst/portto4/kst/src/libkst/kstobject.cpp #688821:688822
@@ -15,7 +15,6 @@
* *
***************************************************************************/
-#include <qdebug.h>
#include "kstobject.h"
/** Tag globals */
--- branches/work/kst/portto4/kst/src/libkst/kstobject.h #688821:688822
@@ -22,150 +22,14 @@
#include <qmutex.h>
#include <qobject.h>
#include <qstring.h>
+#include <qdebug.h>
#include <qstringlist.h>
#include "kst_export.h"
#include "kstsharedptr.h"
-#include <qdebug.h>
#include "rwlock.h"
+#include "kstobjecttag.h"
-class KstObjectTag {
- public:
- static const KstObjectTag invalidTag;
-
- static const QChar tagSeparator;
- static const QChar tagSeparatorReplacement;
-
- static const QStringList globalTagContext;
- static const QStringList constantTagContext;
- static const QStringList orphanTagContext;
-
-
- // construct a tag in a given context
- KstObjectTag(const QString& tag, const QStringList& context,
- unsigned int minDisplayComponents = 1) : _tag(cleanTag(tag)),
- _context(context),
- _minDisplayComponents(minDisplayComponents),
- _uniqueDisplayComponents(UINT_MAX)
- {
- }
-
- // construct a tag in the context of another tag
- KstObjectTag(const QString& tag, const KstObjectTag& contextTag, bool alwaysShowContext = true) :
- _uniqueDisplayComponents(UINT_MAX)
- {
- _tag = cleanTag(tag);
- _context = contextTag.fullTag();
- _minDisplayComponents = 1 + (alwaysShowContext ? qMax(contextTag._minDisplayComponents, (unsigned int)1) : 0);
- }
-
- // construct a tag from a fullTag representation
- KstObjectTag(QStringList fullTag) : _minDisplayComponents(1), _uniqueDisplayComponents(UINT_MAX) {
- _tag = cleanTag(fullTag.last());
- fullTag.pop_back();
- _context = fullTag;
- }
-
- QString tag() const { return _tag; }
- QStringList fullTag() const {
- QStringList ft(_context);
- ft << _tag;
- return ft;
- }
- QStringList context() const { return _context; }
-
- unsigned int components() const {
- if (!isValid()) {
- return 0;
- } else {
- return 1 + _context.count();
- }
- }
-
- // change the tag, maintaining context
- void setTag(const QString& tag) {
- _tag = cleanTag(tag);
- _uniqueDisplayComponents = UINT_MAX;
- }
-
- // change the context
- void setContext(const QStringList& context) {
- _context = context;
- _uniqueDisplayComponents = UINT_MAX;
- }
-
- // change the tag and context
- void setTag(const QString& tag, const QStringList& context) {
- setTag(tag);
- setContext(context);
- }
-
- bool isValid() const { return !_tag.isEmpty(); }
-
- QString tagString() const { return fullTag().join(tagSeparator); }
-
- // display methods
- void setUniqueDisplayComponents(unsigned int n) {
- _uniqueDisplayComponents = n;
- }
- unsigned int uniqueDisplayComponents() const { return _uniqueDisplayComponents; }
-
- void setMinDisplayComponents(unsigned int n) {
- _minDisplayComponents = n;
- }
-
- QStringList displayFullTag() const {
- QStringList out_tag = _context + QStringList(_tag);
- int componentsToDisplay = qMin(qMax(_uniqueDisplayComponents, _minDisplayComponents), components());
- while (out_tag.count() > componentsToDisplay) {
- out_tag.pop_front();
- }
- return out_tag;
- }
-
- QString displayString() const {
- return displayFullTag().join(tagSeparator);
- }
-
- // factory for String representation
- static KstObjectTag fromString(const QString& str) {
- QStringList l = str.split(tagSeparator);
- if (l.isEmpty()) {
- return invalidTag;
- }
-
- QString t = l.last();
- l.pop_back();
- return KstObjectTag(t, l);
- }
-
- bool operator==(const KstObjectTag& tag) const {
- return (_tag == tag._tag && _context == tag._context);
- }
-
- bool operator!=(const KstObjectTag& tag) const {
- return (_tag != tag._tag || _context != tag._context);
- }
-
- static QString cleanTag(const QString& in_tag) {
- if (in_tag.contains(tagSeparator)) {
- QString tag = in_tag;
- tag.replace(tagSeparator, tagSeparatorReplacement);
-// kstdWarning() << "cleaning tag name containing " << tagSeparator << ":\"" << in_tag << "\" -> \"" << tag << "\"" << endl;
- return tag;
- } else {
- return in_tag;
- }
- }
-
- private:
- QString _tag;
- QStringList _context;
- unsigned int _minDisplayComponents; // minimum number of components to use in display tag
- unsigned int _uniqueDisplayComponents; // number of components necessary for unique display tag
-} KST_EXPORT;
-
-
class KstObject : public KstShared, public QObject, public KstRWLock {
public:
KstObject();
@@ -215,179 +79,11 @@
typedef KstSharedPtr<KstObject> KstObjectPtr;
-
-template<class T>
-class KstObjectList : public QList<T> {
- public:
- KstObjectList() : QList<T>() {}
- KstObjectList(const KstObjectList<T>& x) : QList<T>(x) {}
- virtual ~KstObjectList() { }
-
- KstObjectList& operator=(const KstObjectList& l) {
- this->QList<T>::operator=(l);
- return *this;
- }
-
- virtual QStringList tagNames() {
- QStringList rc;
- for (typename QList<T>::ConstIterator it = QList<T>::begin(); it != QList<T>::end(); ++it) {
- rc << (*it)->tagName();
- }
- return rc;
- }
-
- // @since 1.1.0
- QStringList tagNames() const {
- QStringList rc;
- for (typename QList<T>::ConstIterator it = QList<T>::begin(); it != QList<T>::end(); ++it) {
- rc << (*it)->tagName();
- }
- return rc;
- }
-
- virtual typename QList<T>::Iterator findTag(const QString& x) {
- for (typename QList<T>::Iterator it = QList<T>::begin(); it != QList<T>::end(); ++it) {
- if (*(*it) == x) {
- return it;
- }
- }
- return QList<T>::end();
- }
-
- virtual typename QList<T>::ConstIterator findTag(const QString& x) const {
- for (typename QList<T>::ConstIterator it = QList<T>::begin(); it != QList<T>::end(); ++it) {
- if (*(*it) == x) {
- return it;
- }
- }
- return QList<T>::end();
- }
-
- virtual int findIndexTag(const QString& x) const {
- int i = 0;
- for (typename QList<T>::ConstIterator it = QList<T>::begin(); it != QList<T>::end(); ++it) {
- if (*(*it) == x) {
- return i;
- }
- i++;
- }
- return -1;
- }
-
- virtual typename QList<T>::Iterator removeTag(const QString& x) {
- typename QList<T>::Iterator it = findTag(x);
- if (it != QList<T>::end()) {
- return QList<T>::erase(it);
- }
- return it;
- }
-
- KstRWLock& lock() const { return _lock; }
-
- private:
- mutable KstRWLock _lock;
-};
-
-/* Does locking for you automatically. */
-template<class T, class S>
-KstObjectList<KstSharedPtr<S> > kstObjectSubList(KstObjectList<KstSharedPtr<T> >& list) {
- list.lock().readLock();
- KstObjectList<KstSharedPtr<S> > rc;
- typename KstObjectList<KstSharedPtr<T> >::Iterator it;
-
- for (it = list.begin(); it != list.end(); ++it) {
- S *x = dynamic_cast<S*>((*it).data());
- if (x != 0L) {
- rc.append(x);
- }
- }
-
- list.lock().unlock();
- return rc;
-}
-
-
-/* Does locking for you automatically. */
-template<class T, class S>
-void kstObjectSplitList(KstObjectList<KstSharedPtr<T> >& list, KstObjectList<KstSharedPtr<S> >& inclusive, KstObjectList<KstSharedPtr<T> >& exclusive) {
- list.lock().readLock();
- typename KstObjectList<KstSharedPtr<T> >::Iterator it;
-
- for (it = list.begin(); it != list.end(); ++it) {
- S *x = dynamic_cast<S*>((*it).data());
- if (x != 0L) {
- inclusive.append(x);
- } else {
- exclusive.append(*it);
- }
- }
-
- list.lock().unlock();
-}
-
-
-#include <qmap.h>
-
-template<class T>
-class KstObjectMap : public QMap<QString,T> {
- public:
- KstObjectMap() : QMap<QString,T>() {}
- virtual ~KstObjectMap() {}
-
- virtual QStringList tagNames() {
- QStringList rc;
- for (typename QMap<QString,T>::ConstIterator it = QMap<QString,T>::begin(); it != QMap<QString,T>::end(); ++it) {
- rc << it.value()->tagName();
- }
- return rc;
- }
-
- // @since 1.1.0
- QStringList tagNames() const {
- QStringList rc;
- for (typename QMap<QString,T>::ConstIterator it = QMap<QString,T>::begin(); it != QMap<QString,T>::end(); ++it) {
- rc << it.value()->tagName();
- }
- return rc;
- }
-
- // Careful - sets key(value) == value->tagName();
- typename QMap<QString,T>::iterator insertObject(const T& value) {
- return QMap<QString,T>::insert(value->tagName(), value);
- }
-
- typename QMap<QString,T>::iterator findTag(const QString& tag) {
- typename QMap<QString,T>::iterator i;
- for (i = QMap<QString,T>::begin(); i != QMap<QString,T>::end(); ++i) {
- if (i.value()->tagName() == tag) {
- break;
- }
- }
- return i;
- }
-
-/*
-These are wrong. We should not assume that key(x) == x->tagName().
- bool contains(const T& value) {
- return QMap<QString,T>::contains(value->tagName());
- }
-
- typename QMap<QString,T>::iterator find(const T& value) {
- return QMap<QString,T>::find(value->tagName());
- }
-
- void remove(const T& value) {
- QMap<QString,T>::remove(value->tagName());
- }
-
-*/
-};
-
template <typename T, typename U>
inline KstSharedPtr<T> kst_cast(KstSharedPtr<U> object) {
return dynamic_cast<T*>(object.data());
}
-
#endif
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkst/kstobjectcollection.h #688821:688822
@@ -24,6 +24,7 @@
#include <QHash>
#include <qdebug.h>
#include "kstobject.h"
+#include "kstobjectlist.h"
// Forward Declarations
template <class T>
--- branches/work/kst/portto4/kst/src/libkst/kstprimitive.h #688821:688822
@@ -20,6 +20,8 @@
#include "kst_export.h"
#include "kstobject.h"
+#include "kstobjectmap.h"
+#include "kstobjectlist.h"
#include <qpointer.h>
class KST_EXPORT KstPrimitive : public KstObject {
--- branches/work/kst/portto4/kst/src/libkst/kststring.h #688821:688822
@@ -20,6 +20,8 @@
#include <qdom.h>
#include "kstprimitive.h"
+#include "kstobjectlist.h"
+#include "kstobjectmap.h"
#include "kstobjectcollection.h"
class QXmlStreamWriter;
More information about the Kst
mailing list