Back to index

salome-gui  6.5.0
guitester.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 <QApplication>
00021 #include <QMainWindow>
00022 #include <QDockWidget>
00023 #include <QTreeView>
00024 
00025 #include <Basics_Utils.hxx>
00026 
00027 //
00028 // =================================================================
00029 // Generic helper functions
00030 // =================================================================
00031 //
00037 void showWidget(QWidget * widget) {
00038 
00039   QMainWindow * window = new QMainWindow();
00040 
00041   // Prepare a gui framework for testing the widget. We use a
00042   // dockwidget, just to be in a context similar to as the SALOME
00043   // target context.
00044   QDockWidget * dwDataPanel = new QDockWidget(window);
00045   dwDataPanel->setVisible(true);
00046   dwDataPanel->setWindowTitle("XCAD data model");
00047   window->addDockWidget(Qt::LeftDockWidgetArea, dwDataPanel);
00048 
00049   // Then plug the widget in the dock widget framework:
00050   widget->setParent(dwDataPanel);
00051   widget->setMinimumHeight(300);
00052   dwDataPanel->setWidget(widget);
00053 
00054   window->show();
00055 }
00056 
00057 //
00058 // =================================================================
00059 // Tests functions for TreeModel
00060 // =================================================================
00061 //
00062 #include "TreeModel.hxx"
00063 #include "MyDataModel.hxx"
00064 #include "testhelper.hxx"
00065 
00066 
00071 void _TEST_treemodel_addData_01(TreeModel * dataTreeModel) {
00072   // We can first add categories (for example to set categories
00073   // properties)
00074   QStringList path;
00075   DataObject * folder;
00076 
00077   path << "folder_1";
00078   folder = TESTHELPER_dummyObject("folder_1.1");
00079   dataTreeModel->addData(folder, path);
00080   folder = TESTHELPER_dummyObject("folder_1.2");
00081   dataTreeModel->addData(folder, path);
00082 
00083   path.clear();
00084   path << "folder_2";
00085   folder = TESTHELPER_dummyObject("folder_2.1");
00086   dataTreeModel->addData(folder, path);
00087   
00088   // Then we can add data
00089   DataObject * data;
00090   path.clear();
00091   path << "folder_1" << "folder_1.1";
00092   data = TESTHELPER_dummyObject("data_1.1.1");
00093   dataTreeModel->addData(data, path);
00094   data = TESTHELPER_dummyObject("data_1.1.2");
00095   dataTreeModel->addData(data, path);
00096   // You can notice that there is no conceptual difference between a
00097   // folder and an item, as in the QTreeModel.
00098   
00099   // No limit to the depth
00100   path.clear();
00101   path << "xcad" << "data1" << "x" << "y";
00102   data = TESTHELPER_dummyObject("z");
00103   dataTreeModel->addData(data,path);
00104 }
00105 
00106 #define LOOPSIZE 15
00107 
00110 void _TEST_treemodel_addData_02(TreeModel * dataTreeModel) {
00111   QStringList path;
00112   DataObject * data;
00113   
00114   START_TIMING(treemodel);
00115   for (int i=0; i<LOOPSIZE; i++) {
00116     END_TIMING(treemodel,1);
00117     for (int j=0; j<LOOPSIZE; j++) {
00118       for (int k=0; k<LOOPSIZE; k++) {
00119         // The data list corresponds to the path of the item in the tree
00120         path << QString("folder_%0").arg(i)
00121              << QString("subfolder_%0_%1").arg(i).arg(j);
00122         data = TESTHELPER_dummyObject(QString("item_%0_%1_%2").arg(i).arg(j).arg(k));
00123         dataTreeModel->addData(data,path);
00124         path.clear();
00125       } 
00126     }
00127   }
00128   END_TIMING(treemodel,1);
00129 }
00130 
00131 void _TEST_treemodel_addData_03(TreeModel * dataTreeModel) {
00132   MyDataObject * dataObject = new MyDataObject();
00133   dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
00134   dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
00135   dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
00136   dataTreeModel->addData(dataObject);
00137 
00138   dataObject = new MyDataObject();
00139   dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
00140   dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
00141   dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
00142   dataTreeModel->addData(dataObject);
00143 
00144   dataObject = new MyDataObject();
00145   dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
00146   dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
00147   dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF2");
00148   dataTreeModel->addData(dataObject);
00149 
00150   dataObject = new MyDataObject();
00151   dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "Tuyauterie");
00152   dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RRA");
00153   dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
00154   dataTreeModel->addData(dataObject);
00155 
00156   dataObject = new MyDataObject();
00157   dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE,    "GĂ©nie civil");
00158   dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RRA");
00159   dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
00160   dataTreeModel->addData(dataObject);
00161 }
00162 
00167 void _TEST_treemodel_loadDataFromFile(TreeModel * dataTreeModel, const QString &filename) {
00168   TESTHELPER_loadDataFromFile(dataTreeModel, filename);
00169 }
00170 
00174 #include "TreeModel.hxx"
00175 #include "TreeView.hxx"
00176 void TEST_treemodel() {
00177 
00178   START_TIMING(treemodel);
00179 
00180   // We first prepare a data view embedding a tree model
00181   TreeView * dataView = new TreeView();
00182   QStringList headers;
00183   headers << QObject::tr("Name") << QObject::tr("Value");
00184   TreeModel * dataTreeModel = new TreeModel(headers);
00185   dataView->setModel(dataTreeModel);
00186   END_TIMING(treemodel,1);
00187 
00188   // Then we can fill the tree model with data. Can proceed with
00189   // different ways (comment/uncomment which you want to test):
00190   _TEST_treemodel_loadDataFromFile(dataTreeModel, TESTHELPER_testfilename(DATAFILENAME));
00191   //_TEST_treemodel_addData_01(dataTreeModel);
00192   //_TEST_treemodel_addData_02(dataTreeModel);
00193   //_TEST_treemodel_addData_03(dataTreeModel);
00194   // Finally, show the widget in a main window
00195   END_TIMING(treemodel,1);
00196 
00197   showWidget(dataView);
00198   END_TIMING(treemodel,1);
00199 }
00200 
00201 //
00202 // =================================================================
00203 // Tests functions for TreeModel with interactive changes
00204 // =================================================================
00205 //
00206 #include "mainwindow.hxx"
00207 void TEST_treemodel_interactif() {
00208   MainWindow * window = new MainWindow();
00209   window->show();
00210 }
00211 
00212 //
00213 // =================================================================
00214 //
00215 int main(int argc, char * argv[ ])
00216 {
00217   QApplication app(argc, argv);
00218   TEST_treemodel();
00219   //TST_treemodel_interactif();
00220   return app.exec();
00221 }