Back to index

salome-gui  6.5.0
Defines | Functions
guitester.cxx File Reference
#include <QApplication>
#include <QMainWindow>
#include <QDockWidget>
#include <QTreeView>
#include <Basics_Utils.hxx>
#include "TreeModel.hxx"
#include "MyDataModel.hxx"
#include "testhelper.hxx"
#include "TreeView.hxx"
#include "mainwindow.hxx"

Go to the source code of this file.

Defines

#define LOOPSIZE   15

Functions

void showWidget (QWidget *widget)
 This functions displays a main window that embeds the specified widget.
void _TEST_treemodel_addData_01 (TreeModel *dataTreeModel)
 This function fills the specified tree with data that show different levels of path in the tree.
void _TEST_treemodel_addData_02 (TreeModel *dataTreeModel)
 This function fills the specified tree with a huge amount of data.
void _TEST_treemodel_addData_03 (TreeModel *dataTreeModel)
void _TEST_treemodel_loadDataFromFile (TreeModel *dataTreeModel, const QString &filename)
 This test function shows how it's possible to load data from a file to populate the tree model.
void TEST_treemodel ()
 Main test function for the tree model demo.
void TEST_treemodel_interactif ()
int main (int argc, char *argv[])

Define Documentation

#define LOOPSIZE   15

Definition at line 106 of file guitester.cxx.


Function Documentation

void _TEST_treemodel_addData_01 ( TreeModel *  dataTreeModel)

This function fills the specified tree with data that show different levels of path in the tree.

Definition at line 71 of file guitester.cxx.

                                                           {
  // We can first add categories (for example to set categories
  // properties)
  QStringList path;
  DataObject * folder;

  path << "folder_1";
  folder = TESTHELPER_dummyObject("folder_1.1");
  dataTreeModel->addData(folder, path);
  folder = TESTHELPER_dummyObject("folder_1.2");
  dataTreeModel->addData(folder, path);

  path.clear();
  path << "folder_2";
  folder = TESTHELPER_dummyObject("folder_2.1");
  dataTreeModel->addData(folder, path);
  
  // Then we can add data
  DataObject * data;
  path.clear();
  path << "folder_1" << "folder_1.1";
  data = TESTHELPER_dummyObject("data_1.1.1");
  dataTreeModel->addData(data, path);
  data = TESTHELPER_dummyObject("data_1.1.2");
  dataTreeModel->addData(data, path);
  // You can notice that there is no conceptual difference between a
  // folder and an item, as in the QTreeModel.
  
  // No limit to the depth
  path.clear();
  path << "xcad" << "data1" << "x" << "y";
  data = TESTHELPER_dummyObject("z");
  dataTreeModel->addData(data,path);
}

Here is the call graph for this function:

void _TEST_treemodel_addData_02 ( TreeModel *  dataTreeModel)

This function fills the specified tree with a huge amount of data.

Definition at line 110 of file guitester.cxx.

                                                           {
  QStringList path;
  DataObject * data;
  
  START_TIMING(treemodel);
  for (int i=0; i<LOOPSIZE; i++) {
    END_TIMING(treemodel,1);
    for (int j=0; j<LOOPSIZE; j++) {
      for (int k=0; k<LOOPSIZE; k++) {
        // The data list corresponds to the path of the item in the tree
        path << QString("folder_%0").arg(i)
             << QString("subfolder_%0_%1").arg(i).arg(j);
        data = TESTHELPER_dummyObject(QString("item_%0_%1_%2").arg(i).arg(j).arg(k));
        dataTreeModel->addData(data,path);
        path.clear();
      } 
    }
  }
  END_TIMING(treemodel,1);
}

Here is the call graph for this function:

void _TEST_treemodel_addData_03 ( TreeModel *  dataTreeModel)

Definition at line 131 of file guitester.cxx.

                                                           {
  MyDataObject * dataObject = new MyDataObject();
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
  dataTreeModel->addData(dataObject);

  dataObject = new MyDataObject();
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
  dataTreeModel->addData(dataObject);

  dataObject = new MyDataObject();
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF2");
  dataTreeModel->addData(dataObject);

  dataObject = new MyDataObject();
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RRA");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
  dataTreeModel->addData(dataObject);

  dataObject = new MyDataObject();
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "GĂ©nie civil");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RRA");
  dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
  dataTreeModel->addData(dataObject);
}
void _TEST_treemodel_loadDataFromFile ( TreeModel *  dataTreeModel,
const QString &  filename 
)

This test function shows how it's possible to load data from a file to populate the tree model.

Definition at line 167 of file guitester.cxx.

                                                                                          {
  TESTHELPER_loadDataFromFile(dataTreeModel, filename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 215 of file guitester.cxx.

{
  QApplication app(argc, argv);
  TEST_treemodel();
  //TST_treemodel_interactif();
  return app.exec();
}

Here is the call graph for this function:

void showWidget ( QWidget *  widget)

This functions displays a main window that embeds the specified widget.

A dockwidget is used to create a context similar to as the SALOME target context.

Definition at line 37 of file guitester.cxx.

                                  {

  QMainWindow * window = new QMainWindow();

  // Prepare a gui framework for testing the widget. We use a
  // dockwidget, just to be in a context similar to as the SALOME
  // target context.
  QDockWidget * dwDataPanel = new QDockWidget(window);
  dwDataPanel->setVisible(true);
  dwDataPanel->setWindowTitle("XCAD data model");
  window->addDockWidget(Qt::LeftDockWidgetArea, dwDataPanel);

  // Then plug the widget in the dock widget framework:
  widget->setParent(dwDataPanel);
  widget->setMinimumHeight(300);
  dwDataPanel->setWidget(widget);

  window->show();
}

Here is the caller graph for this function:

Main test function for the tree model demo.

Definition at line 176 of file guitester.cxx.

                      {

  START_TIMING(treemodel);

  // We first prepare a data view embedding a tree model
  TreeView * dataView = new TreeView();
  QStringList headers;
  headers << QObject::tr("Name") << QObject::tr("Value");
  TreeModel * dataTreeModel = new TreeModel(headers);
  dataView->setModel(dataTreeModel);
  END_TIMING(treemodel,1);

  // Then we can fill the tree model with data. Can proceed with
  // different ways (comment/uncomment which you want to test):
  _TEST_treemodel_loadDataFromFile(dataTreeModel, TESTHELPER_testfilename(DATAFILENAME));
  //_TEST_treemodel_addData_01(dataTreeModel);
  //_TEST_treemodel_addData_02(dataTreeModel);
  //_TEST_treemodel_addData_03(dataTreeModel);
  // Finally, show the widget in a main window
  END_TIMING(treemodel,1);

  showWidget(dataView);
  END_TIMING(treemodel,1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 207 of file guitester.cxx.

                                 {
  MainWindow * window = new MainWindow();
  window->show();
}