DataControlPlugin.cc 16.7 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16 17 18 19
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================





#include <QtGui>

#include "DataControlPlugin.hh"

#include <QLayout>
41
#include <QGridLayout>
Jan Möbius's avatar
 
Jan Möbius committed
42
#include <QItemSelectionModel>
43

Jan Möbius's avatar
 
Jan Möbius committed
44 45 46 47
#include <iostream>
#include <ACG/GL/GLState.hh>
#include <QStringList>
#include <ACG/Scenegraph/BaseNode.hh>
Dirk Wilden's avatar
Dirk Wilden committed
48
#include <ACG/QtWidgets/QtMaterialDialog.hh>
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52 53 54 55
#include <QModelIndexList>

#include <queue>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>


Dirk Wilden's avatar
Dirk Wilden committed
56 57 58
void DataControlPlugin::initializePlugin(){
}

Jan Möbius's avatar
 
Jan Möbius committed
59
void DataControlPlugin::pluginsInitialized() {
60

Jan Möbius's avatar
 
Jan Möbius committed
61 62 63
  //set the slot descriptions
  setDescriptions();

Jan Möbius's avatar
 
Jan Möbius committed
64
  QMenu* contextMenu = new QMenu("Object selection");
65

Jan Möbius's avatar
 
Jan Möbius committed
66 67 68 69 70
  //Target Objects
  QAction* hideAction = new QAction(tr("&Hide"), this);
  hideAction->setStatusTip(tr("Hide object"));
  connect(hideAction, SIGNAL(triggered()), this, SLOT(slotContextMenuHide()) );
  contextMenu->addAction(hideAction);
71

Jan Möbius's avatar
 
Jan Möbius committed
72 73 74 75 76 77
  //Target Objects
  targetAction_ = new QAction(tr("&target"), this);
  targetAction_->setCheckable(true);
  targetAction_->setStatusTip(tr("Set object as target"));
  connect(targetAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuTarget()) );
  contextMenu->addAction(targetAction_);
78

Jan Möbius's avatar
 
Jan Möbius committed
79 80 81 82 83
  //Source Objects
  sourceAction_ = new QAction(tr("&source"), this);
  sourceAction_->setCheckable(true);
  sourceAction_->setStatusTip(tr("Set object as source"));
  connect(sourceAction_, SIGNAL(triggered()), this, SLOT(slotContextMenuSource()) );
84 85 86
  contextMenu->addAction(sourceAction_);

  emit addContextMenu(contextMenu , DATA_ALL , CONTEXTTOPLEVELMENU);
Jan Möbius's avatar
 
Jan Möbius committed
87 88 89 90 91
}

bool DataControlPlugin::initializeToolbox(QWidget*& _widget)
{
   locked = false;
92 93 94
   tool_ = new DatacontrolToolboxWidget();
   connect( tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
            this  , SLOT(slotKeyEvent ( QKeyEvent* ) ));
Jan Möbius's avatar
 
Jan Möbius committed
95 96
   _widget = tool_;
   QSize size(300, 300);
97 98 99
   tool_->resize(size);
   MeshDialogLayout_ = new QGridLayout( tool_);

Jan Möbius's avatar
 
Jan Möbius committed
100
   model_ = new TreeModel( );
101

Jan Möbius's avatar
 
Jan Möbius committed
102 103
   view_ = new QTreeView(0);
   view_->setModel(model_);
104

Jan Möbius's avatar
 
Jan Möbius committed
105 106 107
   view_->QTreeView::resizeColumnToContents(1);
   view_->QTreeView::resizeColumnToContents(2);
   view_->QTreeView::resizeColumnToContents(3);
108

Jan Möbius's avatar
 
Jan Möbius committed
109
   view_->setContextMenuPolicy(Qt::CustomContextMenu);
110

Jan Möbius's avatar
 
Jan Möbius committed
111 112
   view_->setSelectionBehavior(QAbstractItemView::SelectRows);
   view_->setSelectionMode(QAbstractItemView::ExtendedSelection);
113

Jan Möbius's avatar
 
Jan Möbius committed
114 115
   connect( model_,SIGNAL(dataChanged( const QModelIndex&, const QModelIndex& ) ),
             this,SLOT(slotDataChanged( const QModelIndex&, const QModelIndex& )));
116

Jan Möbius's avatar
 
Jan Möbius committed
117 118
   connect( model_ , SIGNAL(rowsRemoved( const QModelIndex &, int , int ) ),
            this , SLOT(slotRowsRemoved ( const QModelIndex &, int , int ) ) );
119

Jan Möbius's avatar
 
Jan Möbius committed
120 121
   connect( view_,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,SLOT(slotCustomContextMenuRequested ( const QPoint & ) ));
122 123 124 125

   MeshDialogLayout_->addWidget( view_ , 0,0  );

   viewHeader_ = view_->header();
Jan Möbius's avatar
 
Jan Möbius committed
126
   viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
127

Jan Möbius's avatar
 
Jan Möbius committed
128 129 130
   // connect the slot for the context menu
   connect( viewHeader_, SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
            this,        SLOT(slotHeaderCustomContextMenuRequested ( const QPoint & ) ));
131

Jan Möbius's avatar
 
Jan Möbius committed
132 133 134 135 136 137 138
   return true;
}

