Commit b52b2330 authored by Dirk Wilden's avatar Dirk Wilden

removed EVERY model reset :)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6063 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 81a3e9b0
This diff is collapsed.
......@@ -104,6 +104,7 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
// LoadSaveInterface
void fileOpened(int _id);
void addedEmptyObject(int _id);
void objectDeleted(int _id);
public :
/// Destructor
......@@ -149,14 +150,14 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
private slots:
/// Gets called when the data in the table has changed
void slotDataChanged ( BaseObject* _obj, int _column );
void slotDataChanged (int _id, int _column, const QVariant& _value);
void slotModelAboutToReset();
void slotModelResetComplete();
/// Gets called when an object was moved via drag n drop
void slotMoveBaseObject (int _id, int _newParentId);
private:
std::map< BaseObject*, bool > isExpanded_;
void propagateDownwards(BaseObject* _obj, int _column );
void propagateUpwards(BaseObject* _obj, int _column );
/** @} */
......
......@@ -468,7 +468,7 @@ void DataControlPlugin::showAll() {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, type); o_it != PluginFunctions::objectsEnd(); ++o_it){
o_it->show();
visibilityChanged( o_it->id() );
emit visibilityChanged( o_it->id() );
}
emit updateView();
......
......@@ -50,6 +50,7 @@
*
*/
void DataControlPlugin::slotPopupRemove ( ) {
QItemSelectionModel* selection = view_->selectionModel();
if (selection == 0) return;
......@@ -65,10 +66,9 @@ void DataControlPlugin::slotPopupRemove ( ) {
QString text;
for ( int i = 0 ; i < indexList.size() ; ++i) {
BaseObject* deleteItem = model_->getItem( indexList[i] );
text += deleteItem->name() + "\n";
}
for ( int i = 0 ; i < indexList.size() ; ++i)
text += model_->itemName( indexList[i] ) + "\n";
msgBox.setDetailedText(text);
if ( msgBox.exec() == QMessageBox::No)
......@@ -76,24 +76,14 @@ void DataControlPlugin::slotPopupRemove ( ) {
for ( int i = 0 ; i < indexList.size() ; ++i) {
BaseObject* deleteItem = model_->getItem( indexList[i] );
// Skip the root item
if ( model_->isRoot( deleteItem ) )
continue;
int id = model_->itemId( indexList[i] );
// remove the whole subtree below this item
deleteItem->deleteSubtree();
// remove the item itself from the parent
deleteItem->parent()->removeChild(deleteItem);
// delete it
delete deleteItem;
if ( id != -1 )
emit deleteObject( id );
}
emit updateView();
emit updatedObject(-1);
}
......@@ -108,20 +98,29 @@ void DataControlPlugin::slotUngroup ( ) {
// Get all selected rows
QModelIndexList indexList = selection->selectedRows ( 0 );
//remove complete group if selected item was a group
BaseObject* group = model_->getItem( indexList[0]);
//get the object
int id = model_->itemId( indexList[0] );
BaseObject* group = 0;
for (int i=0; i < group->childCount(); i++){
group->child(i)->setParent(group->parent());
group->parent()->appendChild( group->child(i) );
}
if ( id > 0 && PluginFunctions::getObject(id, group ) ){
//iterate over children
for (int i=group->childCount()-1; i >= 0; i--){
BaseObject* child = group->child(i);
group->parent()->removeChild(group);
// remove it from the old parent
group->removeChild( child );
delete group;
// then change the parent
child->setParent(group->parent());
child->parent()->appendChild( child );
// and inform everyone that the parent changed
emit objectPropertiesChanged( child->id() );
}
//because the parent of all items in the group changed
emit objectPropertiesChanged( -1 );
//delete the group
emit deleteObject( group->id() );
}
}
......@@ -140,11 +139,14 @@ void DataControlPlugin::slotCopy() {
for ( int i = 0 ; i < indexList.size() ; ++i) {
BaseObject* copyItem = model_->getItem( indexList[i] );
int id = model_->itemId( indexList[i] );
if ( id > 0){
int newObject;
int newObject;
emit copyObject( copyItem->id(), newObject );
emit copyObject( id, newObject );
}
}
......@@ -158,6 +160,7 @@ void DataControlPlugin::slotCopy() {
*
*/
void DataControlPlugin::slotGroup() {
QItemSelectionModel* selection = view_->selectionModel();
// Get all selected rows
......@@ -165,22 +168,39 @@ void DataControlPlugin::slotGroup() {
//check if all objects have the same parent
//abort if the parents differ
bool visible = (model_->getItem( indexList[0]))->visible();
bool target = (model_->getItem( indexList[0]))->target();
bool source = (model_->getItem( indexList[0]))->source();
BaseObject* parent = (model_->getItem( indexList[0]))->parent();
int id = model_->itemId( indexList[0] );
BaseObject* obj0 = 0;
if (id == -1 || !PluginFunctions::getObject(id, obj0) ){
std::cerr << "Group Objects: Unable to get object" << std::endl;
return;
}
bool visible = obj0->visible();
bool target = obj0->target();
bool source = obj0->source();
BaseObject* parent = obj0->parent();
for ( int i = 1 ; i < indexList.size() ; ++i) {
BaseObject* item = model_->getItem( indexList[i] );
if (parent != item->parent()){
//get an object
id = model_->itemId( indexList[i] );
BaseObject* item = 0;
PluginFunctions::getObject(id, item );
//compare parent
if ( parent != item->parent() ){
emit log("Cannot group Objects with different parents");
return;
}
//remember if at least on child was target/source
visible |= (model_->getItem( indexList[i]))->visible();
target |= (model_->getItem( indexList[i]))->target();
source |= (model_->getItem( indexList[i]))->source();
visible |= item->visible();
target |= item->target();
source |= item->source();
}
//create new group
......@@ -191,12 +211,24 @@ void DataControlPlugin::slotGroup() {
parent->appendChild( dynamic_cast< BaseObject* >( groupItem ) );
groupItem->setParent( parent );
emit emptyObjectAdded( groupItem->id() );
//append new children to group
for ( int i = 0 ; i < indexList.size() ; ++i) {
BaseObject* item = model_->getItem( indexList[i] );
//get an object
id = model_->itemId( indexList[i] );
BaseObject* item = 0;
PluginFunctions::getObject(id, item );
//and move it into the group
item->parent()->removeChild(item);
item->setParent( dynamic_cast< BaseObject* >( groupItem ) );
groupItem->appendChild(item);
//inform everyone that the parent changed
emit objectPropertiesChanged( id );
}
//update target/source state
......@@ -205,11 +237,8 @@ void DataControlPlugin::slotGroup() {
groupItem->source(source);
emit visibilityChanged( groupItem->id() );
emit objectPropertiesChanged( groupItem->id() );
// emit objectPropertiesChanged( groupItem->id() );
emit objectSelectionChanged ( groupItem->id() );
//because the parent of all items in the group changed
emit objectPropertiesChanged( -1 );
}
......@@ -225,7 +254,7 @@ void DataControlPlugin::slotCustomContextMenuRequested ( const QPoint & _pos ) {
if (!popupIndex_.isValid())
return;
BaseObject* item = model_->getItem(popupIndex_);
TreeItem* item = model_->getItem(popupIndex_);
QItemSelectionModel* selection = view_->selectionModel();
......@@ -402,14 +431,19 @@ void DataControlPlugin::slotRename(){
QModelIndexList indexList = selection->selectedRows ( 0 );
int selectedRows = indexList.size();
if (selectedRows == 1){
BaseObject* item = model_->getItem( indexList[0]);
bool ok;
QString newName = QInputDialog::getText(0, tr("Rename"),
tr("Enter a new name:"), QLineEdit::Normal,
item->name(), &ok);
if (ok && !newName.isEmpty()){
item->setName(newName);
emit objectPropertiesChanged( item->id() );
int id = model_->itemId( indexList[0]);
BaseObject* item = 0;
if ( id != -1 && PluginFunctions::getObject(id,item) ){
bool ok;
QString newName = QInputDialog::getText(0, tr("Rename"),
tr("Enter a new name:"), QLineEdit::Normal,
item->name(), &ok);
if (ok && !newName.isEmpty()){
item->setName(newName);
emit objectPropertiesChanged( item->id() );
}
}
}
}
......@@ -443,8 +477,12 @@ void DataControlPlugin::slotMaterialProperties(){
// Get all selected rows
QModelIndexList indexList = selection->selectedRows ( 0 );
int selectedRows = indexList.size();
if (selectedRows == 1)
item = model_->getItem( indexList[0] );
if (selectedRows == 1){
int id = model_->itemId( indexList[0] );
if ( id > 0 )
PluginFunctions::getObject(id,item);
}
}
if ( item != 0 ){
......@@ -488,7 +526,11 @@ void DataControlPlugin::slotZoomTo(){
QModelIndexList indexList = selection->selectedRows ( 0 );
int selectedRows = indexList.size();
if (selectedRows == 1){
BaseObject* item = model_->getItem( indexList[0]);
BaseObject* item = 0;
int id = model_->itemId( indexList[0]);
if (id == -1 || !PluginFunctions::getObject( id, item) )
return;
if ( item->isGroup() ) {
//zoom to all objects in this group
......
#include "TreeItem.hh"
//--------------------------------------------------------------------------------
TreeItem::TreeItem(int _id, QString _name, DataType _type, TreeItem* _parent) :
id_(_id),
dataType_(_type),
name_(_name),
parentItem_(_parent)
{
}
// ===============================================================================
// Static Members
// ===============================================================================
int TreeItem::id() {
return id_;
}
//--------------------------------------------------------------------------------
bool TreeItem::dataType(DataType _type) {
if ( _type == DATA_ALL ) {
return true;
}
return ( dataType_ & _type);
}
//--------------------------------------------------------------------------------
DataType TreeItem::dataType() {
return dataType_;
}
//--------------------------------------------------------------------------------
int TreeItem::group() {
// Skip root node
if ( parent() == 0 )
return -1;
// Dont count root node as a group
if ( parent()->parent() == 0 )
return -1;
// Only consider groups
if ( !parent()->dataType(DATA_GROUP) )
return -1;
// Get the group id
return ( parent()->id() );
}
//--------------------------------------------------------------------------------
bool TreeItem::isGroup() {
return ( dataType(DATA_GROUP) );
}
// ===============================================================================
// Dynamic Members
// ===============================================================================
bool TreeItem::target() {
return target_;
}
//--------------------------------------------------------------------------------
void TreeItem::target(bool _target) {
target_= _target;
}
//--------------------------------------------------------------------------------
bool TreeItem::source() {
return source_;
}
//--------------------------------------------------------------------------------
void TreeItem::source(bool _source) {
source_ = _source;
}
//--------------------------------------------------------------------------------
bool TreeItem::visible() {
return visible_;
}
//--------------------------------------------------------------------------------
void TreeItem::visible(bool _visible) {
visible_ = _visible;
}
//--------------------------------------------------------------------------------
QString TreeItem::name() {
return name_;
}
//--------------------------------------------------------------------------------
void TreeItem::name(QString _name ) {
name_ = _name;
}
// ===============================================================================
// Tree Structure
// ===============================================================================
TreeItem* TreeItem::next() {
// Visit child item of this node
if ( childItems_.size() > 0 ) {
return childItems_[0];
}
// No Child Item so visit the next child of the parentItem_
if ( parentItem_ ) {
TreeItem* parentPointer = parentItem_;
TreeItem* thisPointer = this;
// while we are not at the root node
while ( parentPointer ) {
// If there is an unvisited child of the parent, return this one
if ( parentPointer->childCount() > ( thisPointer->row() + 1) ) {
return parentPointer->childItems_[ thisPointer->row() + 1 ];
}
// Go to the next level
thisPointer = parentPointer;
parentPointer = parentPointer->parentItem_;
}
return thisPointer;
}
return this;
}
//--------------------------------------------------------------------------------
int TreeItem::level() {
int level = 0;
TreeItem* current = this;
// Go up and count the levels to the root node
while ( current->parent() != 0 ) {
level++;
current = current->parent();
}
return level;
}
//--------------------------------------------------------------------------------
int TreeItem::row() const
{
if (parentItem_)
return parentItem_->childItems_.indexOf(const_cast<TreeItem*>(this));
return 0;
}
//--------------------------------------------------------------------------------
TreeItem* TreeItem::parent()
{
return parentItem_;
}
//--------------------------------------------------------------------------------
void TreeItem::setParent(TreeItem* _parent) {
parentItem_ = _parent;
}
//--------------------------------------------------------------------------------
void TreeItem::appendChild(TreeItem *item)
{
childItems_.append(item);
}
//--------------------------------------------------------------------------------
TreeItem *TreeItem::child(int row)
{
return childItems_.value(row);
}
//--------------------------------------------------------------------------------
int TreeItem::childCount() const
{
return childItems_.count();
}
//--------------------------------------------------------------------------------
TreeItem* TreeItem::childExists(int _objectId) {
// Check if this object has the requested id
if ( id_ == _objectId )
return this;
// search in children
for ( int i = 0 ; i < childItems_.size(); ++i ) {
TreeItem* tmp = childItems_[i]->childExists(_objectId);
if ( tmp != 0)
return tmp;
}
return 0;
}
//--------------------------------------------------------------------------------
TreeItem* TreeItem::childExists(QString _name) {
// Check if this object has the requested id
if ( name() == _name )
return this;
// search in children
for ( int i = 0 ; i < childItems_.size(); ++i ) {
TreeItem* tmp = childItems_[i]->childExists(_name);
if ( tmp != 0)
return tmp;
}
return 0;
}
//--------------------------------------------------------------------------------
void TreeItem::removeChild( TreeItem* _item ) {
bool found = false;
QList<TreeItem*>::iterator i;
for (i = childItems_.begin(); i != childItems_.end(); ++i) {
if ( *i == _item ) {
found = true;
break;
}
}
if ( !found ) {
std::cerr << "TreeItem: Illegal remove request" << std::endl;
return;
}
childItems_.erase(i);
}
//--------------------------------------------------------------------------------
QList< TreeItem* > TreeItem::getLeafs() {
QList< TreeItem* > items;
for ( int i = 0 ; i < childItems_.size(); ++i ) {
items = items + childItems_[i]->getLeafs();
}
// If we are a leave...
if ( childCount() == 0 )
items.push_back(this);
return items;
}
//--------------------------------------------------------------------------------
void TreeItem::deleteSubtree() {
// call function for all children of this node
for ( int i = 0 ; i < childItems_.size(); ++i) {
// remove the subtree recursively
childItems_[i]->deleteSubtree();
// delete child
delete childItems_[i];
}
// clear the array
childItems_.clear();
}
//=============================================================================
#ifndef TREEITEM_HH
#define TREEITEM_HH
#include <QString>
#include <QList>
#include <vector>
#include <OpenFlipper/common/Types.hh>
class TreeItem {
public :
TreeItem(int _id, QString _name, DataType _type, TreeItem* _parent);
// static members
public:
/// id
int id();
/// dataType
DataType dataType();
bool dataType(DataType _type);
/// group
int group();
bool isGroup();
private:
int id_;
DataType dataType_;
// dynamic members
public:
/// target
bool target();
void target(bool _target);
/// source
bool source();
void source(bool _source);
/// visible
bool visible();
void visible(bool _visible);
/// name
QString name( );
void name( QString _name );
private:
bool target_;
bool source_;
bool visible_;