23#include "customproperty.h"
31#include <tqasciidict.h>
32#include <tqguardedptr.h>
43 : caption(0), listData(0), changed(false), storable(true),
44 readOnly(false), visible(true),
45 autosync(-1), custom(0), useCustomProperty(true),
46 sets(0), parent(0), children(0), relatedProperties(0),
51 inline void setCaptionForDisplaying(
const TQString& captionForDisplaying)
54 if (captionForDisplaying.simplifyWhiteSpace()!=captionForDisplaying)
55 caption =
new TQString(captionForDisplaying.simplifyWhiteSpace());
58 this->captionForDisplaying = captionForDisplaying;
67 delete relatedProperties;
74 TQString captionForDisplaying;
80 Property::ListData* listData;
89 TQMap<TQCString, TQVariant> options;
93 bool useCustomProperty;
96 TQGuardedPtr<Set> set;
98 TQPtrDict< TQGuardedPtr<Set> > *sets;
102 TQValueList<Property*> *children;
104 TQValueList<Property*> *relatedProperties;
114Property::ListData::ListData(
const TQStringList& keys_,
const TQStringList& names_)
118 setKeysAsStringList(keys_);
121Property::ListData::ListData(
const TQValueList<TQVariant> keys_,
const TQStringList& names_)
122 : keys(keys_), names(names_)
127Property::ListData::ListData()
132Property::ListData::~ListData()
136void Property::ListData::setKeysAsStringList(
const TQStringList& list)
139 for (TQStringList::ConstIterator it = list.constBegin(); it!=list.constEnd(); ++it) {
144TQStringList Property::ListData::keysAsStringList()
const
147 for (TQValueList<TQVariant>::ConstIterator it = keys.constBegin(); it!=keys.constEnd(); ++it) {
148 result.append((*it).toString());
176 : d( new PropertyPrivate() )
179 d->setCaptionForDisplaying(
caption);
183 d->type =
value.type();
195 const TQVariant &value,
const TQString &caption,
const TQString &description,
197 : d( new PropertyPrivate() )
200 d->setCaptionForDisplaying(
caption);
213 const TQVariant &value,
const TQString &caption,
const TQString &description,
215 : d( new PropertyPrivate() )
218 d->setCaptionForDisplaying(
caption);
231 : d( new PropertyPrivate() )
236 : d( new PropertyPrivate() )
262 return d->caption ? *d->caption : d->captionForDisplaying;
268 return d->captionForDisplaying;
274 d->setCaptionForDisplaying(
caption);
280 return d->description;
286 d->description = desc;
316 if(d->custom && d->custom->handleValue())
317 return d->custom->value();
333 if (d->name.isEmpty()) {
334 kopropertywarn <<
"Property::setValue(): COULD NOT SET value to a null property" << endl;
337 TQVariant currentValue = this->
value();
338 const TQVariant::Type t = currentValue.type();
339 const TQVariant::Type newt =
value.type();
341 if (t != newt && !currentValue.isNull() && !
value.isNull()
342 && !( (t==TQVariant::Int && newt==TQVariant::UInt)
343 || (t==TQVariant::UInt && newt==TQVariant::Int)
344 || (t==TQVariant::CString && newt==TQVariant::String)
345 || (t==TQVariant::String && newt==TQVariant::CString)
346 || (t==TQVariant::ULongLong && newt==TQVariant::LongLong)
347 || (t==TQVariant::LongLong && newt==TQVariant::ULongLong)
349 kopropertywarn <<
"Property::setValue(): INCOMPATIBLE TYPES! old=" << currentValue
350 <<
" new=" <<
value << endl;
355 if (t == TQVariant::DateTime
356 || t == TQVariant::Time) {
359 ch = (currentValue.toString() !=
value.toString());
361 else if (t == TQVariant::String || t==TQVariant::CString) {
364 ch = ( (currentValue.toString().isEmpty() !=
value.toString().isEmpty())
366 || (!currentValue.toString().isEmpty() && !
value.toString().isEmpty() && currentValue !=
value) );
368 else if (t == TQVariant::Invalid && newt == TQVariant::Invalid)
371 ch = (currentValue !=
value);
377 if(rememberOldValue) {
379 d->oldValue = currentValue;
383 d->oldValue = TQVariant();
387 if(d->custom && useCustomProperty) {
388 d->custom->setValue(
value, rememberOldValue);
389 prevValue = d->custom->value();
392 prevValue = currentValue;
394 if (!d->custom || !useCustomProperty || !d->custom->handleValue())
404 bool cleared =
false;
406 d->set->informAboutClearing(cleared);
412 if(d->parent && d->parent->value() == d->parent->oldValue())
413 d->parent->d->changed =
false;
416 for (TQPtrDictIterator< TQGuardedPtr<Set> > it(*d->sets); it.current(); ++it) {
418 emit (*it.current())->propertyReset(**it.current(), *
this);
422 emit d->set->propertyReset(*d->set, *
this);
438 if (list == d->listData)
460 return d->name.isEmpty();
484 d->readOnly = readOnly;
496 d->visible = visible;
520 d->storable = storable;
526 d->options[
name] = val;
532 if (d->options.contains(
name))
533 return d->options[
name];
540 return !d->options.isEmpty();
545Property::operator bool ()
const
560 if(&property ==
this)
571 if(d->relatedProperties) {
572 delete d->relatedProperties;
573 d->relatedProperties = 0;
580 d->name =
property.d->name;
582 d->description =
property.d->description;
583 d->type =
property.d->type;
585 d->icon =
property.d->icon;
586 d->autosync =
property.d->autosync;
587 d->visible =
property.d->visible;
588 d->storable =
property.d->storable;
589 d->readOnly =
property.d->readOnly;
590 d->options =
property.d->options;
592 if(property.d->listData) {
593 d->listData =
new ListData(*property.d->listData);
595 if(property.d->custom) {
601 d->value =
property.d->value;
602 if(property.d->children) {
604 d->children =
new TQValueList<Property*>();
605 TQValueList<Property*>::ConstIterator endIt =
property.d->children->constEnd();
606 for(TQValueList<Property*>::ConstIterator it = property.d->children->constBegin(); it != endIt; ++it) {
613 if(property.d->relatedProperties) {
614 d->relatedProperties =
new TQValueList<Property*>( *(property.d->relatedProperties));
618 d->oldValue =
property.d->oldValue;
619 d->changed =
property.d->changed;
620 d->sortingKey =
property.d->sortingKey;
628 return ((d->name == prop.d->name) && (
value() == prop.
value()));
633const TQValueList<Property*>*
642 TQValueList<Property*>::ConstIterator endIt = d->children->constEnd();
643 for(TQValueList<Property*>::ConstIterator it = d->children->constBegin(); it != endIt; ++it) {
644 if((*it)->name() ==
name)
662 if(!d->children || tqFind( d->children->begin(), d->children->end(), prop) == d->children->end()) {
664 d->children =
new TQValueList<Property*>();
665 d->children->append(prop);
667 prop->d->parent =
this;
670 kopropertywarn <<
"Property::addChild(): property \"" <<
name()
671 <<
"\": child property \"" << prop->
name() <<
"\" already added" << endl;
686 if ((
Set*)d->set==set)
688 TQGuardedPtr<Set> *pset = d->sets ? d->sets->find(set) : 0;
689 if (pset && (
Set*)*pset == set)
692 d->sets =
new TQPtrDict< TQGuardedPtr<Set> >( 101 );
693 d->sets->setAutoDelete(
true);
696 d->sets->replace(set,
new TQGuardedPtr<Set>( set ));
703const TQValueList<Property*>*
706 return d->relatedProperties;
712 if(!d->relatedProperties)
713 d->relatedProperties =
new TQValueList<Property*>();
715 TQValueList<Property*>::iterator it = tqFind( d->relatedProperties->begin(), d->relatedProperties->end(), property);
716 if(it == d->relatedProperties->end())
717 d->relatedProperties->append(property);
734 return d->sortingKey;
745 for (TQPtrDictIterator< TQGuardedPtr<Set> > it(*d->sets); it.current(); ++it) {
747 emit (*it.current())->propertyChangedInternal(**it.current(), *
this);
748 emit (*it.current())->propertyChanged(**it.current(), *
this);
759 emit d->set->propertyChangedInternal(*d->set, *
this);
760 emit d->set->propertyChanged(*d->set, *
this);
769 TQString dbg =
"Property( name='" + TQString(d->name) +
"' desc='" + d->description
770 +
"' val=" + (
value().isValid() ?
value().toString() :
"<INVALID>");
771 if (!d->oldValue.isValid())
772 dbg += (
", oldVal='" + d->oldValue.toString() +
'\'');
773 dbg += (TQString(d->changed ?
" " :
" un") +
"changed");
774 dbg += (d->visible ?
" visible" :
" hidden");
777 kopropertydbg << dbg << endl;
Base class for custom properties.
static FactoryManager * self()
CustomProperty * createCustomProperty(Property *parent)
The base class representing a single property.
void setSortingKey(int key)
void setAutoSync(int sync)
CustomProperty * customProperty() const
void setStorable(bool storable)
const Property & operator=(const TQVariant &val)
Property * child(const TQCString &name)
const TQValueList< Property * > * children() const
ListData * listData() const
TQVariant option(const char *name) const
Property * parent() const
static const Property null
A contant for null property.
void addRelatedProperty(Property *property)
void clearModifiedFlag()
Clears "modified" flag, so isModified() will return false.
void setReadOnly(bool readOnly)
void setCaption(const TQString &caption)
void addChild(Property *prop)
TQString description() const
void setName(const TQCString &name)
void setVisible(bool visible)
void setValue(const TQVariant &value, bool rememberOldValue=true, bool useCustomProperty=true)
const TQValueList< Property * > * related() const
TQString captionForDisplaying() const
bool operator==(const Property &prop) const
void setListData(ListData *list)
TQVariant oldValue() const
void setCustomProperty(CustomProperty *prop)
void emitPropertyChanged()
void setOption(const char *name, const TQVariant &val)
void setDescription(const TQString &description)
void setIcon(const TQString &icon)
Lists holding properties in groups.
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.