void DataControlPlugin::slotObjectUpdated( int _identifier ) {
  model_->updatedObject( _identifier );
}

Dirk Wilden's avatar
Dirk Wilden committed
139
void DataControlPlugin::slotCellClicked(int /*_row*/ , int /*_col*/) {
140

Jan Möbius's avatar
 
Jan Möbius committed
141 142 143 144
//    if ( _col == 0 ) {
//          QTableWidgetItem* target = objectList_->item(_row,_col);
//          if ( target->checkState() == Qt::Checked ) {
//             target->setCheckState(Qt::Unchecked);
145 146
//             (*data_)[_row]->target(false);
//          } else {
Jan Möbius's avatar
 
Jan Möbius committed
147
//             target->setCheckState(Qt::Checked);
148
//             (*data_)[_row]->target(true);
Jan Möbius's avatar
 
Jan Möbius committed
149 150 151 152 153
//          }
//         emit activeObjectChanged();
//    }
}

Dirk Wilden's avatar
Dirk Wilden committed
154
void DataControlPlugin::verticalHeaderClicked( int /*_row*/ ) {
Jan Möbius's avatar
 
Jan Möbius committed
155 156 157 158
//     (*data_)[_row]->target ( !(*data_)[_row]->target() );
//    QTableWidgetItem* target = objectList_->item(_row,3);
//    if ( target->checkState() == Qt::Checked ) {
//       target->setCheckState(Qt::Unchecked);
159 160
//       (*data_)[_row]->target(false);
//    } else {
Jan Möbius's avatar
 
Jan Möbius committed
161
//       target->setCheckState(Qt::Checked);
162
//       (*data_)[_row]->target(true);
Jan Möbius's avatar
 
Jan Möbius committed
163 164 165 166 167 168
//    }
//    emit activeObjectChanged();
// //    QTableWidgetSelectionRange range(5,0,5,3);
// //    objectList_->setRangeSelected(range,true);
}

Dirk Wilden's avatar
Dirk Wilden committed
169
void DataControlPlugin::verticalCountClicked( int  /*id*/ , int /*old*/ , int /*newc*/ ) {
Jan Möbius's avatar
 
Jan Möbius committed
170 171 172 173
//    emit log(LOGWARN,"VHeader : Count " + QString::number(id) + " " + QString::number(old) + " " + QString::number(newc));
}


174
void DataControlPlugin::slotActiveObjectChanged()
Jan Möbius's avatar
 
Jan Möbius committed
175 176 177 178 179 180 181 182 183
{
  ///@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
184
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
 
Jan Möbius committed
185 186 187 188 189 190 191 192 193 194 195 196
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
      if ( o_it->target() ) {
               o_it->materialNode()->disable_blending();
               OpenMesh::Vec4f base_color = o_it->materialNode()->base_color();
               base_color[3] = 1.0;
               o_it->materialNode()->set_base_color(base_color);
               OpenMesh::Vec4f ambient_color = o_it->materialNode()->ambient_color();
               ambient_color[3] = 1.0;
               o_it->materialNode()->set_ambient_color(ambient_color);
               OpenMesh::Vec4f diffuse_color = o_it->materialNode()->diffuse_color();
               diffuse_color[3] = 1.0;
               o_it->materialNode()->set_diffuse_color(diffuse_color);
197
      }  else {
Jan Möbius's avatar
 
Jan Möbius committed
198 199 200 201 202 203 204 205 206 207
            o_it->materialNode()->enable_blending();
            OpenMesh::Vec4f base_color = o_it->materialNode()->base_color();
            base_color[3] = 0.4;
            o_it->materialNode()->set_base_color(base_color);
            OpenMesh::Vec4f ambient_color = o_it->materialNode()->ambient_color();
            ambient_color[3] = 0.4;
            o_it->materialNode()->set_ambient_color(ambient_color);
            OpenMesh::Vec4f diffuse_color = o_it->materialNode()->diffuse_color();
            diffuse_color[3] = 0.4;
            o_it->materialNode()->set_diffuse_color(diffuse_color);
208
      }
Jan Möbius's avatar
 
Jan Möbius committed
209
  }
210

Jan Möbius's avatar
 
Jan Möbius committed
211 212 213 214 215 216 217 218
  emit update_view();
}

void DataControlPlugin::slotKeyEvent( QKeyEvent* _event )
{

//    QList<QTableWidgetItem *> selected ;
//    QList<QTableWidgetSelectionRange> ranges;
219
//    switch (_event->key())
Jan Möbius's avatar
 
Jan Möbius committed
220
//    {
221
//      case Qt::Key_M :
Jan Möbius's avatar
 
Jan Möbius committed
222 223 224 225
//           for ( uint i = 0 ; i < data_->size() ; ++i ) {
//                QTableWidgetSelectionRange range(i,0,i,3);
//                objectList_->setRangeSelected(range,true);
//          }
226 227 228
//          return;
//
//       case Qt::Key_N :
Jan Möbius's avatar
 
Jan Möbius committed
229 230 231
//          std::cerr << "Checking : " << std::endl;
//          for ( uint i = 0 ; i < data_->size() ; ++i ) {
//             QTableWidgetItem * item = objectList_->verticalHeaderItem ( i );
232
//             if ( objectList_->isItemSelected(item)  )
Jan Möbius's avatar
 
Jan Möbius committed
233 234 235 236 237
//                std::cerr << i << item->text().toStdString() << " : yes" << std::endl;
//             else {
//                std::cerr << i << item->text().toStdString() << " : no" << std::endl;
//             }
//          }
238
//
Jan Möbius's avatar
 
Jan Möbius committed
239 240
//          selected = objectList_->selectedItems();
//          std::cerr << "Selected " << selected.size() << std::endl;
241
//
Jan Möbius's avatar
 
Jan Möbius committed
242 243
//          ranges = objectList_->selectedRanges();
//          std::cerr << "Ranges " << ranges.size() << std::endl;
244
//
Jan Möbius's avatar
 
Jan Möbius committed
245
//          for ( int i = 0 ; i < ranges.size(); ++i ) {
246 247
//            std::cerr << "Range " << i << " : " << ranges[i].topRow() << " .. " << ranges[i].bottomRow() << std::endl;
//            std::cerr << "Range " << i << " : " << ranges[i].leftColumn() << " .. " << ranges[i].rightColumn() << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
248
//          }
249
//
Jan Möbius's avatar
 
Jan Möbius committed
250
//          return;
251
//       case Qt::Key_C :
Jan Möbius's avatar
 
Jan Möbius committed
252
//           if ( _event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) ) {
253
//                for ( uint i = 0 ; i < data_->size() ; ++i ) {
Jan Möbius's avatar
 
Jan Möbius committed
254 255 256 257
//                   (*data_)[i]->source(false);
//                }
//                emit updated_objects(-1);
//               return;
258 259
//           }
//
Jan Möbius's avatar
 
Jan Möbius committed
260
//           if ( _event->modifiers() == (Qt::AltModifier | Qt::ShiftModifier) ) {
261
//              for ( uint i = 0 ; i < data_->size() ; ++i ) {
Jan Möbius's avatar
 
Jan Möbius committed
262 263 264 265
//                 (*data_)[i]->target(false);
//               }
//               emit updated_objects(-1);
//              return;
266 267
//           }
//
Jan Möbius's avatar
 
Jan Möbius committed
268
//           return;
269 270
//
//        case Qt::Key_A :
Jan Möbius's avatar
 
Jan Möbius committed
271
//           if ( _event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) ) {
272
//                for ( uint i = 0 ; i < data_->size() ; ++i ) {
Jan Möbius's avatar
 
Jan Möbius committed
273 274 275 276
//                   (*data_)[i]->source(true);
//                }
//                emit updated_objects(-1);
//               return;
277 278
//           }
//
Jan Möbius's avatar
 
Jan Möbius committed
279
//           if ( _event->modifiers() == (Qt::AltModifier | Qt::ShiftModifier) ) {
280
//              for ( uint i = 0 ; i < data_->size() ; ++i ) {
Jan Möbius's avatar
 
Jan Möbius committed
281 282 283 284
//                 (*data_)[i]->target(true);
//               }
//               emit updated_objects(-1);
//              return;
285 286
//           }
//
Jan Möbius's avatar
 
Jan Möbius committed
287 288 289 290
//           return;
//       default:
//       break;
//   }
291

Jan Möbius's avatar
 
Jan Möbius committed
292 293
  if ( _event->modifiers() == Qt::ControlModifier ) {
    switch (_event->key()) {
294
      case Qt::Key_A :
Jan Möbius's avatar
 
Jan Möbius committed
295 296 297 298 299 300
          setAllTarget();
        return;
      default:
        return;
    }
  }
301 302 303 304 305 306 307 308 309 310

    switch (_event->key()) {
      case Qt::Key_Delete :
          std::cerr << "Todo : Datacontrol Plugin: got delete key ..." << std::endl;
          slotPopupRemove();
        return;
      default:
        return;
    }

Jan Möbius's avatar
 
Jan Möbius committed
311 312 313
}

