Salome HOME
16f8bea39dadbf55c553bccf8269362d39c88d34
[modules/gui.git] / src / TreeData / DataProcessor.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author: Guillaume Boulant (EDF/R&D)
21
22
23 #include "DataProcessor.hxx"
24 #include <Basics_Utils.hxx>
25 #include "QtHelper.hxx"
26
27 DataProcessor::DataProcessor(DataModel * dataModel) {
28   _dataModel = dataModel;
29 }
30
31 /*!
32  * This function retrieves in the data model all the DataObject
33  * associated to the item nameIds contained in the specified list. The
34  * input list is what the TreeView sends via the notification signal.
35  */
36 DataObjectVector * DataProcessor::extract(QStringList itemNameIdList) {
37   if ( _dataModel == NULL ) {
38     STDLOG("No data model associated to this processor");
39     return NULL;
40   }
41
42   DataObjectVector * dataObjectList = new DataObjectVector();
43
44   // We can request the dataModel to obtain the dataObject associated
45   // to each of the item (iteNameId is a TreeView id, Qt stuff only).
46   QStringList::const_iterator it;
47   for (it = itemNameIdList.constBegin(); it != itemNameIdList.constEnd(); ++it) {
48     QString itemNameId = *it;
49     DataObject * dataObject = _dataModel->getDataObject(QS2S(itemNameId));
50     
51     if ( dataObject != NULL ) {
52       dataObjectList->push_back(dataObject);
53     } else {
54       LOG("No data object associated to the item "<<itemNameId);
55     } 
56   }
57   return dataObjectList;
58 }
59
60
61 void DataProcessor::process(QStringList itemNameIdList) {
62   if ( _dataModel == NULL ) {
63     STDLOG("No data model");
64     return;
65   }
66
67   this->preprocess(itemNameIdList);
68
69   // We can request the dataModel to obtain the dataObject associated
70   // to each of the item (iteNameId is a TreeView id, Qt stuff only).
71   QStringList::const_iterator it;
72   for (it = itemNameIdList.constBegin(); it != itemNameIdList.constEnd(); ++it) {
73     QString itemNameId = *it;
74     DataObject * dataObject = _dataModel->getDataObject(QS2S(itemNameId));
75     
76     if ( dataObject != NULL ) {
77       this->processDataObject(dataObject);
78     } else {
79       STDLOG("No data object associated to the item "<<QS2S(itemNameId));
80     } 
81   }
82
83   this->postprocess(itemNameIdList);
84 }
85
86