1 // Copyright (C) 2006-2019 CEA/DEN, EDF R&D
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 "SchemaDirTypesItem.hxx"
21 #include "SchemaDataTypeItem.hxx"
22 #include "SchemaModel.hxx"
23 #include "QtGuiContext.hxx"
24 #include "ItemMimeData.hxx"
25 #include "GuiEditor.hxx"
31 #include "YacsTrace.hxx"
34 using namespace YACS::ENGINE;
35 using namespace YACS::HMI;
37 SchemaDirTypesItem::SchemaDirTypesItem(SchemaItem *parent, QString label, Subject* subject)
38 : SchemaItem(parent, label, subject)
40 _itemDeco.replace(YLabel, QIcon("icons:folder_cyan.png"));
43 void SchemaDirTypesItem::addTypeItem(Subject* subject)
45 DEBTRACE("SchemaDirTypesItem::addTypeItem");
46 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
47 int nbsons = childCount();
48 SubjectDataType *sdt = dynamic_cast<SubjectDataType*>(subject);
51 model->beginInsertRows(modelIndex(), nbsons, nbsons);
52 SchemaItem *item = new SchemaDataTypeItem(this,
53 sdt->getAlias().c_str(),
55 model->endInsertRows();
58 void SchemaDirTypesItem::removeTypeItem(Subject* subject)
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();
66 model->beginRemoveRows(modelIndex(), position, position);
67 removeChild(toRemove);
68 model->endRemoveRows();
71 Qt::ItemFlags SchemaDirTypesItem::flags(const QModelIndex &index)
73 //DEBTRACE("SchemaDirTypesItem::flags");
74 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
77 bool SchemaDirTypesItem::dropMimeData(const QMimeData* data, Qt::DropAction action)
79 DEBTRACE("SchemaDirTypesItem::dropMimeData");
80 if (!data) return false;
81 const ItemMimeData* myData = dynamic_cast<const ItemMimeData*>(data);
82 if (!myData) return false;
84 if (myData->hasFormat("yacs/cataType"))
87 QtGuiContext::getQtCurrent()->getGMain()->_guiEditor->AddTypeFromCatalog(myData);
92 QVariant SchemaDirTypesItem::editionWhatsThis(int column) const
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.";