Commit 5859b4f4 authored by Stéphane Albert's avatar Stéphane Albert

REFAC: Factorized specific drag-and-drop (move) into TreeWidgetItem base class.

parent 53bfd09f
......@@ -39,6 +39,7 @@ set( Common_Gui_SOURCES
mvdSearchableTreeWidget.cxx
mvdStatusBarWidget.cxx
mvdTaskProgressDialog.cxx
mvdTreeWidget.cxx
mvdTreeWidgetItem.cxx
)
......@@ -83,6 +84,7 @@ set( Common_Gui_HEADERS_MOC
mvdSearchableTreeWidget.h
mvdStatusBarWidget.h
mvdTaskProgressDialog.h
mvdTreeWidget.h
#mvdTreeWidgetItem.h
)
......
......@@ -66,16 +66,11 @@ namespace mvd
/*******************************************************************************/
DatabaseTreeWidget
::DatabaseTreeWidget( QWidget* parent ):
QTreeWidget( parent),
m_DatasetFilename(""),
m_EditionActive(false)
TreeWidget( parent ),
m_DatasetFilename(),
m_EditionActive( false )
{
setDefaultDropAction( Qt::MoveAction );
// setMouseTracking(true);
setDragEnabled( true );
setAcceptDrops( true );
// setup contextual menu
InitializeContextualMenu();
......@@ -315,71 +310,6 @@ DatabaseTreeWidget::dropEvent(QDropEvent *event)
#endif // BYPASS_DRAG_AND_DROP_EVENTS
}
/*******************************************************************************/
QStringList
DatabaseTreeWidget
::mimeTypes() const
{
// qDebug() << this << "::mimeTypes()";
QStringList mimeTypes( QTreeWidget::mimeTypes() );
mimeTypes << "application/x-qtreewidgetitemptrlist";
return mimeTypes;
}
/*******************************************************************************/
QMimeData*
DatabaseTreeWidget
::mimeData( const QList< QTreeWidgetItem* > items ) const
{
qDebug() << this << "::mimeData(" << items << ")";
QMimeData* mimeData = QTreeWidget::mimeData( items );
typedef QList< QTreeWidgetItem* > QTreeWidgetItemList;
QByteArray byteArray;
QDataStream stream( &byteArray, QIODevice::WriteOnly );
for( QTreeWidgetItemList::const_iterator it( items.begin() );
it!=items.end();
++it )
{
/*
qDebug()
<< "QTreeWidgetItem::parent()==" << ( *it )->parent();
qDebug()
<< "Pointer:" << static_cast< void* >( *it );
qDebug()
<< "Variant:" << QVariant::fromValue< QTreeWidgetItem* >( *it );
*/
// http://www.qtfr.org/viewtopic.php?id=9630
// stream << *it;
stream << QVariant::fromValue< QTreeWidgetItem* >( *it );
}
mimeData->setData( "application/x-qtreewidgetitemptrlist", byteArray );
/*
qDebug() << mimeData->formats();
for( QTreeWidgetItemList::const_iterator it( items.begin() );
it!=items.end();
++it )
{
QTreeWidgetItem* item = *it;
qDebug()
<< item->type() << item->text( 0 ) << item->text( 1 ) << item->text( 2 );
}
*/
return mimeData;
}
/*******************************************************************************/
bool
DatabaseTreeWidget::dropMimeData( QTreeWidgetItem* parent,
......
......@@ -44,7 +44,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "Gui/mvdTreeWidget.h"
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
......@@ -79,7 +79,7 @@ namespace Ui
* widget class.
*/
class Monteverdi2_EXPORT DatabaseTreeWidget :
public QTreeWidget
public TreeWidget
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
......@@ -150,9 +150,6 @@ protected:
//
// QTreeWidget overloads.
virtual QStringList mimeTypes () const;
virtual QMimeData* mimeData( const QList< QTreeWidgetItem* > items ) const;
virtual bool dropMimeData( QTreeWidgetItem* parent,
int index,
......
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "mvdTreeWidget.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
#include "Core/mvdAlgorithm.h"
#include "Core/mvdDataStream.h"
#include "Gui/mvdTreeWidgetItem.h"
namespace mvd
{
/*
TRANSLATOR mvd::TreeWidget
Necessary for lupdate to be aware of C++ namespaces.
Context comment for translator.
*/
/*****************************************************************************/
/* CONSTANTS */
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
class StaticInitializer
{
public:
StaticInitializer() :
m_QTreeWidgetItemPtrMetaTypeId( -1 )
{
Initialize();
}
~StaticInitializer()
{
Finalize();
}
private:
inline
void
Initialize()
{
//
// Call qRegisterMetaType<>() to make type available in
// non-template signatures and serialization.
StaticInitializer::m_QTreeWidgetItemPtrMetaTypeId =
qRegisterMetaType< QTreeWidgetItem* >( "QTreeWidgetItem *" );
//
// Register serialization operators for custom meta-types.
qRegisterMetaTypeStreamOperators< QTreeWidgetItem* >();
}
inline
void
Finalize()
{
}
int m_QTreeWidgetItemPtrMetaTypeId;
};
namespace
{
static const StaticInitializer STATIC_INITIALIZER;
}
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
TreeWidget
::TreeWidget( QWidget* parent ):
QTreeWidget( parent )
{
setDefaultDropAction( Qt::MoveAction );
setDragEnabled( true );
setAcceptDrops( true );
}
/*******************************************************************************/
TreeWidget
::~TreeWidget()
{
}
/*******************************************************************************/
QStringList
TreeWidget
::mimeTypes() const
{
// qDebug() << this << "::mimeTypes()";
QStringList mimeTypes( QTreeWidget::mimeTypes() );
mimeTypes << "application/x-qtreewidgetitemptrlist";
return mimeTypes;
}
/*******************************************************************************/
QMimeData*
TreeWidget
::mimeData( const QList< QTreeWidgetItem* > items ) const
{
qDebug() << this << "::mimeData(" << items << ")";
QMimeData* mimeData = QTreeWidget::mimeData( items );
typedef QList< QTreeWidgetItem* > QTreeWidgetItemList;
QByteArray byteArray;
QDataStream stream( &byteArray, QIODevice::WriteOnly );
for( QTreeWidgetItemList::const_iterator it( items.begin() );
it!=items.end();
++it )
{
/*
qDebug()
<< "QTreeWidgetItem::parent()==" << ( *it )->parent();
qDebug()
<< "Pointer:" << static_cast< void* >( *it );
qDebug()
<< "Variant:" << QVariant::fromValue< QTreeWidgetItem* >( *it );
*/
// http://www.qtfr.org/viewtopic.php?id=9630
// stream << *it;
stream << QVariant::fromValue< QTreeWidgetItem* >( *it );
}
mimeData->setData( "application/x-qtreewidgetitemptrlist", byteArray );
/*
qDebug() << mimeData->formats();
for( QTreeWidgetItemList::const_iterator it( items.begin() );
it!=items.end();
++it )
{
QTreeWidgetItem* item = *it;
qDebug()
<< item->type() << item->text( 0 ) << item->text( 1 ) << item->text( 2 );
}
*/
return mimeData;
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
} // end namespace 'mvd'
/*****************************************************************************/
/* GLOBAL FUNCTIONS IMPLEMENTATION SECTION */
#if TREE_WIDGET_ITEM_USE_STREAM_OPERATORS
/*****************************************************************************/
QDataStream&
operator << ( QDataStream& out, QTreeWidgetItem const * item )
{
/*
qDebug() <<
"QDataStream& operator << ( QDataStream&, QTreeWidgetItem const * & );";
*/
#if DATA_STREAM_USE_TEMPLATE_OPERATORS
return operator << < QTreeWidgetItem >( out, item );
#else // DATA_STREAM_USE_TEMPLATE_OPERATORS
DATA_STREAM_OUT( out, QTreeWidgetItem, item );
return out;
#endif // DATA_STREAM_USE_TEMPLATE_OPERATORS
}
/*****************************************************************************/
QDataStream&
operator >>( QDataStream& in, QTreeWidgetItem * & item )
{
/*
qDebug() <<
"QDataStream& operator >> ( QDataStream&, QTreeWidgetItem * & );";
*/
#if DATA_STREAM_USE_TEMPLATE_OPERATORS
return operator >> < QTreeWidgetItem >( in, item );
#else // DATA_STREAM_USE_TEMPLATE_OPERATORS
DATA_STREAM_IN( in, QTreeWidgetItem, item );
return in;
#endif // DATA_STREAM_USE_TEMPLATE_OPERATORS
}
#endif // TREE_WIDGET_ITEM_USE_STREAM_OPERATORS
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __mvdTreeWidget_h
#define __mvdTreeWidget_h
//
// Configuration include.
//// Included at first position before any other ones.
#include "ConfigureMonteverdi2.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
#include <QtGui>
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
{
}
namespace mvd
{
//
// Internal classes pre-declaration.
namespace Ui
{
//class TreeWidget;
};
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class TreeWidget
*
* \brief Widget template skeleton to copy-paste when adding a new
* widget class.
*/
class Monteverdi2_EXPORT TreeWidget :
public QTreeWidget
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT;
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
/** \brief Constructor. */
TreeWidget( QWidget* parent =NULL );
/** \brief Destructor. */
virtual ~TreeWidget();
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
//
// Public SLOTS.
public slots:
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
// Signals.
signals:
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
//
// QTreeWidget overloads.
virtual QStringList mimeTypes() const;
virtual QMimeData* mimeData( const QList< QTreeWidgetItem* > items ) const;
//
// Protected attributes.
protected:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private methods.
private:
//
// Private attributes.
private:
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
//
// Slots.
private slots:
};
} // end namespace 'mvd'
/*****************************************************************************/
/* GLOBAL FUNCTIONS DECLARATION */
//
// Declare Qt tree-widget item pointer types so they can be wrapped by
// QVariant.
Q_DECLARE_METATYPE( QTreeWidgetItem* );
#define TREE_WIDGET_ITEM_USE_STREAM_OPERATORS 1
#if TREE_WIDGET_ITEM_USE_STREAM_OPERATORS
/**
*/
QDataStream&
operator << ( QDataStream& out, QTreeWidgetItem const * item );
/**
*/
QDataStream&
operator >>( QDataStream& in, QTreeWidgetItem * & item );
#endif // !DATASTREAM_USE_TEMPLATE_OPERATORS
/*****************************************************************************/
/* INLINE SECTION */
namespace mvd
{
} // end namespace 'mvd'
#endif // __mvdTreeWidget_h
......@@ -38,7 +38,6 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "Core/mvdDataStream.h"
namespace mvd
{
......@@ -62,50 +61,6 @@ namespace
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
class StaticInitializer
{
public:
StaticInitializer() :
m_QTreeWidgetItemPtrMetaTypeId( -1 )
{
Initialize();
}
~StaticInitializer()
{
Finalize();
}
private:
inline
void
Initialize()
{
//
// Call qRegisterMetaType<>() to make type available in
// non-template signatures and serialization.
StaticInitializer::m_QTreeWidgetItemPtrMetaTypeId =
qRegisterMetaType< QTreeWidgetItem* >( "QTreeWidgetItem *" );
//
// Register serialization operators for custom meta-types.
qRegisterMetaTypeStreamOperators< QTreeWidgetItem* >();
}
inline
void
Finalize()
{
}
int m_QTreeWidgetItemPtrMetaTypeId;
};
namespace
{
static const StaticInitializer STATIC_INITIALIZER;
}
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
......@@ -180,50 +135,3 @@ TreeWidgetItem
}
} // end namespace 'mvd'
/*****************************************************************************/
/* GLOBAL FUNCTIONS IMPLEMENTATION SECTION */
#if TREE_WIDGET_ITEM_USE_STREAM_OPERATORS
/*****************************************************************************/
QDataStream&
operator << ( QDataStream& out, QTreeWidgetItem const * item )
{
/*
qDebug() <<
"QDataStream& operator << ( QDataStream&, QTreeWidgetItem const * & );";
*/
#if DATA_STREAM_USE_TEMPLATE_OPERATORS
return operator << < QTreeWidgetItem >( out, item );
#else // DATA_STREAM_USE_TEMPLATE_OPERATORS
DATA_STREAM_OUT( out, QTreeWidgetItem, item );
return out;
#endif // DATA_STREAM_USE_TEMPLATE_OPERATORS
}
/*****************************************************************************/
QDataStream&
operator >>( QDataStream& in, QTreeWidgetItem * & item )
{
/*
qDebug() <<
"QDataStream& operator >> ( QDataStream&, QTreeWidgetItem * & );";
*/
#if DATA_STREAM_USE_TEMPLATE_OPERATORS
return operator >> < QTreeWidgetItem >( in, item );
#else // DATA_STREAM_USE_TEMPLATE_OPERATORS
DATA_STREAM_IN( in, QTreeWidgetItem, item );
return in;
#endif // DATA_STREAM_USE_TEMPLATE_OPERATORS
}
#endif // TREE_WIDGET_ITEM_USE_STREAM_OPERATORS
......@@ -197,33 +197,7 @@ private slots:
// Declare TreeWidgetItem meta-type so it can be used for drag-and-drop
// operations.
Q_DECLARE_METATYPE( mvd::TreeWidgetItem );
//
// Pointer and const-pointer must be declared in order to be wrapped
// by QVariant.
Q_DECLARE_METATYPE( mvd::TreeWidgetItem* );
Q_DECLARE_METATYPE( const mvd::TreeWidgetItem* );
*/
//
// Declare Qt tree-widget item pointer types so they can be wrapped by
// QVariant.
Q_DECLARE_METATYPE( QTreeWidgetItem* );
#define TREE_WIDGET_ITEM_USE_STREAM_OPERATORS 1
#if TREE_WIDGET_ITEM_USE_STREAM_OPERATORS
/**
*/
QDataStream&
operator << ( QDataStream& out, QTreeWidgetItem const * item );
/**
*/
QDataStream&
operator >>( QDataStream& in, QTreeWidgetItem * & item );
#endif // !DATASTREAM_USE_TEMPLATE_OPERATORS
/*****************************************************************************/
/* INLINE SECTION */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment