}
/*!Private SLOT. Support drag-and-drop operation.*/
-void LightApp_Application::onDropped (const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex& parent)
+void LightApp_Application::onDropped( const QList<SUIT_DataObject*>& objects, SUIT_DataObject* parent, int row, Qt::DropAction action )
{
- if (action == Qt::IgnoreAction)
+ LightApp_DataObject* parentObj = dynamic_cast<LightApp_DataObject*>( parent );
+ if ( !parentObj )
return;
- if (!data->hasFormat("application/vnd.text.list"))
- return;
-
- if (column > 0)
- return;
-
- if (!parent.isValid())
- // dropping into the top level of the model is not allowed
- return;
-
- SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>(objectBrowser()->model());
-
- SUIT_DataObject* obj = treeModel->object(parent);
- if (!obj)
- return;
-
- LightApp_DataObject* parentObj = dynamic_cast<LightApp_DataObject*>(obj);
- if (!parentObj)
- return;
-
- // decode mime data
- QByteArray encodedData = data->data("application/vnd.text.list");
- QDataStream stream (&encodedData, QIODevice::ReadOnly);
- QStringList newItems;
-
- while (!stream.atEnd()) {
- QString text;
- stream >> text;
- if (!text.isEmpty())
- newItems << text;
- }
-
- DataObjectList listObjs;
- foreach (QString text, newItems) {
- SUIT_DataObject* anObji = findObject(text);
- if (anObji)
- listObjs.append(anObji);
- }
-
- // tmp: clear selection to avoid problem with persistent data model indexes
- //mySelMgr->clearSelected();
-
- LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(parentObj->module());
- if (aModule)
- aModule->dropObjects(listObjs, action, parentObj, row);
+ LightApp_Module* aModule = dynamic_cast<LightApp_Module*>( parentObj->module() );
+ if ( aModule )
+ aModule->dropObjects( objects, parentObj, row, action );
}
/*!Private SLOT. On preferences.*/
// Mantis issue 0020136: Drag&Drop in OB
SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
- connect( proxyModel, SIGNAL(dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&)),
- this, SLOT(onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&)) );
+ if ( proxyModel ) {
+ connect( proxyModel, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
+ this, SLOT( onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
+ }
// temporary commented
/*
val = obj->text( id );
break;
case DecorationRole: {
- if(id == SUIT_DataObject::VisibilityId) {
- int anId = obj->customData(Qtx::IdType).toInt();
- QString objId = data(createIndex(index.row(),anId,index.internalPointer())).toString();
- if(myVisibilityMap.contains(objId)) {
+ // icon
+ if ( id == SUIT_DataObject::VisibilityId ) {
+ // for visibility column, icon is defined specifically (using data object id)
+ QString objId = objectId( index );
+ if ( myVisibilityMap.contains( objId ) ) {
+ // visibility status is defined -> return proper icon
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
- val = (myVisibilityMap.value(objId) == Qtx::ShownState) ?
- resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" )) : resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ));
- } else {
+ val = ( myVisibilityMap.value( objId ) == Qtx::ShownState ) ?
+ resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) :
+ resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) );
+ }
+ else {
+ // visibility status is undefined -> no icon
val = QIcon();
}
- } else {
+ }
+ else {
+ // for other columns get icon from the object
val = obj->icon( id );
}
break;
*/
Qt::ItemFlags SUIT_TreeModel::flags( const QModelIndex& index ) const
{
- /*
- if ( !index.isValid() )
- return 0;
-
- SUIT_DataObject* obj = object( index );
- Qt::ItemFlags f = 0;
-
- if ( obj ) {
- // data object is enabled
- if ( obj->isEnabled() )
- f = f | Qt::ItemIsEnabled;
-
- // data object is selectable
- if ( obj->isSelectable() )
- f = f | Qt::ItemIsSelectable;
-
- // data object is checkable
- if ( obj->isCheckable( index.column() ) )
- f = f | Qt::ItemIsUserCheckable;
-
- // data object can be renamed
- if ( obj->renameAllowed( index.column() ) )
- f = f | Qt::ItemIsEditable;
- }
-
- return f;
- */
-
Qt::ItemFlags f = 0;
if (!index.isValid())
return Qt::CopyAction | Qt::MoveAction;
}
-//This function is never called
-bool SUIT_TreeModel::removeRows(int row, int count, const QModelIndex &parent)
-{
- qDebug("Remove");
- if (parent.isValid())
- return FALSE;
-
- beginRemoveRows(parent, row, row + count - 1);
-
- for (int i = 0; i < count; ++i){
- //delete m_pAllData->takeAt(row);
- }
-
- endRemoveRows();
- return TRUE;
-}
-
/*!
\brief Get header data (can be used in any data view).
\param column column number
return root() ? root()->customSorting( column ) : false;
}
+void SUIT_TreeModel::forgetObject( const SUIT_DataObject* obj )
+{
+ removeItem( treeItem( obj ) );
+}
+
/*!
\brief Compares two model indexes for the sorting purposes.
return myItems.contains( obj ) ? obj : 0;
}
+/*!
+ \brief Get unique object identifier
+
+ Object identifier is customized via the Qtx::IdType custom data
+
+ \param index model index
+ \return object identifier or null string if it isn't specified
+ \sa SUIT_DataObject::customData()
+*/
+QString SUIT_TreeModel::objectId( const QModelIndex& index ) const
+{
+ QString objId;
+ if ( index.isValid() ) {
+ SUIT_DataObject* obj = object( index );
+ if ( obj ) {
+ int anId = obj->customData( Qtx::IdType ).toInt();
+ objId = data( createIndex( index.row(), anId, index.internalPointer() ) ).toString();
+ }
+ }
+ return objId;
+}
+
/*!
\brief Create an item corresponding to the data object.
\param obj source data object
\brief Called when the data objects are exported(dragged) from the tree.
\param indexes the list of exported objects
*/
-QMimeData* SUIT_TreeModel::mimeData (const QModelIndexList &indexes) const
+QMimeData* SUIT_TreeModel::mimeData( const QModelIndexList& indexes ) const
{
- QMimeData *mimeData = new QMimeData();
+ QMimeData* mimeData = new QMimeData();
QByteArray encodedData;
- QDataStream stream (&encodedData, QIODevice::WriteOnly);
+ QDataStream stream( &encodedData, QIODevice::WriteOnly );
- foreach (QModelIndex index, indexes) {
- if (index.isValid()) {
- if (index.column() == 0) {
- SUIT_DataObject* aDObj = object(index);
- QString anEntry = aDObj->text(SUIT_DataObject::VisibilityId + 1);
- stream << anEntry;
- }
- }
+ foreach ( QModelIndex index, indexes ) {
+ QString id = objectId( index );
+ // we have to check only 0 column in order to avoid repeating items in the drag object
+ // - QTreeView tries to drag indices for all visible columns
+ if ( index.isValid() && index.column() == 0 && !id.isEmpty() )
+ stream << id;
}
- mimeData->setData("application/vnd.text.list", encodedData);
+ mimeData->setData( "application/vnd.text.list", encodedData );
return mimeData;
}
-bool SUIT_TreeModel::dropMimeData (const QMimeData* data, Qt::DropAction action,
- int row, int column, const QModelIndex& parent)
+bool SUIT_TreeModel::dropMimeData( const QMimeData* data, Qt::DropAction action,
+ int row, int column, const QModelIndex& parent )
{
- emit dropped(data, action, row, column, parent);
+ if ( action == Qt::IgnoreAction )
+ // do nothing with data
+ return false;
- return true;
+ if ( !data->hasFormat( "application/vnd.text.list" ) )
+ // not supported data dropped
+ return false;
+
+ if ( !parent.isValid() )
+ // dropping into the top level of the model is not allowed
+ return false;
+
+ // get parent object
+ SUIT_DataObject* pobj = object( parent );
+ if ( !pobj )
+ // invalid parent
+ return false;
+
+ // decode mime data and collect data objects being dropped
+ QByteArray encodedData = data->data( "application/vnd.text.list" );
+ QDataStream stream( &encodedData, QIODevice::ReadOnly );
+
+ DataObjectList objects;
+
+ while ( !stream.atEnd() ) {
+ QString id;
+ stream >> id;
+ if ( !id.isEmpty() && searcher() ) {
+ SUIT_DataObject* obj = searcher()->findObject( id );
+ if ( obj ) objects << obj;
+ }
+ }
+
+ // emit signal
+ emit dropped( objects, pobj, row, action );
+
+ // return true if there's any to drop
+ return !objects.isEmpty();
}
/*!
{
SUIT_TreeModel* model = new SUIT_TreeModel( this );
connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) );
- connect( model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) );
- connect( model, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ),
- //this, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ));
- this, SLOT( onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ));
+ connect( model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL(clicked( SUIT_DataObject*, int ) ) );
+ connect( model, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
+ this, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
setSourceModel( model );
setDynamicSortFilter( true );
}
{
SUIT_TreeModel* model = new SUIT_TreeModel( root, this );
connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) );
- connect( model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) );
- connect( model, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ),
- //this, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ));
- this, SLOT( onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ));
+ connect( model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL( clicked( SUIT_DataObject*, int ) ) );
+ connect( model, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
+ this, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
setSourceModel( model );
setDynamicSortFilter( true );
}
mySortingEnabled( true )
{
connect( *model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) );
- connect( *model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) );
- connect( *model, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ),
- //this, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ));
- this, SLOT( onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ));
+ connect( *model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL( clicked( SUIT_DataObject*, int ) ) );
+ connect( *model, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
+ this, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
setSourceModel( *model );
setDynamicSortFilter( true );
}
treeModel()->updateTree( obj );
}
+void SUIT_ProxyModel::forgetObject( const SUIT_DataObject* obj )
+{
+ if ( treeModel() )
+ treeModel()->forgetObject( obj );
+}
+
/*!
\brief Compares two model indexes for the sorting purposes.
\param left first index to compare
\param flags - header flags
*/
-void SUIT_ProxyModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) {
+void SUIT_ProxyModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags )
+{
if(treeModel())
treeModel()->setHeaderFlags(name, flags);
}
\param name - column name
\return header flags
*/
-Qtx::HeaderViewFlags SUIT_ProxyModel::headerFlags( const QString& name ) const {
+Qtx::HeaderViewFlags SUIT_ProxyModel::headerFlags( const QString& name ) const
+{
return treeModel() ? treeModel()->headerFlags( name ) : Qtx::ShowAll;
}
\param id - column name
\param state - visible state
*/
-void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState state) {
+void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState state)
+{
if(treeModel())
treeModel()->setVisibilityState(id,state);
}
\param id - column name
\param state - visible state
*/
-void SUIT_ProxyModel::setVisibilityStateForAll(Qtx::VisibilityState state) {
+void SUIT_ProxyModel::setVisibilityStateForAll(Qtx::VisibilityState state)
+{
if(treeModel())
treeModel()->setVisibilityStateForAll(state);
}
\param id - column name
\return visible state
*/
-Qtx::VisibilityState SUIT_ProxyModel::visibilityState(const QString& id) const {
+Qtx::VisibilityState SUIT_ProxyModel::visibilityState(const QString& id) const
+{
return treeModel() ? treeModel()->visibilityState(id) : Qtx::UnpresentableState;
}
-void SUIT_ProxyModel::emitClicked( SUIT_DataObject* obj, const QModelIndex& index) {
+void SUIT_ProxyModel::emitClicked( SUIT_DataObject* obj, const QModelIndex& index)
+{
if(treeModel())
treeModel()->emitClicked(obj,index);
}
-void SUIT_ProxyModel::onDropped (const QMimeData* data, Qt::DropAction action,
- int row, int column, const QModelIndex& parent)
-{
- emit dropped(data, action, row, column, mapFromSource(parent));
-}
-
/*!
\class SUIT_ItemDelegate
\brief An SUIT_DataObject-based item delegate class.
virtual QAbstractItemDelegate* delegate() const = 0;
virtual bool customSorting( const int ) const = 0;
virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const = 0;
+ virtual void forgetObject( const SUIT_DataObject* ) = 0;
virtual void updateTree( const QModelIndex& ) = 0;
virtual void updateTree( SUIT_DataObject* = 0 ) = 0;
virtual QVariant headerData( int, Qt::Orientation, int = Qt::DisplayRole ) const;
virtual Qt::DropActions supportedDropActions() const;
- virtual bool removeRows(int row, int count, const QModelIndex &parent);
virtual QModelIndex index( int, int, const QModelIndex& = QModelIndex() ) const;
virtual QModelIndex parent( const QModelIndex& ) const;
virtual bool customSorting( const int ) const;
virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
+ virtual void forgetObject( const SUIT_DataObject* );
QAbstractItemDelegate* delegate() const;
signals:
void modelUpdated();
void clicked( SUIT_DataObject*, int );
- void dropped( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& );
+ void dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction );
private:
void initialize();
TreeItem* treeItem( const QModelIndex& ) const;
TreeItem* treeItem( const SUIT_DataObject* ) const;
SUIT_DataObject* object( const TreeItem* ) const;
+ QString objectId( const QModelIndex& = QModelIndex() ) const;
TreeItem* createItem( SUIT_DataObject*, TreeItem* = 0, TreeItem* = 0 );
TreeItem* createItemAtPos( SUIT_DataObject*, TreeItem* = 0, int pos=0 );
bool isSortingEnabled() const;
bool customSorting( const int ) const;
+ virtual void forgetObject( const SUIT_DataObject* );
virtual bool lessThan( const QModelIndex&, const QModelIndex& ) const;
virtual void registerColumn( const int group_id, const QString& name, const int custom_id );
virtual void unregisterColumn( const int group_id, const QString& name );
virtual void updateTree( const QModelIndex& );
virtual void updateTree( SUIT_DataObject* = 0 );
void setSortingEnabled( bool );
- void onDropped( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& );
signals:
void modelUpdated();
void clicked( SUIT_DataObject*, int );
- void dropped( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& );
+ void dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction );
protected:
SUIT_AbstractModel* treeModel() const;