Salome HOME
c598e6368c52282c3d71ebed1a51708ee7f313d9
[modules/yacs.git] / src / genericgui / SchemaDirTypesItem.cxx
1 // Copyright (C) 2006-2022  CEA/DEN, EDF R&D
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 #include "SchemaDirTypesItem.hxx"
21 #include "SchemaDataTypeItem.hxx"
22 #include "SchemaModel.hxx"
23 #include "QtGuiContext.hxx"
24 #include "ItemMimeData.hxx"
25 #include "GuiEditor.hxx"
26
27 #include <QIcon>
28 #include <cassert>
29
30 //#define _DEVDEBUG_
31 #include "YacsTrace.hxx"
32
33 using namespace std;
34 using namespace YACS::ENGINE;
35 using namespace YACS::HMI;
36
37 SchemaDirTypesItem::SchemaDirTypesItem(SchemaItem *parent, QString label, Subject* subject)
38   : SchemaItem(parent, label, subject)
39 {
40   _itemDeco.replace(YLabel, QIcon("icons:folder_cyan.png"));
41 }
42
43 void SchemaDirTypesItem::addTypeItem(Subject* subject)
44 {
45   DEBTRACE("SchemaDirTypesItem::addTypeItem");
46   SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
47   int nbsons = childCount();
48   SubjectDataType *sdt = dynamic_cast<SubjectDataType*>(subject);
49   YASSERT(sdt);
50   DEBTRACE(nbsons);
51   model->beginInsertRows(modelIndex(), nbsons, nbsons);
52   SchemaItem *item = new SchemaDataTypeItem(this,
53                                             sdt->getAlias().c_str(),
54                                             sdt);
55   model->endInsertRows();
56 }
57
58 void SchemaDirTypesItem::removeTypeItem(Subject* subject)
59 {
60   DEBTRACE("SchemaDirTypesItem::removeTypeItem");
61   SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
62   YASSERT(QtGuiContext::getQtCurrent()->_mapOfSchemaItem.count(subject));
63   SchemaItem *toRemove = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[subject];
64   int position = toRemove->row();
65   DEBTRACE(position);
66   model->beginRemoveRows(modelIndex(), position, position);
67   removeChild(toRemove);
68   model->endRemoveRows();
69 }
70
71 Qt::ItemFlags SchemaDirTypesItem::flags(const QModelIndex &index)
72 {
73   //DEBTRACE("SchemaDirTypesItem::flags");
74   return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
75 }
76
77 bool SchemaDirTypesItem::dropMimeData(const QMimeData* data, Qt::DropAction action)
78 {
79   DEBTRACE("SchemaDirTypesItem::dropMimeData");
80   if (!data) return false;
81   const ItemMimeData* myData = dynamic_cast<const ItemMimeData*>(data);
82   if (!myData) return false;
83   bool ret =false;
84   if (myData->hasFormat("yacs/cataType"))
85     {
86       ret =true;
87       QtGuiContext::getQtCurrent()->getGMain()->_guiEditor->AddTypeFromCatalog(myData);
88     }
89   return ret;
90 }
91
92 QVariant SchemaDirTypesItem::editionWhatsThis(int column) const
93 {
94 return "All the Data types required in this schema must be in this folder.\n" \
95   "You can add data types here by import from catalogs "                \
96   "(builtin catalog, session catalog, or a catalog built from another schema).\n" \
97   "To add a data type, drag a data type item from catalogs panel and drop it here.";
98 }
99