Commit 61c6e0a9 authored by Dirk Wilden's avatar Dirk Wilden

improved treeModel

treeView now keeps expanded status of object

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5099 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ba0019f4
......@@ -53,9 +53,11 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
void DataControlPlugin::initializePlugin(){
}
//******************************************************************************
/** \brief Plugin initialization
*
*/
void DataControlPlugin::pluginsInitialized() {
//set the slot descriptions
......@@ -87,6 +89,14 @@ void DataControlPlugin::pluginsInitialized() {
}
//******************************************************************************
/** \brief initialize the toolBox
*
* @param _widget a reference to the toolBox
* @return returns if the toolbox was created successfully
*/
bool DataControlPlugin::initializeToolbox(QWidget*& _widget)
{
locked = false;
......@@ -119,8 +129,11 @@ bool DataControlPlugin::initializeToolbox(QWidget*& _widget)
connect( model_,SIGNAL(dataChanged( const QModelIndex&, const QModelIndex& ) ),
this,SLOT(slotDataChanged( const QModelIndex&, const QModelIndex& )));
connect( model_ , SIGNAL(rowsRemoved( const QModelIndex &, int , int ) ),
this , SLOT(slotRowsRemoved ( const QModelIndex &, int , int ) ) );
connect( model_ , SIGNAL( modelAboutToBeReset() ),
this , SLOT(slotModelAboutToReset() ) );
connect( model_ , SIGNAL( modelReset() ),
this , SLOT( slotModelResetComplete() ) );
connect( view_,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
this,SLOT(slotCustomContextMenuRequested ( const QPoint & ) ));
......@@ -138,54 +151,26 @@ bool DataControlPlugin::initializeToolbox(QWidget*& _widget)
return true;
}
void DataControlPlugin::slotObjectUpdated( int _identifier ) {
model_->updatedObject( _identifier );
}
void DataControlPlugin::slotCellClicked(int /*_row*/ , int /*_col*/) {
// if ( _col == 0 ) {
// QTableWidgetItem* target = objectList_->item(_row,_col);
// if ( target->checkState() == Qt::Checked ) {
// target->setCheckState(Qt::Unchecked);
// (*data_)[_row]->target(false);
// } else {
// target->setCheckState(Qt::Checked);
// (*data_)[_row]->target(true);
// }
// emit activeObjectChanged();
// }
}
//******************************************************************************
void DataControlPlugin::verticalHeaderClicked( int /*_row*/ ) {
// (*data_)[_row]->target ( !(*data_)[_row]->target() );
// QTableWidgetItem* target = objectList_->item(_row,3);
// if ( target->checkState() == Qt::Checked ) {
// target->setCheckState(Qt::Unchecked);
// (*data_)[_row]->target(false);
// } else {
// target->setCheckState(Qt::Checked);
// (*data_)[_row]->target(true);
// }
// emit activeObjectChanged();
// // QTableWidgetSelectionRange range(5,0,5,3);
// // objectList_->setRangeSelected(range,true);
/** \brief inform the model that it has to reset when an object changes
*
* @param _identifier id of an object
*/
void DataControlPlugin::slotObjectUpdated( int _identifier ) {
model_->updatedObject( _identifier );
}
void DataControlPlugin::verticalCountClicked( int /*id*/ , int /*old*/ , int /*newc*/ ) {
// emit log(LOGWARN,"VHeader : Count " + QString::number(id) + " " + QString::number(old) + " " + QString::number(newc));
}
//******************************************************************************
/** \brief update drawing of objects when the active object changed
*
*/
void DataControlPlugin::slotActiveObjectChanged()
{
///@todo set all target checkboxes right
// hint : dont call slotObjectUpdated -1 as this will do a redraw
// slotObjectUpdated(-1);
update_active();
}
void DataControlPlugin::update_active( ) {
// find changed manipulator
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
......@@ -217,84 +202,16 @@ void DataControlPlugin::update_active( ) {
emit updateView();
}
//******************************************************************************
/** \brief a key event occurred
*
* @param _event the event that occurred
*/
void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
{
// QList<QTableWidgetItem *> selected ;
// QList<QTableWidgetSelectionRange> ranges;
// switch (_event->key())
// {
// case Qt::Key_M :
// for ( uint i = 0 ; i < data_->size() ; ++i ) {
// QTableWidgetSelectionRange range(i,0,i,3);
// objectList_->setRangeSelected(range,true);
// }
// return;
//
// case Qt::Key_N :
// std::cerr << "Checking : " << std::endl;
// for ( uint i = 0 ; i < data_->size() ; ++i ) {
// QTableWidgetItem * item = objectList_->verticalHeaderItem ( i );
// if ( objectList_->isItemSelected(item) )
// std::cerr << i << item->text().toStdString() << " : yes" << std::endl;
// else {
// std::cerr << i << item->text().toStdString() << " : no" << std::endl;
// }
// }
//
// selected = objectList_->selectedItems();
// std::cerr << "Selected " << selected.size() << std::endl;
//
// ranges = objectList_->selectedRanges();
// std::cerr << "Ranges " << ranges.size() << std::endl;
//
// for ( int i = 0 ; i < ranges.size(); ++i ) {
// std::cerr << "Range " << i << " : " << ranges[i].topRow() << " .. " << ranges[i].bottomRow() << std::endl;
// std::cerr << "Range " << i << " : " << ranges[i].leftColumn() << " .. " << ranges[i].rightColumn() << std::endl;
// }
//
// return;
// case Qt::Key_C :
// if ( _event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) ) {
// for ( uint i = 0 ; i < data_->size() ; ++i ) {
// (*data_)[i]->source(false);
// }
// emit updatedObject(-1);
// return;
// }
//
// if ( _event->modifiers() == (Qt::AltModifier | Qt::ShiftModifier) ) {
// for ( uint i = 0 ; i < data_->size() ; ++i ) {
// (*data_)[i]->target(false);
// }
// emit updatedObject(-1);
// return;
// }
//
// return;
//
// case Qt::Key_A :
// if ( _event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) ) {
// for ( uint i = 0 ; i < data_->size() ; ++i ) {
// (*data_)[i]->source(true);
// }
// emit updatedObject(-1);
// return;
// }
//
// if ( _event->modifiers() == (Qt::AltModifier | Qt::ShiftModifier) ) {
// for ( uint i = 0 ; i < data_->size() ; ++i ) {
// (*data_)[i]->target(true);
// }
// emit updatedObject(-1);
// return;
// }
//
// return;
// default:
// break;
// }
if ( _event->modifiers() == Qt::ControlModifier ) {
switch (_event->key()) {
case Qt::Key_A :
......@@ -315,6 +232,14 @@ void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
}
//******************************************************************************
/** \brief emit the right updates when the model changed
*
* @param topLeft index in the model
* @param
*/
void DataControlPlugin::slotDataChanged ( const QModelIndex & topLeft,
const QModelIndex & /*bottomRight*/ )
{
......@@ -345,11 +270,67 @@ void DataControlPlugin::slotDataChanged ( const QModelIndex & topLeft,
}
}
void DataControlPlugin::slotRowsRemoved ( const QModelIndex & /*_parent*/, int /*_start*/, int /*_end*/ ) {
std::cerr << "Row removed! " << std::endl;
emit updateView();
//******************************************************************************
/** \brief Store the expanded status of all objects when the model wants to reset
*
*/
void DataControlPlugin::slotModelAboutToReset(){
isExpanded_.clear();
QVector< BaseObject* > stack;
stack.push_back( PluginFunctions::objectRoot() );
BaseObject* item;
do{ // Store the expanded state of all objects
item = stack.front();
stack.pop_front();
for(int i=0; i < item->childCount(); i++)
stack.push_back( item->child(i) );
isExpanded_[ item ] = view_->isExpanded( model_->getModelIndex(item, 0 ) );
} while ( !stack.isEmpty() );
}
//******************************************************************************
/** \brief restore the expanded status of all objects after reset
*
*/
void DataControlPlugin::slotModelResetComplete(){
// first expandAll so that alle ModelIndices in the TreeModel are recreated
view_->expandAll();
// and then restore the expanded state
std::map< BaseObject*, bool>::iterator it;
for ( it=isExpanded_.begin() ; it != isExpanded_.end(); it++ ){
QModelIndex index = model_->getModelIndex( (*it).first, 0 );
if (index.isValid())
view_->setExpanded( index, (*it).second);
}
}
//******************************************************************************
/** \brief Load Groups from ini file
*
* @param _ini an ini file
*/
void DataControlPlugin::loadIniFileOptionsLast( INIFile& _ini ) {
if ( !_ini.section_exists( "Groups" ) )
return;
......@@ -415,6 +396,13 @@ void DataControlPlugin::loadIniFileOptionsLast( INIFile& _ini ) {
emit updatedObject(-1);
}
//******************************************************************************
/** \brief Save groups to ini file
*
* @param _ini an ini file
*/
void DataControlPlugin::saveIniFileOptions( INIFile& _ini ) {
if ( !_ini.section_exists( "Groups" ) )
_ini.add_section("Groups");
......
......@@ -32,12 +32,9 @@
#ifndef COLORPLUGIN_HH
#define COLORPLUGIN_HH
#ifndef DATACONTROLPLUGIN_HH
#define DATACONTROLPLUGIN_HH
#include <QObject>
#include <QMenuBar>
#include "DataControlPlugin.hh"
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
......@@ -49,8 +46,6 @@
#include <OpenFlipper/common/Types.hh>
#include "Toolbox.hh"
//#include "QCheckBoxDelegate.hh"
#include "TreeModel.hh"
......@@ -68,109 +63,93 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
Q_INTERFACES(ScriptInterface)
signals:
/// Force Examiner widget to update their views
// BaseInterface
void updateView();
/// Emit this Signal, if object list has changed (e.g. Source or Target changed)
void updatedObject(int);
void visibilityChanged( );
void visibilityChanged();
void activeObjectChanged();
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
// LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
// ContextMenuInterface
void addContextMenu(QMenu* _menu );
void addContextMenu(QMenu* _menu ,DataType _objectType , ContextMenuType _type );
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
private slots :
/// Updates the table widget
void slotObjectUpdated( int _identifier );
void slotActiveObjectChanged();
void slotKeyEvent( QKeyEvent* _event );
void loadIniFileOptionsLast( INIFile& _ini );
void saveIniFileOptions( INIFile& _ini );
void pluginsInitialized();
void initializePlugin();
public :
~DataControlPlugin() {};
/** Initialize the toolbar (create a widget in the right side toolbox)\n
* Creates Table and buttons */
bool initializeToolbox(QWidget*& _widget);
private slots :
// BaseInterface
void pluginsInitialized();
void slotObjectUpdated( int _identifier );
void slotActiveObjectChanged();
/// Name of the Plugin
QString name(){ return (QString("DataControl")); };
// KeyInterface
void slotKeyEvent( QKeyEvent* _event );
/// Description of the Plugin
QString description() { return (QString("Manages Data Objects")); };
// INIInterface
void loadIniFileOptionsLast( INIFile& _ini );
void saveIniFileOptions( INIFile& _ini );
/// Update the visualization of the active objects
void update_active( );
public :
/// Destructor
~DataControlPlugin() {};
private :
/// Widget for Toolbox
DatacontrolToolboxWidget* tool_;
/// Initialize the ToolBox
bool initializeToolbox(QWidget*& _widget);
/// Layout for Toolbox
QGridLayout* MeshDialogLayout_;
/// Name of the Plugin
QString name(){ return (QString("DataControl")); };
/// Table containing Mesh information and status
QTableWidget* objectList_;
/// Description of the Plugin
QString description() { return (QString("Manages Data Objects")); };
/// Flag set to true if meshlist is updated, preventing signal for list udate to be called
bool locked;
private :
/// Widget for Toolbox
DatacontrolToolboxWidget* tool_;
/// The Treemodel organizing the data
TreeModel* model_;
/// Layout for Toolbox
QGridLayout* MeshDialogLayout_;
///Tree view
QTreeView* view_;
/// Table containing Mesh information and status
QTableWidget* objectList_;
/// Pointer to the header to the view widget
QHeaderView * viewHeader_;
/// Flag set to true if meshlist is updated, preventing signal for list udate to be called
bool locked;
/// Delegate for boolean values
//QCheckBoxDelegate* checkboxDelegate_;
/// The Treemodel organizing the data
TreeModel* model_;
private slots:
///Tree view
QTreeView* view_;
/// This slot is called when the mesh selection changed in the table
void slotCellClicked(int _row, int _col);
/// Pointer to the header to the view widget
QHeaderView * viewHeader_;
/// Vertical header of the list has been clicked
void verticalHeaderClicked( int _row );
//===========================================================================
/** @name Slots which are called if data changed
* @{ */
//===========================================================================
void verticalCountClicked( int id , int old , int newc );
private slots:
/// Gets called when the data in the table has changed
void slotDataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight );
//===========================================================================
/** @name Slots which are called if data changed
* @{ */
//===========================================================================
void slotModelAboutToReset();
/// Gets called when the data in the table has changed
void slotDataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight );
void slotModelResetComplete();
/// called when an object is removed from the view
void slotRowsRemoved ( const QModelIndex & _parent, int _start, int _end );
private:
std::map< BaseObject*, bool > isExpanded_;
/** @} */
/** @} */
//===========================================================================
/** @name Popup Menu related
* @{ */
//===========================================================================
//===========================================================================
/** @name Popup Menu related
* @{ */
//===========================================================================
private slots:
/// Display a custom context window for the TreeView
void slotCustomContextMenuRequested ( const QPoint & _pos );
......@@ -212,12 +191,12 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
/// Defines the section of the Popup
int headerPopupType_;
/** @} */
/** @} */
//===========================================================================
/** @name GL Area Context Menu related slots
* @{ */
//===========================================================================
//===========================================================================
/** @name GL Area Context Menu related slots
* @{ */
//===========================================================================
private slots:
......@@ -237,12 +216,12 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
QAction* targetAction_;
QAction* sourceAction_;
/** @} */
/** @} */
//===========================================================================
/** @name Scripting functions
* @{ */
//===========================================================================
//===========================================================================
/** @name Scripting functions
* @{ */
//===========================================================================
private slots:
void setDescriptions();
......@@ -296,10 +275,10 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
/// Group objects together
void groupObjects(idList _objectIDs, QString _groupName = "");
/** @} */
/** @} */
public slots:
QString version() { return QString("1.02"); };
QString version() { return QString("1.03"); };
};
#endif //COLORPLUGIN_HH
#endif //DATACONTROLPLUGIN_HH
......@@ -43,7 +43,12 @@
#include <QMessageBox>
#include "Menu.hh"
/// Slot for Remove action in ContextMenu
//******************************************************************************
/** \brief Slot for Remove action in ContextMenu
*
*/
void DataControlPlugin::slotPopupRemove ( ) {
QItemSelectionModel* selection = view_->selectionModel();
......@@ -91,7 +96,12 @@ void DataControlPlugin::slotPopupRemove ( ) {
emit updatedObject(-1);
}
/// Slot for Ungroup action in ContextMenu
//******************************************************************************
/** \brief Slot for Ungroup action in ContextMenu
*
*/
void DataControlPlugin::slotUngroup ( ) {
QItemSelectionModel* selection = view_->selectionModel();
......@@ -113,8 +123,13 @@ void DataControlPlugin::slotUngroup ( ) {
emit updatedObject(-1);
}
/// Slot for Copy action in ContextMenu
void DataControlPlugin::slotCopy ( ) {
//******************************************************************************
/** \brief Slot for Copy action in ContextMenu
*
*/
void DataControlPlugin::slotCopy() {
QItemSelectionModel* selection = view_->selectionModel();
if (selection == 0) return;
......@@ -138,8 +153,13 @@ void DataControlPlugin::slotCopy ( ) {
emit updateView();
}
/// Slot for Group action in ContextMenu
void DataControlPlugin::slotGroup ( ) {
//******************************************************************************
/** \brief Slot for Group action in ContextMenu
*
*/
void DataControlPlugin::slotGroup() {
QItemSelectionModel* selection = view_->selectionModel();
// Get all selected rows
......@@ -194,7 +214,13 @@ void DataControlPlugin::slotGroup ( ) {
emit updatedObject(-1);
}
/// ContextMenu requested - creates the contextMenu
//******************************************************************************
/** \brief ContextMenu requested - creates the contextMenu
*
* @param _pos Position where it was requested
*/
void DataControlPlugin::slotCustomContextMenuRequested ( const QPoint & _pos ) {
popupIndex_ = view_->indexAt(_pos);
......@@ -261,6 +287,13 @@ void DataControlPlugin::slotCustomContextMenuRequested ( const QPoint & _pos ) {
}
//******************************************************************************
/** \brief Generate a ContextMenu for the header of the TreeView
*
* @param _pos Position where the Menu has to be created
*/
void DataControlPlugin::slotHeaderCustomContextMenuRequested ( const QPoint & _pos ) {
headerPopupType_ = viewHeader_->logicalIndexAt( _pos );
......@@ -299,6 +332,12 @@ void DataControlPlugin::slotHeaderCustomContextMenuRequested ( const QPoint & _p
menu.exec(viewHeader_->mapToGlobal( _pos ) );
}
//******************************************************************************
/** \brief show a rename dialog for object names
*
*/
void DataControlPlugin::slotRename(){
QItemSelectionModel* selection = view_->selectionModel();
......@@ -316,6 +355,12 @@ void DataControlPlugin::slotRename(){
}
}
//******************************************************************************
/** \brief show the material properties dialog
*
*/
void DataControlPlugin::slotMaterialProperties(){
QItemSelectionModel* selection = view_->selectionModel();
......@@ -341,11 +386,22 @@ void DataControlPlugin::slotMaterialProperties(){
}
}
///Called when the material properties were changed inside the material dialog
//******************************************************************************
/** \brief Called when the material properties were changed inside the material dialog
*
* @param unused
*/
void DataControlPlugin::slotNodeChanged( ACG::SceneGraph::BaseNode* /*_node*/ ){
emit updateView();
}
//******************************************************************************
/** \brief Zoom to an object
*