void DataControlPlugin::setAllTarget() {
314 315 316
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                    o_it != PluginFunctions::objects_end(); ++o_it)
  o_it->target(true);
Jan Möbius's avatar
 
Jan Möbius committed
317
  emit activeObjectChanged();
318
  emit updated_objects(-1);
Jan Möbius's avatar
 
Jan Möbius committed
319 320 321
}

void DataControlPlugin::setAllSource() {
322 323 324 325
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                    o_it != PluginFunctions::objects_end(); ++o_it)
  o_it->source(true);
  emit updated_objects(-1);
Jan Möbius's avatar
 
Jan Möbius committed
326 327 328
}

void DataControlPlugin::clearAllTarget() {
329 330 331
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                    o_it != PluginFunctions::objects_end(); ++o_it)
  o_it->target(false);
Jan Möbius's avatar
 
Jan Möbius committed
332
  emit activeObjectChanged();
333
  emit updated_objects(-1);
Jan Möbius's avatar
 
Jan Möbius committed
334 335 336
}

void DataControlPlugin::clearAllSource() {
337 338 339 340
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                    o_it != PluginFunctions::objects_end(); ++o_it)
  o_it->source(false);
  emit updated_objects(-1);
Jan Möbius's avatar
 
Jan Möbius committed
341 342 343
}

void DataControlPlugin::hideAll() {
344 345 346
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                    o_it != PluginFunctions::objects_end(); ++o_it)
    o_it->hide();
Jan Möbius's avatar
 
Jan Möbius committed
347 348 349 350
  emit update_view();
}

void DataControlPlugin::showAll() {
351 352 353
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                    o_it != PluginFunctions::objects_end(); ++o_it)
    o_it->show();
Jan Möbius's avatar
 
Jan Möbius committed
354 355 356
  emit update_view();
}

357
void DataControlPlugin::slotDataChanged ( const QModelIndex & topLeft,
Dirk Wilden's avatar
Dirk Wilden committed
358
                                          const QModelIndex & /*bottomRight*/ )
