The class OB_Browser implements public API of an object browser widget
that can be used to display arbitrary application data in a hierarchical form.
- It is based on Qt4 model/view architecture.
+ It is based on Qt4 model/view architecture.
Object browser can be used with conjuction of any custom item model inherited
from QAbstractItemModel class (see Qt 4 reference manual).
mySearchTool->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
mySearchTool->setActivators( QtxSearchTool::StandardKey | QtxSearchTool::SlashKey );
mySearchTool->setSearcher( new QtxTreeViewSearcher( myView ) );
-
+
QVBoxLayout* main = new QVBoxLayout( this );
main->addWidget( myView );
main->addWidget( mySearchTool );
\brief Expand all branches to the specified number of levels.
If \a levels value is negative, then autoOpenLevel() value is used instead.
-
+
\param levels number of levels to be expanded
\sa autoOpenLevel()
*/
\brief Select/deselect specified model index.
\param index model index to be selected/deselected
\param on if \c true, the index will be selected, otherwise - deselected
- \param keepSelection if \c true (default) the previous selection is kept,
+ \param keepSelection if \c true (default) the previous selection is kept,
otherwise it is first cleared
*/
void OB_Browser::select( const QModelIndex& index, const bool on, const bool keepSelection )
\brief Select/deselect specified model indices.
\param indexes model indices to be selected/deselected
\param on if \c true, the indices will be selected, otherwise - deselected
- \param keepSelection if \c true (default) the previous selection is kept,
+ \param keepSelection if \c true (default) the previous selection is kept,
otherwise it is first cleared
*/
void OB_Browser::select( const QModelIndexList& indexes, const bool on, const bool keepSelection )
myView->setExpanded( index, open ); // hasChildren() ???
}
+/*!
+ \brief Expand the all parent items of item specifed by the \index.
+ \param index model index to be opened
+*/
+void OB_Browser::expandTo( const QModelIndex& index )
+{
+ myView->expandTo( index );
+}
+
/*!
\brief Adjust first column width to its contents.
*/
void OB_Browser::contextMenuEvent( QContextMenuEvent* e )
{
QMenu* popup = new QMenu();
-
+
createPopupMenu( popup );
Qtx::simplifySeparators( popup );
\return latest updating time
*/
unsigned long OB_Browser::getModifiedTime() const
-{
- return myModifiedTime;
+{
+ return myModifiedTime;
}
/*!
/*!
\brief Called when "Expand all" popup menu command is activated.
-
+
Expands all selected items recursively.
*/
void OB_Browser::onExpandAll()
/*!
\brief Called when "Collapse all" popup menu command is activated.
-
+
Collapse all selected items recursively.
*/
void OB_Browser::onCollapseAll()
QModelIndexList indexes = selectedIndexes();
bool closed = false, opened = false;
-
- for ( QModelIndexList::Iterator it = indexes.begin();
+
+ for ( QModelIndexList::Iterator it = indexes.begin();
it != indexes.end() && !closed; ++it ) {
closed = hasCollased( *it );
}
- for ( QModelIndexList::Iterator it = indexes.begin();
+ for ( QModelIndexList::Iterator it = indexes.begin();
it != indexes.end() && !opened; ++it ) {
opened = hasExpanded( *it );
}
// 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
+// 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
+//
+// 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
+// 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/ or email : webmaster.salome@opencascade.com
QtxSearchTool* searchTool() const;
bool isSearchToolEnabled() const;
void setSearchToolEnabled( const bool );
-
+
int autoOpenLevel() const;
void setAutoOpenLevel( const int );
void openLevels( const int = -1 );
bool isOpen( const QModelIndex& ) const;
virtual void setOpen( const QModelIndex& theObject, const bool theOpen = true );
+ void expandTo( const QModelIndex& );
+
void adjustWidth();
void adjustFirstColumnWidth();
void adjustColumnsWidth();
unsigned long getModifiedTime() const;
void setModified();
-
+
// san - moved to SUIT_TreeModel
//OB_Updater* getUpdater() const;
//virtual void setUpdater( OB_Updater* theUpdate = 0 );
//void onDestroyed( SUIT_DataObject* );
//void onDoubleClicked ( QListViewItem* );
//void onDropped( QPtrList<QListViewItem>, QListViewItem*, int );
-
+
protected:
//void adjustWidth( QListViewItem* );
//virtual void updateText();
{
QTranslator* trans = new QtxTranslator( 0 );
QString fname = fileName( sect, prefix, name );
+ if ( fname.isEmpty() )
+ return 0;
+
if ( !trans->load( Qtx::file( fname, false ), Qtx::dir( fname ) ) )
{
+ qDebug( "Can't to load translation file '%s'", (const char*)fname.toLatin1() );
delete trans;
trans = 0;
}
+ else {
+ qDebug( "Translation file '%s' is loaded successfully", (const char*)fname.toLatin1() );
+ }
+
return trans;
}
QFile file( fname );
if ( !file.open( QFile::ReadOnly ) )
{
- qDebug( "File cannot be opened" );
+ qDebug( "File '%s' cannot be opened", (const char*)fname.toLatin1() );
return false;
}
lst.prepend( *iter );
QTranslator* trans = 0;
-
+
for ( ResList::Iterator it = lst.begin(); it != lst.end(); ++it )
{
for ( QStringList::ConstIterator itr = translators.begin(); itr != translators.end(); ++itr )
// 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
+// 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
+//
+// 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
+// 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/ or email : webmaster.salome@opencascade.com
\param orders orders[i] contains sort order for section logicalIndices[i]
\internal
*/
-void QtxTreeView::Header::setSortIndicators( const QVector<int>& logicalIndices,
+void QtxTreeView::Header::setSortIndicators( const QVector<int>& logicalIndices,
const QVector<Qt::SortOrder>& orders )
{
mySortSections = logicalIndices;
\param orders Out parameter, orders[i] contains the current sort order for section logicalIndices[i]
\internal
*/
-void QtxTreeView::Header::sortIndicators( QVector<int>& logicalIndices,
+void QtxTreeView::Header::sortIndicators( QVector<int>& logicalIndices,
QVector<Qt::SortOrder>& orders ) const
{
logicalIndices.clear();
orders.clear();
-
+
if ( isSortIndicatorShown() ){
logicalIndices.push_back( sortIndicatorSection() );
orders.push_back ( sortIndicatorOrder () );
style()->drawItemText( painter,
//rect,
QRect( rect.left(), rect.top(), rect.width() - 2, rect.height() ),
- Qt::AlignRight,
+ Qt::AlignRight,
opt.palette,
( opt.state & QStyle::State_Enabled ),
QString( "%1" ).arg( ++sortIndex ),
else if ( qVariantCanConvert<QPixmap>( iconData ) )
icon = qVariantValue<QPixmap>( iconData );
}
- if ( ( !lab.isEmpty() || !icon.isNull() ) &&
+ if ( ( !lab.isEmpty() || !icon.isNull() ) &&
appropriate.isValid() ? appropriate.toBool() : true ) {
QAction* a = menu.addAction( icon, lab );
a->setCheckable( true );
\brief Tree view class with possibility to display columns popup menu.
The QtxTreeView class represents a customized tree view class. In addition to the
- base functionality inherited from the QTreeView class, clicking at the tree view
+ base functionality inherited from the QTreeView class, clicking at the tree view
header with the right mouse button displays the popup menu allowing the user
to show/hide specified columns.
the data model (see QAbstractItemModel class). The custom model should implement
headerData() method and return \c true for the Qtx::AppropriateRole role for
those columns which should be available in the popup menu and \c false for the columns
- which should not be added to it.
+ which should not be added to it.
*/
/*!
/*!
\brief Expand all branches for specified number of levels.
-
+
If \c levels < 0, all branches are expanded (the same results can
be achieved with expandAll() method).
/*!
\brief Collapse all branches for specified number of levels.
-
+
If \c levels < 0, all branches are collapsed (the same results can
be achieved with collapseAll() method).
setOpened( index, -1, false );
}
+/*!
+ \brief Expand the all parent items of item specifed by the \index.
+ \param index model index to be opened
+ \sa expandAll()
+*/
+void QtxTreeView::expandTo( const QModelIndex& index )
+{
+ if ( !index.isValid() )
+ return;
+
+ QModelIndex idx = index.parent();
+ while ( idx.isValid() ) {
+ expand( idx );
+ idx = idx.parent();
+ }
+}
+
/*
\brief Enable/disable "Sorting" popup menu command for the header.
\param enableSortMenu if \c true, enable "Sorting" menu command
void QtxTreeView::setSortingEnabled( const bool enable )
{
Header* h = dynamic_cast<Header*>( header() );
- if ( h )
+ if ( h )
h->setSortingEnabled( enable );
}
/*!
\brief Enables multi-column sorting.
- As soon as multi-column sorting is enabled, the user can click
+ As soon as multi-column sorting is enabled, the user can click
several header sections in required order while holding <Ctrl> key so as to sort the contents
of the tree view on a basis of these columns' values. The column clicked first
has maximum sort priority, the column clicked last has minimum sort priority.
/*!
\brief Called when the selection is changed.
-
+
Emits selectionChanged() signal.
-
+
\param selected new selection
\param deselected previous selection
*/
-void QtxTreeView::selectionChanged( const QItemSelection& selected,
+void QtxTreeView::selectionChanged( const QItemSelection& selected,
const QItemSelection& deselected )
{
QTreeView::selectionChanged( selected, deselected );
// 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
+// 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
+//
+// 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
+// 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/ or email : webmaster.salome@opencascade.com
void setMultiSortEnabled( const bool );
bool multiSortEnabled() const;
+ void expandTo( const QModelIndex& );
+
protected slots:
void onHeaderClicked();
void rowsAboutToBeRemoved( const QModelIndex&, int, int );
void selectionChanged( const QItemSelection&, const QItemSelection& );
-
+
protected:
void setOpened( const QModelIndex&, const int, bool );
virtual void drawRow( QPainter*, const QStyleOptionViewItem&,
// 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
+// 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
+//
+// 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
+// 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/ or email : webmaster.salome@opencascade.com
//
// File : SUIT_DataBrowser.cxx
// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
-//
+//
#include "SUIT_DataBrowser.h"
#include <SUIT_TreeModel.h>
#include <QtxTreeView.h>
#include <QShortcut>
+#include <QModelIndex>
/*!
\class SUIT_DataBrowser
void SUIT_DataBrowser::setRoot( SUIT_DataObject* r )
{
SUIT_ProxyModel* m = qobject_cast<SUIT_ProxyModel*>( model() );
- if ( m )
+ if ( m )
m->setRoot( r );
}
void SUIT_DataBrowser::setAutoUpdate( const bool on, const bool updateImmediately )
{
SUIT_ProxyModel* m = qobject_cast<SUIT_ProxyModel*>( model() );
- if ( m )
+ if ( m )
m->setAutoUpdate( on, updateImmediately );
}
}
/*!
- \brief Get current key accelerator used for the
+ \brief Get current key accelerator used for the
object browser update operation.
\return current key accelerator
\sa setUpdateKey(), requestUpdate()
}
/*!
- \brief Assign the key accelerator to be used for the
+ \brief Assign the key accelerator to be used for the
object browser update operation.
By default, \c [F5] key is assigned for the update operation.
if ( m ) {
QModelIndexList sel = selectedIndexes();
QModelIndex idx;
-
+
foreach( idx, sel ) {
SUIT_DataObject* obj = m->object( idx );
if ( obj )
}
}
+/*!
+ \brief Expand the all parent items of item specifed by the \obj.
+ \param obj data object to be opened
+*/
+void SUIT_DataBrowser::expandTo( const SUIT_DataObject* obj )
+{
+ SUIT_ProxyModel* m = qobject_cast<SUIT_ProxyModel*>( model() );
+
+ if ( m ) {
+ QModelIndex index = m->index( obj );
+ if ( index.isValid() )
+ OB_Browser::expandTo( index );
+ }
+}
+
+/*!
+ \brief Scroll the contents of the object browser until the given data object \obj is visible.
+ The \hint parameter specifies where the object should be located after the operation.
+ \param obj data object to be visible
+*/
+void SUIT_DataBrowser::scrollTo( const SUIT_DataObject* obj, QAbstractItemView::ScrollHint hint )
+{
+ SUIT_ProxyModel* m = qobject_cast<SUIT_ProxyModel*>( model() );
+
+ if ( m ) {
+ QModelIndex index = m->index( obj );
+ if ( index.isValid() )
+ treeView()->scrollTo( index, hint );
+ }
+}
+
/*!
\brief Add custom actions to the popup menu.
\param menu popup menu
/*!
\brief Set 'auto-size columns' flag value.
- If this flag is set to \c true (by default is false), columns width except
+ If this flag is set to \c true (by default is false), columns width except
the first column is resized to its contents.
\param on 'auto-size columns' flag value
{
SUIT_ProxyModel* m = new SUIT_ProxyModel( root, this );
connect( m, SIGNAL( modelUpdated() ), this, SLOT( onModelUpdated() ) );
-
+
setModel( m );
setItemDelegate( qobject_cast<SUIT_ProxyModel*>( model() )->delegate() );
- connect( treeView(), SIGNAL( sortingEnabled( bool ) ),
+ connect( treeView(), SIGNAL( sortingEnabled( bool ) ),
model(), SLOT( setSortingEnabled( bool ) ) );
- connect( treeView(), SIGNAL( doubleClicked( const QModelIndex& ) ),
+ connect( treeView(), SIGNAL( doubleClicked( const QModelIndex& ) ),
this, SLOT( onDblClicked( const QModelIndex& ) ) );
- connect( treeView(), SIGNAL( expanded( const QModelIndex& ) ),
+ connect( treeView(), SIGNAL( expanded( const QModelIndex& ) ),
this, SLOT( onExpanded( const QModelIndex& ) ) );
myShortcut = new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) );
/*!
\brief Called when item is double-clicked in the tree view
\internal
-
+
Emits signal doubleClicked( SUIT_DataObject* );
*/
void SUIT_DataBrowser::onDblClicked( const QModelIndex& index )
// 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
+// 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
+//
+// 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
+// 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/ or email : webmaster.salome@opencascade.com
//
// File : SUIT_DataBrowser.h
// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
-//
+//
#ifndef SUIT_DATABROWSER_H
#define SUIT_DATABROWSER_H
#include "SUIT.h"
#include "SUIT_PopupClient.h"
#include "SUIT_DataObject.h"
+
#include <OB_Browser.h>
+#include <QAbstractItemView>
+
class QShortcut;
class SUIT_EXPORT SUIT_DataBrowser : public OB_Browser, public SUIT_PopupClient
void setSelected( const SUIT_DataObject*, const bool = false );
void setSelected( const DataObjectList&, const bool = false );
+ void expandTo( const SUIT_DataObject* );
+ void scrollTo( const SUIT_DataObject*, QAbstractItemView::ScrollHint = QAbstractItemView::EnsureVisible );
+
virtual void contextMenuPopup( QMenu* );
void setAutoSizeFirstColumn( const bool on );
(*it)->dump( indent + 2 );
}
+/*!
+ \brief Notify the data model about data object changes.
+*/
+void SUIT_DataObject::dataChanged()
+{
+ signal()->emitChanged( this );
+}
+
/*!
\class SUIT_DataObject::Signal
\brief Watcher class, responsible for the emitting signals on behalf of
emit created( object );
}
+/*!
+ \brief Emit signal about data object changes.
+ \param object data object being changed
+*/
+void SUIT_DataObject::Signal::emitChanged( SUIT_DataObject* object )
+{
+ if ( object )
+ emit changed( object );
+}
+
/*!
\brief Emit signal about data object destroying.
\param object data object being destroyed
void dump( const int indent = 2 ) const; // dump to cout
+protected:
+ void dataChanged();
+
private:
SUIT_DataObject* myParent;
bool myOpen;
private:
void emitCreated( SUIT_DataObject* );
+ void emitChanged( SUIT_DataObject* );
void emitDestroyed( SUIT_DataObject* );
void emitInserted( SUIT_DataObject*, SUIT_DataObject* );
void emitRemoved( SUIT_DataObject*, SUIT_DataObject* );
signals:
void created( SUIT_DataObject* );
+ void changed( SUIT_DataObject* );
void destroyed( SUIT_DataObject* );
- void inserted( SUIT_DataObject*, SUIT_DataObject* );
void removed( SUIT_DataObject*, SUIT_DataObject* );
+ void inserted( SUIT_DataObject*, SUIT_DataObject* );
friend class SUIT_DataObject;
// 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
+// 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
+//
+// 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
+// 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/ or email : webmaster.salome@opencascade.com
QList<TreeItem*> children() const;
TreeItem* nextSibling() const;
TreeItem* prevSibling() const;
-
+
private:
TreeItem* myParent;
QList<TreeItem*> myChildren;
\param parent parent item
\param after tree item after each this one should be inserted
*/
-SUIT_TreeModel::TreeItem::TreeItem( SUIT_DataObject* obj,
+SUIT_TreeModel::TreeItem::TreeItem( SUIT_DataObject* obj,
SUIT_TreeModel::TreeItem* parent,
SUIT_TreeModel::TreeItem* after )
: myParent( parent ),
\param child child item being inserted
\param after tree item after each \a child should be inserted
*/
-void SUIT_TreeModel::TreeItem::insertChild( SUIT_TreeModel::TreeItem* child,
+void SUIT_TreeModel::TreeItem::insertChild( SUIT_TreeModel::TreeItem* child,
SUIT_TreeModel::TreeItem* after )
{
if ( !child )
/*!
\class SUIT_TreeModel::TreeSync
- \brief Functor class for synchronizing data tree and tree model
+ \brief Functor class for synchronizing data tree and tree model
when the data tree is changed outside the model.
\internal
*/
\brief Check if item corresponds to the specified data object.
\internal
\param obj data object
- \param item tree item
+ \param item tree item
\return \c true if item corresponds to the data object
*/
bool SUIT_TreeModel::TreeSync::isEqual( const ObjPtr& obj, const ItemPtr& item ) const
\return created item
*/
SUIT_TreeModel::ItemPtr SUIT_TreeModel::TreeSync::createItem( const ObjPtr& obj,
- const ItemPtr& parent,
+ const ItemPtr& parent,
const ItemPtr& after ) const
{
ItemPtr item = myModel ? myModel->createItem( obj, parent, after ) : 0;
{
if( obj )
obj->update();
- if ( item && needUpdate( item ) )
+ if ( item && needUpdate( item ) )
myModel->updateItem( item );
}
QList<SUIT_TreeModel::ItemPtr> SUIT_TreeModel::TreeSync::children( const ItemPtr& item ) const
{
QList<ItemPtr> ch;
- if ( item )
+ if ( item )
ch = item->children();
return ch;
}
// 1. check text
/* update = ( item->text( 0 ) != obj->name() ) || myBrowser->needToUpdateTexts( item );
- if ( !update ) {
+ if ( !update ) {
// 2. check pixmap (compare serialNumber()-s)
QPixmap objPix = obj->icon();
const QPixmap* itemPix = item->pixmap( 0 );
- update = ( objPix.isNull() && ( itemPix && !itemPix->isNull() ) ) ||
- ( !objPix.isNull() && ( !itemPix || itemPix->isNull() ) );
+ update = ( objPix.isNull() && ( itemPix && !itemPix->isNull() ) ) ||
+ ( !objPix.isNull() && ( !itemPix || itemPix->isNull() ) );
if ( !update && !objPix.isNull() && itemPix && !itemPix->isNull() ) {
int aIconW = objPix.width();
if( aIconW > 20 ) {
\brief Implementation of the model/view API based on the tree of SUIT_DataObject class
instances.
- The SUIT_TreeModel class does not support insertion/removal of rows. It is synchronized
- automatically with the tree of data objects used by SUIT-based applications to
+ The SUIT_TreeModel class does not support insertion/removal of rows. It is synchronized
+ automatically with the tree of data objects used by SUIT-based applications to
expose their data in a hierarchical form to the user.
*/
switch ( role ) {
case DisplayRole:
// data object text for the specified column
- val = obj->text( index.column() );
+ val = obj->text( index.column() );
break;
case DecorationRole:
// data object icon for the specified column
- val = obj->icon( index.column() );
+ val = obj->icon( index.column() );
break;
case ToolTipRole:
// data object tooltip for the specified column
- val = obj->toolTip( index.column() );
+ val = obj->toolTip( index.column() );
break;
case StatusTipRole:
// data object status tip for the specified column
- val = obj->statusTip( index.column() );
+ val = obj->statusTip( index.column() );
break;
case WhatsThisRole:
// data object what's this info for the specified column
- val = obj->whatsThis( index.column() );
+ val = obj->whatsThis( index.column() );
break;
case FontRole:
// data object font for the specified column
- val = obj->font( index.column() );
+ val = obj->font( index.column() );
break;
case TextAlignmentRole:
// data object text alignment for the specified column
- val = obj->alignment( index.column() );
+ val = obj->alignment( index.column() );
break;
case BackgroundRole:
// data background color for the specified column
c = obj->color( SUIT_DataObject::Background, index.column() );
// NOTE by san: Zero alpha is treated as fully transparent, therefore no background
// is drawn at all (that is, the base color will appear instead of the custom backround).
- // However, maximum alpha (each QColor has alpha == 1.0f by default) might be also unacceptable
- // since it disables blending effects that might be used by a custom style.
+ // However, maximum alpha (each QColor has alpha == 1.0f by default) might be also unacceptable
+ // since it disables blending effects that might be used by a custom style.
// Thus applications should choose color's alpha themselves to get required visual result.
if ( !c.isValid() ){ // default value, should be fully transparent
c = QApplication::palette().color( QPalette::Base );
c.setAlpha( 0 );
}
- val = c;
+ val = c;
break;
case ForegroundRole:
// data foreground (text) color for the specified column
c = obj->color( SUIT_DataObject::Foreground, index.column() );
if ( !c.isValid() ) // default value
c = QApplication::palette().color( QPalette::Foreground );
- val = c;
+ val = c;
break;
case BaseColorRole:
// editor background color for the specified column
c = obj->color( SUIT_DataObject::Base, index.column() );
if ( !c.isValid() ) // default value
c = QApplication::palette().color( QPalette::Base );
- val = c;
+ val = c;
break;
case TextColorRole:
// editor foreground (text) color for the specified column
c = obj->color( SUIT_DataObject::Text, index.column() );
if ( !c.isValid() ) // default value
c = QApplication::palette().color( QPalette::Text );
- val = c;
+ val = c;
break;
case HighlightRole:
// adta object highlighted background color for the specified column
c = obj->color( SUIT_DataObject::Highlight, index.column() );
if ( !c.isValid() ) // default value
c = QApplication::palette().color( QPalette::Highlight );
- val = c;
+ val = c;
break;
case HighlightedTextRole:
// data object highlighted foreground (text) color for the specified column
c = obj->color( SUIT_DataObject::HighlightedText, index.column() );
if ( !c.isValid() ) // default value
c = QApplication::palette().color( QPalette::HighlightedText );
- val = c;
+ val = c;
break;
case CheckStateRole:
// data object checked state for the specified column
// NOTE! three-state check is not supported currently
if ( obj->isCheckable( index.column() ) )
- val = obj->isOn( index.column() ) ? Qt::Checked : Qt::Unchecked;
+ val = obj->isOn( index.column() ) ? Qt::Checked : Qt::Unchecked;
break;
case SizeHintRole:
// data size hint
\return \c true if data is set
\sa data()
*/
-bool SUIT_TreeModel::setData( const QModelIndex& index,
+bool SUIT_TreeModel::setData( const QModelIndex& index,
const QVariant& value, int role )
{
if ( index.isValid() && value.isValid() ) {
\param parent parent model index
\return model index
*/
-QModelIndex SUIT_TreeModel::index( int row, int column,
+QModelIndex SUIT_TreeModel::index( int row, int column,
const QModelIndex& parent ) const
{
if ( hasIndex( row, column, parent ) ) {
else if ( obj->root() != root() )
return;
- synchronize<ObjPtr,ItemPtr,SUIT_TreeModel::TreeSync>( obj,
- treeItem( obj ),
+ synchronize<ObjPtr,ItemPtr,SUIT_TreeModel::TreeSync>( obj,
+ treeItem( obj ),
SUIT_TreeModel::TreeSync( this ) );
emit modelUpdated();
}
{
if ( item == rootItem() )
return root();
-
+
SUIT_DataObject* obj = item ? item->dataObject() : 0;
return myItems.contains( obj ) ? obj : 0;
}
\return created tree item or 0 if item could not be created
*/
SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItem( SUIT_DataObject* obj,
- SUIT_TreeModel::TreeItem* parent,
+ SUIT_TreeModel::TreeItem* parent,
SUIT_TreeModel::TreeItem* after )
{
if ( !obj )
{
if ( !item )
return;
-
+
SUIT_DataObject* obj = object( item );
if ( !obj )
return;
-
+
// update all columns corresponding to the given data object
QModelIndex firstIdx = index( obj, 0 );
QModelIndex lastIdx = index( obj, obj->columnCount() - 1 );
removeItem( item->child( 0 ) );
SUIT_DataObject* obj = object( item );
-
+
// Warning! obj can be deleted at this point!
SUIT_DataObject* parentObj = object( item->parent() );
QModelIndex parentIdx = index( parentObj, 0 );
int row = item->position();
-
+
beginRemoveRows( parentIdx, row, row );
myItems.remove( obj );
updateTree( parent );
}
+/*!
+ \brief Called when the data object is changed.
+ \param object data object being changed
+*/
+void SUIT_TreeModel::onChanged( SUIT_DataObject* obj )
+{
+ QModelIndex idx = index( obj );
+ if ( idx.isValid() )
+ emit dataChanged( idx, idx );
+}
+
/*!
\brief Called when the data object is removed from the tree.
\param object data object being removed
This class can be used to render the SUIT_DataObject-based item
in the widgets like QTreeView and others.
- Refer to the Qt 4 documentation, model/view architecture
+ Refer to the Qt 4 documentation, model/view architecture
section for more details).
*/
\param option painting option
\param index model index being rendered
*/
-void SUIT_ItemDelegate::paint( QPainter* painter,
+void SUIT_ItemDelegate::paint( QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
// 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
+// 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
+//
+// 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
+// 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/ or email : webmaster.salome@opencascade.com
class TreeSync;
typedef SUIT_DataObject* ObjPtr;
typedef SUIT_TreeModel::TreeItem* ItemPtr;
-
+
public:
//! Data role
typedef enum {
virtual void updateTree( SUIT_DataObject* = 0 );
signals:
- void modelUpdated();
+ void modelUpdated();
private:
void initialize();
SUIT_DataObject* object( const TreeItem* ) const;
TreeItem* createItem( SUIT_DataObject*,
- TreeItem* = 0,
+ TreeItem* = 0,
TreeItem* = 0 );
void updateItem( TreeItem* );
void removeItem( TreeItem* );
private slots:
+ void onChanged( SUIT_DataObject* );
void onInserted( SUIT_DataObject*, SUIT_DataObject* );
void onRemoved( SUIT_DataObject*, SUIT_DataObject* );
private:
typedef QMap<SUIT_DataObject*, TreeItem*> ItemMap;
-
+
SUIT_DataObject* myRoot;
TreeItem* myRootItem;
ItemMap myItems;
bool autoUpdate() const;
void setAutoUpdate( const bool, const bool = true );
-
+
QAbstractItemDelegate* delegate() const;
public slots:
public:
SUIT_ItemDelegate( QObject* = 0 );
-
+
virtual void paint( QPainter*, const QStyleOptionViewItem&,
const QModelIndex& ) const;
};