Back to index

salome-gui  6.5.0
testhelper.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "testhelper.hxx"
00021 
00022 #include <QFile>
00023 #include <QString>
00024 
00025 #include "QtHelper.hxx"
00026 #include "MyDataModel.hxx"
00027 
00028 // Standard C include (for getenv)
00029 #include <stdlib.h>
00030 
00031 QString TESTHELPER_testfilename(const char * basefilename) {
00032   QString aFile;
00033   char * GUI_ROOT_DIR = getenv("GUI_ROOT_DIR");
00034   QString * root;
00035   if ( GUI_ROOT_DIR != NULL ) {
00036     root = new QString(GUI_ROOT_DIR);
00037   }
00038   else {
00039     root = new QString("/home/gboulant/development/projets/salome/devel/XSALOME/install");
00040   }
00041   QString relativePathName = "/share/salome/resources/gui/testdata/";
00042   aFile.append(*root + relativePathName + basefilename);
00043 
00044   QLOG("The test file is : "<<aFile);
00045   return aFile;
00046 }
00047 
00052 DataObject * TESTHELPER_dummyObject(QString label) {
00053   MyDataObject * dataObject = new MyDataObject();
00054   dataObject->setLabel(QCHARSTAR(label));
00055   return dataObject;
00056 }
00057 
00058 
00059 #define SEP ";"
00060 
00064 void TESTHELPER_loadDataFromFile(TreeModel * dataTreeModel, const QString &filename) {
00065   QFile file ( filename );
00066   file.open ( QIODevice::ReadOnly );
00067   
00068   MyDataObject * dataObject;
00069   while ( 1 ) {
00070     QByteArray byteArray = file.readLine();
00071 
00072     if ( byteArray.isEmpty() )
00073       break;
00074     
00075     QString data = (QString ( byteArray.mid(0, byteArray.size()-1))).trimmed();
00076     QStringList dataList = data.split ( SEP );
00077     // The data list is used here to set properties (and then the path
00078     // of location in the tree model).
00079 
00080     dataObject = new MyDataObject();
00081     // The label is autogenerated, but we may specify here a custom
00082     // one. We just fill the properties with data values read in the
00083     // file.
00084     dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    QCHARSTAR(dataList[0]));
00085     dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, QCHARSTAR(dataList[1]));
00086     dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, QCHARSTAR(dataList[2]));
00087     if ( ! dataTreeModel->addData(dataObject) ) {
00088       QLOG("ERR: data not added");
00089     }
00090   }
00091 
00092   file.close();
00093 }