Jan Möbius's avatar
 
Jan Möbius committed
359
{
360

Jan Möbius's avatar
 
Jan Möbius committed
361
  switch (topLeft.column()) {
362
    // Name
Jan Möbius's avatar
 
Jan Möbius committed
363
    case 0:
Dirk Wilden's avatar
Dirk Wilden committed
364
      view_->expandToDepth(0);
Jan Möbius's avatar
 
Jan Möbius committed
365
      break;
366

Jan Möbius's avatar
 
Jan Möbius committed
367 368
    // show/hide
    case 1:
369
        emit update_view();
Jan Möbius's avatar
 
Jan Möbius committed
370
      break;
371

Jan Möbius's avatar
 
Jan Möbius committed
372 373
    // source
    case 2:
374 375
      break;

Jan Möbius's avatar
 
Jan Möbius committed
376 377 378 379
    // target
    case 3:
      emit activeObjectChanged();
      break;
380

Jan Möbius's avatar
 
Jan Möbius committed
381 382 383 384 385
    default:
      break;
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
386
void DataControlPlugin::slotRowsRemoved ( const QModelIndex & /*_parent*/, int /*_start*/, int /*_end*/ ) {
Jan Möbius's avatar
 
Jan Möbius committed
387 388 389 390 391
  std::cerr << "Row removed! " << std::endl;
  emit update_view();
}

void DataControlPlugin::loadIniFileOptions( INIFile& _ini ) {
392
  if ( !_ini.section_exists( "Groups" ) )
Jan Möbius's avatar
 
Jan Möbius committed
393
    return;
394

Jan Möbius's avatar
 
Jan Möbius committed
395 396
  // Names of all groups
  QStringList groupNames;
397

Jan Möbius's avatar
 
Jan Möbius committed
398 399
  // names of the primary groups
  QStringList rootGroup;
400

Jan Möbius's avatar
 
Jan Möbius committed
401 402
  // Get the list of group names to the file
  _ini.get_entry(groupNames,"Groups","groups");
403

Jan Möbius's avatar
 
Jan Möbius committed
404 405
  // Get the primary group names to the file
  _ini.get_entry(rootGroup,"Groups","rootGroup");
406

Jan Möbius's avatar
 
Jan Möbius committed
407 408 409 410
  // Go over one level of the groups
  while ( rootGroup.size() > 0 ) {
    QString current = rootGroup[0];
    rootGroup.removeFirst();
411

Jan Möbius's avatar
 
Jan Möbius committed
412 413
    QStringList groupChildren;
    QStringList elementChildren;
414

Jan Möbius's avatar
 
Jan Möbius committed
415 416
    _ini.get_entry(elementChildren ,current,"children");
    _ini.get_entry(groupChildren ,current,"subgroups");
417

Jan Möbius's avatar
 
Jan Möbius committed
418 419 420 421 422 423
    // if we get a parent item, scan the tree for it or use the root node otherwise
    BaseObject* parentItem;
    QString parentName;
    if ( _ini.get_entry(parentName,current,"parent") ) {
      parentItem = PluginFunctions::objectRoot()->childExists(parentName);
      if ( parentItem == 0 )
424 425 426 427 428 429
        parentItem = PluginFunctions::objectRoot();
    } else
      parentItem = PluginFunctions::objectRoot();

    rootGroup << groupChildren;

Jan Möbius's avatar
 
Jan Möbius committed
430 431
    // check if this group already exists
    BaseObject* group =  PluginFunctions::objectRoot()->childExists( current );
432

Jan Möbius's avatar
 
Jan Möbius committed
433 434
    // group does not exist
    if ( !group ) {
435

Jan Möbius's avatar
 
Jan Möbius committed
436
      group = dynamic_cast< BaseObject* >( new GroupObject( current, dynamic_cast< GroupObject* >(parentItem ) ) );
437

Jan Möbius's avatar
 
Jan Möbius committed
438 439 440
      parentItem->appendChild(group);
      group->setParent(parentItem);
    }
441

Jan Möbius's avatar
 
Jan Möbius committed
442 443 444 445 446 447 448 449 450 451
    // process children
    for ( int i = 0 ; i < elementChildren.size() ; ++i ) {
      BaseObject* childItem =  PluginFunctions::objectRoot()->childExists( elementChildren[i] );
      if ( childItem ) {
        childItem->parent()->removeChild(childItem);
        childItem->setParent(group);
        group->appendChild(childItem);
      }
    }
  }
452 453

  emit updated_objects(-1);
Jan Möbius's avatar
 
Jan Möbius committed
454 455 456
}

void DataControlPlugin::saveIniFileOptions( INIFile& _ini ) {
457 458 459
  if ( !_ini.section_exists( "Groups" ) )
    _ini.add_section("Groups");

Jan Möbius's avatar
 
Jan Möbius committed
460 461
  std::queue< BaseObject* > children;
  children.push( PluginFunctions::objectRoot() );
462

Jan Möbius's avatar
 
Jan Möbius committed
463
  std::vector< BaseObject* > groups;
464

Jan Möbius's avatar
 
Jan Möbius committed
465 466 467 468
  // Get all groups from the tree
  while ( children.size() > 0 ) {
    BaseObject* item = children.front();
    children.pop();
469 470 471 472 473

    for ( int i = 0 ; i < item->childCount(); ++i )
      if ( item->child(i)->dataType(DATA_GROUP))
        children.push( item->child(i) );

Jan Möbius's avatar
 
Jan Möbius committed
474 475 476
    if ( item->dataType(DATA_GROUP) && (item != PluginFunctions::objectRoot() ) )
      groups.push_back(item);
  }
477

Jan Möbius's avatar
 
Jan Möbius committed
478 479
  // Names of all groups
  QStringList groupNames;
480

Jan Möbius's avatar
 
Jan Möbius committed
481 482
  // names of the primary groups
  QStringList rootGroup;
483

Jan Möbius's avatar
 
Jan Möbius committed
484
  for ( uint i = 0 ; i < groups.size() ; ++i ) {
485 486 487 488 489
    groupNames.push_back( groups[i]->name() );

    if ( !_ini.section_exists( groups[i]->name() ) )
      _ini.add_section(groups[i]->name());

Jan Möbius's avatar
 
Jan Möbius committed
490
    _ini.add_entry(groups[i]->name(),"groupname",groups[i]->name());
491 492

    // write the name of the parent
Jan Möbius's avatar
 
Jan Möbius committed
493 494
    if ( ( groups[i]->parent() != 0 ) && ( groups[i]->parent() != PluginFunctions::objectRoot() ) )
      _ini.add_entry(groups[i]->name(),"parent",groups[i]->parent()->name());
495

Jan Möbius's avatar
 
Jan Möbius committed
496 497
    if ( groups[i]->parent() == PluginFunctions::objectRoot() )
      rootGroup.push_back( groups[i]->name() );
498

Jan Möbius's avatar
 
Jan Möbius committed
499 500 501 502 503 504 505 506 507
    // Write a list of this groups children
    QStringList groupchildren;
    QStringList elementchildren;
    for ( int j = 0 ; j < groups[i]->childCount(); ++j ) {
      if  ( groups[i]->child(j)->dataType(DATA_GROUP) )
        groupchildren.push_back( groups[i]->child(j)->name() );
      else
        elementchildren.push_back( groups[i]->child(j)->name() );
    }
508

Jan Möbius's avatar
 
Jan Möbius committed
509 510 511
    _ini.add_entry(groups[i]->name(),"subgroups",groupchildren);
    _ini.add_entry(groups[i]->name(),"children",elementchildren);
  }
512

Jan Möbius's avatar
 
Jan Möbius committed
513 514
  // Write the list of group names to the file
  _ini.add_entry("Groups","groups",groupNames);
515

Jan Möbius's avatar
 
Jan Möbius committed
516 517 518 519 520 521 522
  // Write the primary group names to the file
  _ini.add_entry("Groups","rootGroup",rootGroup);
}


Q_EXPORT_PLUGIN2( datacontrolplugin , DataControlPlugin );