1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "testhelper.hxx"
25 #include "QtHelper.hxx"
26 #include "MyDataModel.hxx"
28 // Standard C include (for getenv)
31 QString TESTHELPER_testfilename(const char * basefilename) {
33 char * GUI_ROOT_DIR = getenv("GUI_ROOT_DIR");
35 if ( GUI_ROOT_DIR != NULL ) {
36 root = new QString(GUI_ROOT_DIR);
39 root = new QString("/home/gboulant/development/projets/salome/devel/XSALOME/install");
41 QString relativePathName = "/share/salome/resources/gui/testdata/";
42 aFile.append(*root + relativePathName + basefilename);
44 QLOG("The test file is : "<<aFile);
49 * This creates a dummy data object for the needs of the test
50 * functions. The label is the basename of the spécified pathname.
52 DataObject * TESTHELPER_dummyObject(QString label) {
53 MyDataObject * dataObject = new MyDataObject();
54 dataObject->setLabel(QCHARSTAR(label));
61 * This test function shows how it's possible to load data from a file
62 * to populate the tree model.
64 void TESTHELPER_loadDataFromFile(TreeModel * dataTreeModel, const QString &filename) {
65 QFile file ( filename );
66 file.open ( QIODevice::ReadOnly );
68 MyDataObject * dataObject;
70 QByteArray byteArray = file.readLine();
72 if ( byteArray.isEmpty() )
75 QString data = (QString ( byteArray.mid(0, byteArray.size()-1))).trimmed();
76 QStringList dataList = data.split ( SEP );
77 // The data list is used here to set properties (and then the path
78 // of location in the tree model).
80 dataObject = new MyDataObject();
81 // The label is autogenerated, but we may specify here a custom
82 // one. We just fill the properties with data values read in the
84 dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE, QCHARSTAR(dataList[0]));
85 dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, QCHARSTAR(dataList[1]));
86 dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, QCHARSTAR(dataList[2]));
87 if ( ! dataTreeModel->addData(dataObject) ) {
88 QLOG("ERR: data not added");