Commit 95cd69b3 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Replaced DatasetTreeWidgetItem by more generic TreeWidgetItem handling id, text etc.

parent add1c0f8
......@@ -209,7 +209,7 @@ DatabaseBrowserController
//...but force call to valueChanged() slot to force refresh.
widget->blockSignals( true );
{
#if 1
#if 0
// // TODO: Fill in widget.
widget->SetDatasetList( datasets );
#endif
......@@ -261,24 +261,25 @@ DatabaseBrowserController
switch( child->type() )
{
// Nodes.
case DatabaseBrowserWidget::ITEM_TYPE_NODE:
case TreeWidgetItem::ITEM_TYPE_NODE:
// assert( child->data( 1, Qt::UserRole + 1 ).isValid() );
qDebug()
<< "Node:"
<< child->text( 0 )
<< child->text( 1 )
<< child->data( 1, DatabaseBrowserWidget::ITEM_ROLE_ID );
<< child->data( 1, TreeWidgetItem::ITEM_ROLE_ID );
container = &nodes;
break;
// Leaves.
case DatabaseBrowserWidget::ITEM_TYPE_LEAF:
case TreeWidgetItem::ITEM_TYPE_LEAF:
// assert( item->data( 1, Qt::UserRole + 1 ).isValid() );
qDebug()
<< "Leaf:"
<< child->text( 0 )
<< child->text( 1 )
<< child->data( 1, DatabaseBrowserWidget::ITEM_ROLE_ID );
<< child->data( 1, TreeWidgetItem::ITEM_ROLE_ID )
<< child->text( 2 );
container = &leaves;
break;
......@@ -293,7 +294,7 @@ DatabaseBrowserController
{
TreeWidgetItemMap::iterator it(
container->insert(
child->data( 1, DatabaseBrowserWidget::ITEM_ROLE_ID ).toString(),
child->data( 1, TreeWidgetItem::ITEM_ROLE_ID ).toString(),
child
)
);
......@@ -306,7 +307,7 @@ DatabaseBrowserController
<< child->type()
<< it.value()->text( 0 )
<< it.value()->text( 1 )
<< it.value()->data( 1, DatabaseBrowserWidget::ITEM_ROLE_ID );
<< it.value()->data( 1, TreeWidgetItem::ITEM_ROLE_ID );
duplicates.push_back( it.value() );
}
......@@ -438,33 +439,45 @@ DatabaseBrowserController
for ( int topIdx = 0; topIdx < tree->topLevelItemCount(); topIdx++)
{
int nbChild = tree->topLevelItem(topIdx)->childCount();
for ( int idx = 0; idx < nbChild; idx++ )
{
TreeWidgetItem * currentDatasetItem =
dynamic_cast<TreeWidgetItem*>(
tree->topLevelItem(topIdx)->child(idx)
);
TreeWidgetItem* currentDatasetItem =
dynamic_cast< TreeWidgetItem* >(
tree->topLevelItem(topIdx)->child( idx )
);
if( currentDatasetItem!=NULL )
{
QString datasetHash( currentDatasetItem->GetHash() );
if( currentDatasetItem->GetType()==TreeWidgetItem::ITEM_TYPE_LEAF )
{
QString datasetHash( currentDatasetItem->GetHash() );
// qDebug() << "Checking dataset:" << currentDatasetItem->GetId();
qDebug()
<< "Checking dataset:"
<< currentDatasetItem->GetText()
<< currentDatasetItem->GetId()
<< currentDatasetItem->GetHash();
const DatasetModel* datasetModel = model->FindDatasetModel( datasetHash );
assert( datasetModel!=NULL );
const DatasetModel* datasetModel
= model->FindDatasetModel( datasetHash );
// check consistency
if ( !datasetModel->IsConsistent() )
{
// disable inconsistent dataset
currentDatasetItem->setDisabled(true);
assert( datasetModel!=NULL );
// check consistency
if ( !datasetModel->IsConsistent() )
{
// disable inconsistent dataset
currentDatasetItem->setDisabled(true);
// add forbidden icon
currentDatasetItem->setIcon(0, QIcon( ":/icons/forbidden" ));
// add forbidden icon
currentDatasetItem->setIcon(0, QIcon( ":/icons/forbidden" ));
// add tootlip
currentDatasetItem->setToolTip (0,tr ("Inconsistent Dataset disabled") );
// add tootlip
currentDatasetItem->setToolTip(
0,tr( "Inconsistent Dataset disabled" )
);
}
}
}
}
......
......@@ -88,6 +88,12 @@ DatabaseBrowserWidget
#endif
SetupUI();
/*
// Devember 12th, 2013 - Trainee example.
QPushButton* button=new QPushButton ("Click me", this);
layout()->addWidget(button);
*/
}
/*******************************************************************************/
......@@ -125,14 +131,7 @@ DatabaseBrowserWidget
return
InsertItem(
parent,
DatabaseBrowserWidget::ITEM_TYPE_NODE,
Qt::ItemIsEnabled |
#if BYPASS_MOUSE_EVENTS
Qt::ItemIsEditable |
Qt::ItemIsDragEnabled |
#endif
Qt::ItemIsDropEnabled,
QTreeWidgetItem::ShowIndicator,
TreeWidgetItem::ITEM_TYPE_NODE,
text,
id,
columns
......@@ -150,12 +149,7 @@ DatabaseBrowserWidget
return
InsertItem(
parent,
DatabaseBrowserWidget::ITEM_TYPE_LEAF,
Qt::ItemIsEnabled |
Qt::ItemIsSelectable |
Qt::ItemIsEditable |
Qt::ItemIsDragEnabled,
QTreeWidgetItem::DontShowIndicator,
TreeWidgetItem::ITEM_TYPE_LEAF,
text,
id,
columns
......@@ -166,26 +160,20 @@ DatabaseBrowserWidget
QTreeWidgetItem*
DatabaseBrowserWidget
::InsertItem( QTreeWidgetItem* parent,
ItemType type,
Qt::ItemFlags flags,
QTreeWidgetItem::ChildIndicatorPolicy policy,
TreeWidgetItem::ItemType type,
const QString& text,
const QVariant& id,
const QStringList& columns )
{
QTreeWidgetItem* item =
new QTreeWidgetItem(
TreeWidgetItem* item =
new TreeWidgetItem(
parent,
QStringList() << text << id.toString() << columns,
text,
id,
columns,
type
);
item->setData( 1, DatabaseBrowserWidget::ITEM_ROLE_ID, id );
item->setFlags( flags );
item->setChildIndicatorPolicy( policy );
return item;
}
......@@ -256,7 +244,12 @@ DatabaseBrowserWidget
const StringPairListType::value_type::second_type& hash = it->second;
TreeWidgetItem* item =
new TreeWidgetItem( m_DatasetRootItem, hash, alias );
new TreeWidgetItem(
m_DatasetRootItem,
alias,
QVariant(),
QStringList( hash )
);
// Item is visible is search-text is empty or if alias contains
// search-text.
......
......@@ -45,7 +45,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "Core/mvdTypes.h"
#include "Gui/mvdTreeWidgetItem.h"
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
......@@ -60,7 +60,6 @@ namespace mvd
{
class DatabaseTreeWidget;
class DatasetTreeWidgetItem;
//
// Internal classes pre-declaration.
namespace Ui
......@@ -88,20 +87,6 @@ class Monteverdi2_EXPORT DatabaseBrowserWidget :
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public types.
public:
enum ItemType
{
ITEM_TYPE_NODE = QTreeWidgetItem::UserType + 1,
ITEM_TYPE_LEAF = QTreeWidgetItem::UserType + 2,
};
enum ItemRole
{
ITEM_ROLE_ID = Qt::UserRole + 1,
};
//
// Public methods.
public:
......@@ -213,9 +198,7 @@ private:
/**
*/
QTreeWidgetItem* InsertItem( QTreeWidgetItem* parent,
ItemType type,
Qt::ItemFlags flags,
QTreeWidgetItem::ChildIndicatorPolicy policy,
TreeWidgetItem::ItemType type,
const QString& text,
const QVariant& id,
const QStringList& columns =QStringList() );
......
......@@ -65,13 +65,46 @@ namespace mvd
/*******************************************************************************/
TreeWidgetItem
::TreeWidgetItem( QTreeWidgetItem* parent,
const QString& id,
const QString& alias,
const QStringList& columns ) :
QTreeWidgetItem( parent, QStringList( alias ) << id << columns )
const QString& text,
const QVariant& id,
const QStringList& columns,
TreeWidgetItem::ItemType type ) :
QTreeWidgetItem( parent, QStringList( text ) << QString() << columns )
{
assert( !id.isEmpty() );
assert( text( 1 )==id );
SetId( id );
switch( type )
{
case TreeWidgetItem::ITEM_TYPE_NODE:
setChildIndicatorPolicy(
QTreeWidgetItem::DontShowIndicatorWhenChildless
);
setFlags(
Qt::ItemIsEnabled |
#if BYPASS_MOUSE_EVENTS
Qt::ItemIsEditable |
Qt::ItemIsDragEnabled |
#endif
Qt::ItemIsDropEnabled
);
break;
case TreeWidgetItem::ITEM_TYPE_LEAF:
setChildIndicatorPolicy(
QTreeWidgetItem::DontShowIndicator
);
setFlags(
Qt::ItemIsEnabled |
Qt::ItemIsSelectable |
Qt::ItemIsEditable |
Qt::ItemIsDragEnabled
);
break;
default:
assert( false );
break;
}
}
/*******************************************************************************/
......@@ -80,4 +113,12 @@ TreeWidgetItem
{
}
/*******************************************************************************/
QTreeWidgetItem*
TreeWidgetItem
::clone()
{
return new TreeWidgetItem( *this );
}
} // end namespace 'mvd'
......@@ -75,6 +75,21 @@ class Monteverdi2_EXPORT TreeWidgetItem :
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public types.
public:
enum ItemType
{
ITEM_TYPE_NONE = QTreeWidgetItem::UserType,
ITEM_TYPE_NODE = QTreeWidgetItem::UserType + 1,
ITEM_TYPE_LEAF = QTreeWidgetItem::UserType + 2,
};
enum ItemRole
{
ITEM_ROLE_ID = Qt::UserRole + 1,
};
//
// Public methods.
public:
......@@ -83,20 +98,41 @@ public:
* \brief Constructor.
*/
TreeWidgetItem( QTreeWidgetItem* parent,
const QString& id,
const QString& text,
const QStringList& columns = QStringList() );
const QVariant& id /*=QVariant()*/,
const QStringList& columns = QStringList(),
TreeWidgetItem::ItemType type =TreeWidgetItem::ITEM_TYPE_LEAF );
/**
* \brief Destructor.
*/
virtual ~TreeWidgetItem();
/**
*/
inline TreeWidgetItem::ItemType GetType() const;
/**
*/
inline QVariant GetId() const;
/**
*/
inline QString GetText() const;
/**
* \brief Get the datasetID
*/
inline QString GetHash() const;
//
// QTreeWidgetItem overloads.
/**
* \see http://qt-project.org/doc/qt-4.8/qtreewidgetitem.html#clone
*/
virtual QTreeWidgetItem* clone();
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
//
......@@ -125,6 +161,10 @@ protected:
// Private methods.
private:
/**
*/
inline void SetId( const QVariant& id );
//
// Private attributes.
private:
......@@ -145,13 +185,53 @@ private slots:
namespace mvd
{
/*******************************************************************************/
inline
TreeWidgetItem::ItemType
TreeWidgetItem
::GetType() const
{
return
type() < QTreeWidgetItem::UserType
? TreeWidgetItem::ITEM_TYPE_NONE
: TreeWidgetItem::ItemType( type() );
}
/*******************************************************************************/
inline
QVariant
TreeWidgetItem
::GetId() const
{
return data( 1, TreeWidgetItem::ITEM_ROLE_ID );
}
/*******************************************************************************/
inline
void
TreeWidgetItem
::SetId( const QVariant& id )
{
setData( 1, TreeWidgetItem::ITEM_ROLE_ID, id );
setText( 1, id.toString() );
}
/*******************************************************************************/
inline
QString
TreeWidgetItem
::GetText() const
{
return text( 0 );
}
/*******************************************************************************/
inline
QString
TreeWidgetItem
::GetHash() const
{
return text( 1 );
return text( 2 );
}
} // end namespace 'mvd'
......
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