1 // Copyright (C) 2007-2013 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.
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 <QApplication>
21 #include <QMainWindow>
22 #include <QDockWidget>
25 #include <Basics_Utils.hxx>
28 // =================================================================
29 // Generic helper functions
30 // =================================================================
33 * This functions displays a main window that embeds the specified
34 * widget. A dockwidget is used to create a context similar to as the
35 * SALOME target context.
37 void showWidget(QWidget * widget) {
39 QMainWindow * window = new QMainWindow();
41 // Prepare a gui framework for testing the widget. We use a
42 // dockwidget, just to be in a context similar to as the SALOME
44 QDockWidget * dwDataPanel = new QDockWidget(window);
45 dwDataPanel->setVisible(true);
46 dwDataPanel->setWindowTitle("XCAD data model");
47 window->addDockWidget(Qt::LeftDockWidgetArea, dwDataPanel);
49 // Then plug the widget in the dock widget framework:
50 widget->setParent(dwDataPanel);
51 widget->setMinimumHeight(300);
52 dwDataPanel->setWidget(widget);
58 // =================================================================
59 // Tests functions for TreeModel
60 // =================================================================
62 #include "TreeModel.hxx"
63 #include "MyDataModel.hxx"
64 #include "testhelper.hxx"
68 * This function fills the specified tree with data that show
69 * different levels of path in the tree.
71 void _TEST_treemodel_addData_01(TreeModel * dataTreeModel) {
72 // We can first add categories (for example to set categories
78 folder = TESTHELPER_dummyObject("folder_1.1");
79 dataTreeModel->addData(folder, path);
80 folder = TESTHELPER_dummyObject("folder_1.2");
81 dataTreeModel->addData(folder, path);
85 folder = TESTHELPER_dummyObject("folder_2.1");
86 dataTreeModel->addData(folder, path);
88 // Then we can add data
91 path << "folder_1" << "folder_1.1";
92 data = TESTHELPER_dummyObject("data_1.1.1");
93 dataTreeModel->addData(data, path);
94 data = TESTHELPER_dummyObject("data_1.1.2");
95 dataTreeModel->addData(data, path);
96 // You can notice that there is no conceptual difference between a
97 // folder and an item, as in the QTreeModel.
99 // No limit to the depth
101 path << "xcad" << "data1" << "x" << "y";
102 data = TESTHELPER_dummyObject("z");
103 dataTreeModel->addData(data,path);
108 * This function fills the specified tree with a huge amount of data
110 void _TEST_treemodel_addData_02(TreeModel * dataTreeModel) {
114 START_TIMING(treemodel);
115 for (int i=0; i<LOOPSIZE; i++) {
116 END_TIMING(treemodel,1);
117 for (int j=0; j<LOOPSIZE; j++) {
118 for (int k=0; k<LOOPSIZE; k++) {
119 // The data list corresponds to the path of the item in the tree
120 path << QString("folder_%0").arg(i)
121 << QString("subfolder_%0_%1").arg(i).arg(j);
122 data = TESTHELPER_dummyObject(QString("item_%0_%1_%2").arg(i).arg(j).arg(k));
123 dataTreeModel->addData(data,path);
128 END_TIMING(treemodel,1);
131 void _TEST_treemodel_addData_03(TreeModel * dataTreeModel) {
132 MyDataObject * dataObject = new MyDataObject();
133 dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE, "Tuyauterie");
134 dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
135 dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
136 dataTreeModel->addData(dataObject);
138 dataObject = new MyDataObject();
139 dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE, "Tuyauterie");
140 dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
141 dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
142 dataTreeModel->addData(dataObject);
144 dataObject = new MyDataObject();
145 dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE, "Tuyauterie");
146 dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RCP");
147 dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF2");
148 dataTreeModel->addData(dataObject);
150 dataObject = new MyDataObject();
151 dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE, "Tuyauterie");
152 dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RRA");
153 dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
154 dataTreeModel->addData(dataObject);
156 dataObject = new MyDataObject();
157 dataObject->setProperty(MyDataObject::PROPERTY_KEY_TYPE, "Génie civil");
158 dataObject->setProperty(MyDataObject::PROPERTY_KEY_CIRCUIT, "RRA");
159 dataObject->setProperty(MyDataObject::PROPERTY_KEY_REPFONC, "RF1");
160 dataTreeModel->addData(dataObject);
164 * This test function shows how it's possible to load data from a file
165 * to populate the tree model.
167 void _TEST_treemodel_loadDataFromFile(TreeModel * dataTreeModel, const QString &filename) {
168 TESTHELPER_loadDataFromFile(dataTreeModel, filename);
172 * Main test function for the tree model demo.
174 #include "TreeModel.hxx"
175 #include "TreeView.hxx"
176 void TEST_treemodel() {
178 START_TIMING(treemodel);
180 // We first prepare a data view embedding a tree model
181 TreeView * dataView = new TreeView();
183 headers << QObject::tr("Name") << QObject::tr("Value");
184 TreeModel * dataTreeModel = new TreeModel(headers);
185 dataView->setModel(dataTreeModel);
186 END_TIMING(treemodel,1);
188 // Then we can fill the tree model with data. Can proceed with
189 // different ways (comment/uncomment which you want to test):
190 _TEST_treemodel_loadDataFromFile(dataTreeModel, TESTHELPER_testfilename(DATAFILENAME));
191 //_TEST_treemodel_addData_01(dataTreeModel);
192 //_TEST_treemodel_addData_02(dataTreeModel);
193 //_TEST_treemodel_addData_03(dataTreeModel);
194 // Finally, show the widget in a main window
195 END_TIMING(treemodel,1);
197 showWidget(dataView);
198 END_TIMING(treemodel,1);
202 // =================================================================
203 // Tests functions for TreeModel with interactive changes
204 // =================================================================
206 #include "mainwindow.hxx"
207 void TEST_treemodel_interactif() {
208 MainWindow * window = new MainWindow();
213 // =================================================================
215 int main(int argc, char * argv[ ])
217 QApplication app(argc, argv);
219 //TST_treemodel_interactif();