00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "DynamicPropertiesList.h"
00021
00022
00023
00024 DynamicPropertiesList* DynamicPropertiesList::self = 0;
00025
00026 DynamicPropertiesList::DynamicPropertiesList( QObject* parent ): QObject( parent )
00027 {
00028
00029 }
00030
00031
00032 DynamicPropertiesList* DynamicPropertiesList::New()
00033 {
00034 if( DynamicPropertiesList::self == 0 )
00035 {
00036 DynamicPropertiesList::self = new DynamicPropertiesList();
00037 }
00038 return DynamicPropertiesList::self;
00039 }
00040
00041
00042 void DynamicPropertiesList::addProperty( QObject* obj, QString name )
00043 {
00044
00045 Node* node = qobject_cast< Node* >( obj );
00046 if( node )
00047 {
00048 QMap< Graph*, QMultiMap <QString, Node* > >::iterator multimap = _NodesProperties.find( node->graph() );
00049 if( multimap == _NodesProperties.end() )
00050 {
00051 QMultiMap <QString, Node* > newMap;
00052 multimap = _NodesProperties.insert( node->graph(), newMap );
00053 }
00054
00055 multimap.value().insert( name, node );
00056
00057 return;
00058 }
00059
00060 Edge* edge = qobject_cast< Edge* >( obj );
00061 if( edge )
00062 {
00063 QMap< Graph*, QMultiMap <QString, Edge* > >::iterator multimap = _EdgesProperties.find( edge->graph() );
00064 if( multimap == _EdgesProperties.end() )
00065 {
00066 QMultiMap <QString, Edge* > newMap;
00067 multimap = _EdgesProperties.insert( edge->graph(), newMap );
00068 }
00069 multimap.value().insert( name, edge );
00070 return;
00071 }
00072
00073 Graph* graph = qobject_cast< Graph* >( obj );
00074 if( graph )
00075 {
00076 _GraphProperties.insert( name, graph );
00077 return;
00078 }
00079 }
00080
00081
00082 void DynamicPropertiesList::removeProperty( QObject* obj, QString name )
00083 {
00084 Node* node = qobject_cast< Node* >( obj );
00085 if( node )
00086 {
00087 QMap< Graph*, QMultiMap <QString, Node* > >::iterator multimap = _NodesProperties.find( node->graph() );
00088 if( multimap == _NodesProperties.end() )
00089 {
00090 return;
00091 }
00092 multimap.value().remove( name, node );
00093
00094 return;
00095 }
00096
00097 Edge* edge = qobject_cast< Edge* >( obj );
00098 if( edge )
00099 {
00100 QMap< Graph*, QMultiMap <QString, Edge* > >::iterator multimap = _EdgesProperties.find( edge->graph() );
00101 if( multimap == _EdgesProperties.end() )
00102 {
00103 return;
00104 }
00105 multimap.value().remove( name, edge );
00106 return;
00107 }
00108
00109 Graph* graph = qobject_cast< Graph* >( obj );
00110 if( graph )
00111 {
00112 _GraphProperties.remove( name, graph );
00113 return;
00114 }
00115 }
00116
00117 DynamicPropertyType DynamicPropertiesList::type( QObject* obj, QString name )
00118 {
00119 Node* node = qobject_cast< Node* >( obj );
00120 if( node )
00121 {
00122 QMap< Graph*, QMultiMap <QString, Node* > >::iterator multimap = _NodesProperties.find( node->graph() );
00123 if( multimap == _NodesProperties.end() )
00124 {
00125 return None;
00126 }
00127 QList <Node*> list = multimap.value().values( name );
00128
00129 if( node->graph()->nodes().size() == list.size() )
00130 {
00131 return Global;
00132 }
00133 switch( list.size() )
00134 {
00135 case 0 :
00136 return None;
00137 case 1 :
00138 return Unique;
00139 default :
00140 return Multiple;
00141 }
00142 }
00143
00144 Edge* edge = qobject_cast< Edge* >( obj );
00145 if( edge )
00146 {
00147 QMap< Graph*, QMultiMap <QString, Edge* > >::iterator multimap = _EdgesProperties.find( edge->graph() );
00148 if( multimap == _EdgesProperties.end() )
00149 {
00150 return None;
00151 }
00152 QList <Edge*> list = multimap.value().values( name );
00153 if( edge->graph()->edges().size() == list.size() )
00154 {
00155 return Global;
00156 }
00157 switch( list.size() )
00158 {
00159 case 0 :
00160 return None;
00161 case 1 :
00162 return Unique;
00163 default :
00164 return Multiple;
00165 }
00166 }
00167
00168 Graph* graph = qobject_cast< Graph* >( obj );
00169 if( graph )
00170 {
00171 if( _GraphProperties.values( name ).size() == 0 )
00172 {
00173 return None;
00174 }
00175 else
00176 {
00177 return Unique;
00178 }
00179 }
00180 return None;
00181 }
00182
00183 QString DynamicPropertiesList::typeInText( QObject* obj, QString name )
00184 {
00185 switch( type( obj, name ) )
00186 {
00187 case Unique:
00188 return i18n( "Unique" );
00189 case Multiple:
00190 return i18n( "Multiple" );
00191 case Global:
00192 return i18n( "Global" );
00193 case None:
00194 default:
00195 return i18n( "None" );
00196 }
00197 }
00198
00199
00200
00201 void DynamicPropertiesList::clear( Graph* graph )
00202 {
00203 if( graph != 0 )
00204 {
00205 _EdgesProperties.values( graph ).clear();
00206 foreach( QString name, _GraphProperties.keys( graph ) )
00207 {
00208 _GraphProperties.remove( name, graph );
00209 }
00210
00211 _NodesProperties.values( graph ).clear();
00212 }
00213 else
00214 {
00215 _EdgesProperties.clear();
00216 _GraphProperties.clear();
00217 _NodesProperties.clear();
00218
00219 }
00220 }
00221
00222
00223 void DynamicPropertiesList::changePropertyName( QString name, QString newName, QObject* object )
00224 {
00225 Node* node = qobject_cast< Node* >( object );
00226 if( node )
00227 {
00228 QMap< Graph*, QMultiMap <QString, Node* > >::iterator multimap = _NodesProperties.find( node->graph() );
00229 if( multimap == _NodesProperties.end() )
00230 {
00231 return;
00232 }
00233 foreach( node, multimap.value().values( name ) )
00234 {
00235 node->addDynamicProperty( newName, node->property( name.toUtf8() ) );
00236 node->removeDynamicProperty( name );
00237 }
00238 }
00239 Edge* edge = qobject_cast< Edge* >( object );
00240 if( edge )
00241 {
00242 QMap< Graph*, QMultiMap <QString, Edge* > >::iterator multimap = _EdgesProperties.find( edge->graph() );
00243 if( multimap == _EdgesProperties.end() )
00244 {
00245 return;
00246 }
00247
00248 foreach( edge, multimap.value().values( name ) )
00249 {
00250 edge->addDynamicProperty( newName, edge->property( name.toUtf8() ) );
00251 edge->removeDynamicProperty( name );
00252 }
00253 }
00254 Graph* graph = qobject_cast<Graph*>( object );
00255 if( graph )
00256 {
00257 graph->addDynamicProperty( newName, graph->property( name.toUtf8() ) );
00258 graph->removeDynamicProperty( name );
00259 }
00260
00261 }