]> SALOME platform Git repositories - modules/gui.git/blobdiff - src/Qtx/QtxResourceEdit.cxx
Salome HOME
Copyrights update
[modules/gui.git] / src / Qtx / QtxResourceEdit.cxx
index f9c9a4a6c84e59c557e55c2f7bb17d5afb84342c..e1c9e75385e796378ffc6c01600bbeda76e1fb1d 100644 (file)
@@ -1,3 +1,21 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 // File:      QtxResourceEdit.cxx
 // Author:    Sergey TELKOV
 
@@ -33,15 +51,23 @@ int QtxResourceEdit::addItem( const QString& label, const int pId, const int typ
   if ( !i )
     return -1;
 
-  myItems.insert( i->id(), i );
+  if ( !myItems.contains( i->id() ) )
+  {
+    myItems.insert( i->id(), i );
+
+    i->setTitle( label );
+    i->setResource( section, param );
 
-  i->setTitle( label );
-  i->setResource( section, param );
+    if ( !i->parentItem() && !myChildren.contains( i ) )
+      myChildren.append( i );
+
+    itemAdded( i );
+  }
 
   return i->id();
 }
 
-QVariant QtxResourceEdit::property( const int id, const QString& propName ) const
+QVariant QtxResourceEdit::itemProperty( const int id, const QString& propName ) const
 {
   QVariant propValue;
   Item* i = item( id );
@@ -50,7 +76,7 @@ QVariant QtxResourceEdit::property( const int id, const QString& propName ) cons
   return propValue;
 }
 
-void QtxResourceEdit::setProperty( const int id, const QString& propName, const QVariant& propValue )
+void QtxResourceEdit::setItemProperty( const int id, const QString& propName, const QVariant& propValue )
 {
   Item* i = item( id );
   if ( i )
@@ -153,7 +179,10 @@ QtxResourceEdit::Item* QtxResourceEdit::createItem( const QString& label, const
   {
     Item* pItem = item( pId );
     if ( pItem )
+    {
       i = pItem->createItem( label, type );
+      pItem->insertChild( i );
+    }
   }
 
   return i;
@@ -164,19 +193,39 @@ void QtxResourceEdit::removeItem( Item* item )
   if ( !item )
     return;
 
+  myChildren.remove( item );
   myItems.remove( item->id() );
+
+  itemRemoved( item );
+}
+
+void QtxResourceEdit::childItems( QPtrList<Item>& lst ) const
+{
+  lst.clear();
+  for ( QPtrListIterator<Item> it( myChildren ); it.current(); ++it )
+    lst.append( it.current() );
 }
 
 void QtxResourceEdit::resourceValues( QMap<int, QString>& map ) const
 {
+  QString sect, name;
   for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it )
-    map.insert( it.key(), it.data()->resourceValue() );
+  {
+    it.data()->resource( sect, name );
+    if( myResMgr->hasValue( sect, name ) )
+      map.insert( it.key(), it.data()->resourceValue() );
+  }
 }
 
 void QtxResourceEdit::resourceValues( QMap<Item*, QString>& map ) const
 {
+  QString sect, name;
   for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it )
-    map.insert( it.data(), it.data()->resourceValue() );
+  {
+    it.data()->resource( sect, name );
+    if( myResMgr->hasValue( sect, name ) )
+      map.insert( it.data(), it.data()->resourceValue() );
+  }
 }
 
 void QtxResourceEdit::setResourceValues( QMap<int, QString>& map ) const
@@ -228,6 +277,14 @@ void QtxResourceEdit::changedResources( const QMap<Item*, QString>& )
 {
 }
 
+void QtxResourceEdit::itemAdded( Item* )
+{
+}
+
+void QtxResourceEdit::itemRemoved( Item* )
+{
+}
+
 /*
   Class: QtxResourceEdit::Item
   Descr: Class for incapsulation of one preference item
@@ -235,9 +292,12 @@ void QtxResourceEdit::changedResources( const QMap<Item*, QString>& )
 
 QtxResourceEdit::Item::Item( QtxResourceEdit* edit, Item* parent )
 : myEdit( edit ),
-myParent( parent )
+myParent( 0 )
 {
   myId = generateId();
+
+  if ( parent )
+    parent->insertChild( this );
 }
 
 QtxResourceEdit::Item::~Item()
@@ -256,12 +316,38 @@ QtxResourceEdit::Item* QtxResourceEdit::Item::parentItem() const
   return myParent;
 }
 
+void QtxResourceEdit::Item::insertChild( Item* item )
+{
+  if ( !item || myChildren.contains( item ) )
+    return;
+
+  if ( item->parentItem() && item->parentItem() != this )
+    item->parentItem()->removeChild( item );
+
+  item->myParent = this;
+  myChildren.append( item );
+}
+
+void QtxResourceEdit::Item::removeChild( Item* item )
+{
+  if ( !item || !myChildren.contains( item ) )
+    return;
+
+  myChildren.remove( item );
+  item->myParent = 0;
+}
+
 void QtxResourceEdit::Item::childItems( QPtrList<Item>& lst ) const
 {
   for ( ItemListIterator it( myChildren ); it.current(); ++it )
     lst.append( it.current() );
 }
 
+bool QtxResourceEdit::Item::isEmpty() const
+{
+  return myChildren.isEmpty();
+}
+
 QString QtxResourceEdit::Item::title() const
 {
   return myTitle;