1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef _CFG_EXTERNAL_TOOL_MODEL_H_ 23 #define _CFG_EXTERNAL_TOOL_MODEL_H_ 24 25 #include <QAbstractTableModel> 26 27 #include <U2Designer/PropertyWidget.h> 28 29 #include <U2Lang/ExternalToolCfg.h> 30 31 namespace U2 { 32 33 class DataTypeRegistry; 34 class DocumentFormatRegistry; 35 class PropertyDelegate; 36 37 class CfgExternalToolItem { 38 public: 39 CfgExternalToolItem(); 40 ~CfgExternalToolItem(); 41 42 const QString &getDataType() const; 43 void setDataType(const QString &typeId); 44 45 const QString &getId() const; 46 void setId(const QString &id); 47 48 const QString &getName() const; 49 void setName(const QString &name); 50 51 const QString &getFormat() const; 52 void setFormat(const QString &format); 53 54 const QString &getDescription() const; 55 void setDescription(const QString &descr); 56 57 PropertyDelegate *delegateForNames; 58 PropertyDelegate *delegateForIds; 59 PropertyDelegate *delegateForTypes; 60 PropertyDelegate *delegateForFormats; 61 62 DataConfig itemData; 63 64 private: 65 DocumentFormatRegistry *dfr; 66 DataTypeRegistry *dtr; 67 }; 68 69 class CfgExternalToolModel : public QAbstractTableModel { 70 Q_OBJECT 71 public: 72 enum ModelType { 73 Input, 74 Output 75 }; 76 77 enum Columns { 78 COLUMN_NAME = 0, 79 COLUMN_ID = 1, 80 COLUMN_DATA_TYPE = 2, 81 COLUMN_FORMAT = 3, 82 COLUMN_DESCRIPTION = 4, 83 COLUMNS_COUNT = COLUMN_DESCRIPTION + 1 // elements count 84 }; 85 86 CfgExternalToolModel(ModelType modelType, QObject *obj = nullptr); 87 88 int rowCount(const QModelIndex &parent = QModelIndex()) const; 89 int columnCount(const QModelIndex &parent = QModelIndex()) const; 90 Qt::ItemFlags flags(const QModelIndex &index) const; 91 CfgExternalToolItem *getItem(const QModelIndex &index) const; 92 QList<CfgExternalToolItem *> getItems() const; 93 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 94 void createFormatDelegate(const QString &newType, CfgExternalToolItem *item); 95 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); 96 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 97 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); 98 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); 99 100 private: 101 void init(); 102 void initFormats(); 103 void initTypes(); 104 105 bool isInput; 106 QList<CfgExternalToolItem *> items; 107 QVariantMap types; 108 QVariantMap seqFormatsW; 109 QVariantMap msaFormatsW; 110 QVariantMap annFormatsW; 111 QVariantMap annSeqFormatsW; 112 QVariantMap seqFormatsR; 113 QVariantMap msaFormatsR; 114 QVariantMap annFormatsR; 115 QVariantMap annSeqFormatsR; 116 QVariantMap textFormat; 117 }; 118 119 class AttributeItem { 120 public: 121 AttributeItem(); 122 ~AttributeItem(); 123 124 const QString &getId() const; 125 void setId(const QString &id); 126 127 const QString &getName() const; 128 void setName(const QString &name); 129 130 const QString &getDataType() const; 131 void setDataType(const QString &type); 132 133 const QVariant &getDefaultValue() const; 134 void setDefaultValue(const QVariant &defaultValue); 135 136 const QString &getDescription() const; 137 void setDescription(const QString &description); 138 139 PropertyDelegate *delegateForNames; 140 PropertyDelegate *delegateForIds; 141 PropertyDelegate *delegateForDefaultValues; 142 143 private: 144 QString id; 145 QString name; 146 QString type; 147 QVariant defaultValue; 148 QString description; 149 }; 150 151 class CfgExternalToolModelAttributes : public QAbstractTableModel { 152 Q_OBJECT 153 public: 154 enum Columns { 155 COLUMN_NAME = 0, 156 COLUMN_ID = 1, 157 COLUMN_DATA_TYPE = 2, 158 COLUMN_DEFAULT_VALUE = 3, 159 COLUMN_DESCRIPTION = 4, 160 COLUMNS_COUNT = COLUMN_DESCRIPTION + 1 // elements count 161 }; 162 163 CfgExternalToolModelAttributes(SchemaConfig *schemaConfig, QObject *parent = nullptr); 164 ~CfgExternalToolModelAttributes(); 165 166 void changeDefaultValueDelegate(const QString &newType, AttributeItem *item); 167 int rowCount(const QModelIndex &parent = QModelIndex()) const; 168 int columnCount(const QModelIndex &parent = QModelIndex()) const; 169 Qt::ItemFlags flags(const QModelIndex &index) const; 170 AttributeItem *getItem(const QModelIndex &index) const; 171 QList<AttributeItem *> getItems() const; 172 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 173 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); 174 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 175 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); 176 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); 177 178 private: 179 QList<AttributeItem *> items; 180 PropertyDelegate *typesDelegate; 181 QList<ComboItem> types; 182 SchemaConfig *schemaConfig; 183 }; 184 185 } // namespace U2 186 187 #endif // _CFG_EXTERNAL_TOOL_MODEL_H_ 188