diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 47d455dd55be855e4cc691c32f687f723d9247ee (patch) | |
tree | 52e236aaa2576bdb3840ebede26619692fed6d7d /kpovmodeler/pmblob.cpp | |
download | tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpovmodeler/pmblob.cpp')
-rw-r--r-- | kpovmodeler/pmblob.cpp | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/kpovmodeler/pmblob.cpp b/kpovmodeler/pmblob.cpp new file mode 100644 index 00000000..800c3b5a --- /dev/null +++ b/kpovmodeler/pmblob.cpp @@ -0,0 +1,175 @@ +/* +************************************************************************** + description + -------------------- + copyright : (C) 2002 by Andreas Zehender + email : [email protected] +************************************************************************** + +************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +**************************************************************************/ + + +#include "pmblob.h" + +#include "pmxmlhelper.h" +#include "pmblobedit.h" +#include "pmmemento.h" + +#include <klocale.h> + +const double c_defaultThreshold = 0.5; +bool c_defaultSturm = false; +bool c_defaultHierarchy = false; + +PMDefinePropertyClass( PMBlob, PMBlobProperty ); + +PMMetaObject* PMBlob::s_pMetaObject = 0; +PMObject* createNewBlob( PMPart* part ) +{ + return new PMBlob( part ); +} + +PMBlob::PMBlob( PMPart* part ) + : Base( part ) +{ + m_threshold = c_defaultThreshold; + m_sturm = c_defaultSturm; + m_hierarchy = c_defaultHierarchy; +} + +PMBlob::PMBlob( const PMBlob& b ) + : Base( b ) +{ + m_threshold = b.m_threshold; + m_sturm = b.m_sturm; + m_hierarchy = b.m_hierarchy; +} + +PMBlob::~PMBlob( ) +{ +} + +QString PMBlob::description( ) const +{ + return i18n( "blob" ); +} + +void PMBlob::serialize( QDomElement& e, QDomDocument& doc ) const +{ + e.setAttribute( "threshold", m_threshold ); + e.setAttribute( "sturm", m_sturm ); + e.setAttribute( "hierarchy", m_hierarchy ); + Base::serialize( e, doc ); +} + +void PMBlob::readAttributes( const PMXMLHelper& h ) +{ + m_threshold = h.doubleAttribute( "threshold", c_defaultThreshold ); + m_sturm = h.boolAttribute( "sturm", c_defaultSturm ); + m_hierarchy = h.boolAttribute( "hierarchy", c_defaultHierarchy ); + Base::readAttributes( h ); +} + +PMMetaObject* PMBlob::metaObject( ) const +{ + if( !s_pMetaObject ) + { + s_pMetaObject = new PMMetaObject( "Blob", Base::metaObject( ), + createNewBlob ); + s_pMetaObject->addProperty( + new PMBlobProperty( "threshold", &PMBlob::setThreshold, &PMBlob::threshold ) ); + s_pMetaObject->addProperty( + new PMBlobProperty( "hierarchy", &PMBlob::setHierarchy, &PMBlob::hierarchy ) ); + s_pMetaObject->addProperty( + new PMBlobProperty( "sturm", &PMBlob::setSturm, &PMBlob::sturm ) ); + } + return s_pMetaObject; +} + +void PMBlob::cleanUp( ) const +{ + if( s_pMetaObject ) + { + delete s_pMetaObject; + s_pMetaObject = 0; + } + Base::cleanUp( ); +} + +void PMBlob::setThreshold( double t ) +{ + if( t <= 0.0 ) + { + kdError( PMArea ) << "Threshold is not positive in PMBlob::setThreshold\n"; + t = 1.0; + } + + if( t != m_threshold ) + { + if( m_pMemento ) + m_pMemento->addData( s_pMetaObject, PMThresholdID, m_threshold ); + m_threshold = t; + } +} + +void PMBlob::setSturm( bool s ) +{ + if( s != m_sturm ) + { + if( m_pMemento ) + m_pMemento->addData( s_pMetaObject, PMSturmID, m_sturm ); + m_sturm = s; + } +} + +void PMBlob::setHierarchy( bool h ) +{ + if( h != m_hierarchy ) + { + if( m_pMemento ) + m_pMemento->addData( s_pMetaObject, PMHierarchyID, m_hierarchy ); + m_hierarchy = h; + } +} + +PMDialogEditBase* PMBlob::editWidget( QWidget* parent ) const +{ + return new PMBlobEdit( parent ); +} + +void PMBlob::restoreMemento( PMMemento* s ) +{ + PMMementoDataIterator it( s ); + PMMementoData* data; + + for( ; it.current( ); ++it ) + { + data = it.current( ); + if( data->objectType( ) == s_pMetaObject ) + { + switch( data->valueID( ) ) + { + case PMThresholdID: + setThreshold( data->doubleData( ) ); + break; + case PMSturmID: + setSturm( data->boolData( ) ); + break; + case PMHierarchyID: + setHierarchy( data->boolData( ) ); + break; + default: + kdError( PMArea ) << "Wrong ID in PMBlob::restoreMemento\n"; + break; + } + } + } + Base::restoreMemento( s ); +} |