Back to index

salome-gui  6.5.0
Defines | Functions
testhelper.hxx File Reference
#include <QString>
#include "TreeModel.hxx"
#include "DataObject.hxx"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DATAFILENAME   "data.txt"

Functions

QString TESTHELPER_testfilename (const char *basefilename)
DataObject * TESTHELPER_dummyObject (QString label)
 This creates a dummy data object for the needs of the test functions.
void TESTHELPER_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.

Define Documentation

#define DATAFILENAME   "data.txt"

Definition at line 27 of file testhelper.hxx.


Function Documentation

DataObject* TESTHELPER_dummyObject ( QString  label)

This creates a dummy data object for the needs of the test functions.

The label is the basename of the spécified pathname.

Definition at line 52 of file testhelper.cxx.

                                                   {
  MyDataObject * dataObject = new MyDataObject();
  dataObject->setLabel(QCHARSTAR(label));
  return dataObject;
}

Here is the caller graph for this function:

void TESTHELPER_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 64 of file testhelper.cxx.

                                                                                     {
  QFile file ( filename );
  file.open ( QIODevice::ReadOnly );
  
  MyDataObject * dataObject;
  while ( 1 ) {
    QByteArray byteArray = file.readLine();

    if ( byteArray.isEmpty() )
      break;
    
    QString data = (QString ( byteArray.mid(0, byteArray.size()-1))).trimmed();
    QStringList dataList = data.split ( SEP );
    // The data list is used here to set properties (and then the path
    // of location in the tree model).

    dataObject = new MyDataObject();
    // The label is autogenerated, but we may specify here a custom
    // one. We just fill the properties with data values read in the
    // file.
    dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    QCHARSTAR(dataList[0]));
    dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, QCHARSTAR(dataList[1]));
    dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, QCHARSTAR(dataList[2]));
    if ( ! dataTreeModel->addData(dataObject) ) {
      QLOG("ERR: data not added");
    }
  }

  file.close();
}

Here is the caller graph for this function:

QString TESTHELPER_testfilename ( const char *  basefilename)

Definition at line 31 of file testhelper.cxx.

                                                           {
  QString aFile;
  char * GUI_ROOT_DIR = getenv("GUI_ROOT_DIR");
  QString * root;
  if ( GUI_ROOT_DIR != NULL ) {
    root = new QString(GUI_ROOT_DIR);
  }
  else {
    root = new QString("/home/gboulant/development/projets/salome/devel/XSALOME/install");
  }
  QString relativePathName = "/share/salome/resources/gui/testdata/";
  aFile.append(*root + relativePathName + basefilename);

  QLOG("The test file is : "<<aFile);
  return aFile;
}

Here is the caller graph for this function: