+// 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
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 );
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 )
{
Item* pItem = item( pId );
if ( pItem )
+ {
i = pItem->createItem( label, type );
+ pItem->insertChild( i );
+ }
}
return i;
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
{
}
+void QtxResourceEdit::itemAdded( Item* )
+{
+}
+
+void QtxResourceEdit::itemRemoved( Item* )
+{
+}
+
/*
Class: QtxResourceEdit::Item
Descr: Class for incapsulation of one preference item
QtxResourceEdit::Item::Item( QtxResourceEdit* edit, Item* parent )
: myEdit( edit ),
-myParent( parent )
+myParent( 0 )
{
myId = generateId();
+
+ if ( parent )
+ parent->insertChild( this );
}
QtxResourceEdit::Item::~Item()
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;