COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CQBiologicalDescriptionDM Class Reference

#include <CQBiologicalDescriptionDM.h>

Inheritance diagram for CQBiologicalDescriptionDM:
Inheritance graph
[legend]
Collaboration diagram for CQBiologicalDescriptionDM:
Collaboration graph
[legend]

Public Member Functions

virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQBiologicalDescriptionDM (CMIRIAMInfo *MIRIAMInfo, QObject *parent=0)
 
QVariant data (const QModelIndex &index, int role) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
bool removeRows (QModelIndexList rows, const QModelIndex &index=QModelIndex())
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
- Public Member Functions inherited from CQBaseDataModel
virtual bool clear ()
 
 CQBaseDataModel (QObject *parent=0)
 
QString createNewName (const QString name, const int nameCol)
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 
bool insertRow ()
 
virtual bool isDefaultRow (const QModelIndex &i) const
 
bool removeRow (int position)
 

Protected Member Functions

bool insertRows (int position, int rows, const QModelIndex &index=QModelIndex())
 
bool removeRows (int position, int rows, const QModelIndex &index=QModelIndex())
 

Protected Attributes

CMIRIAMInfompMIRIAMInfo
 

Additional Inherited Members

- Signals inherited from CQBaseDataModel
void notifyGUI (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Detailed Description

Definition at line 31 of file CQBiologicalDescriptionDM.h.

Constructor & Destructor Documentation

CQBiologicalDescriptionDM::CQBiologicalDescriptionDM ( CMIRIAMInfo MIRIAMInfo,
QObject *  parent = 0 
)

Definition at line 26 of file CQBiologicalDescriptionDM.cpp.

References mpMIRIAMInfo.

27  : CQBaseDataModel(parent)
28 
29 {
30  mpMIRIAMInfo = MIRIAMInfo;
31 }
CQBaseDataModel(QObject *parent=0)

Member Function Documentation

int CQBiologicalDescriptionDM::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 37 of file CQBiologicalDescriptionDM.cpp.

References TOTAL_COLS_BIOLOGICAL_DESCRIPTIONS.

38 {
40 }
#define TOTAL_COLS_BIOLOGICAL_DESCRIPTIONS
QVariant CQBiologicalDescriptionDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 42 of file CQBiologicalDescriptionDM.cpp.

References COL_ID_BD, COL_RELATIONSHIP, COL_RESOURCE_BD, COL_ROW_NUMBER, FROM_UTF8, CMIRIAMInfo::getBiologicalDescriptions(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, and rowCount().

Referenced by removeRows().

43 {
44  if (!index.isValid())
45  return QVariant();
46 
47  if (index.row() >= rowCount())
48  return QVariant();
49 
50  if (role == Qt::DisplayRole || role == Qt::EditRole)
51  {
52  if (isDefaultRow(index))
53  {
54  if (index.column() == COL_RELATIONSHIP || index.column() == COL_RESOURCE_BD)
55  return QVariant(QString("-- select --"));
56  else if (index.column() == COL_ROW_NUMBER)
57  return QVariant(QString(""));
58  else
59  return QVariant(QString(""));
60  }
61  else
62  {
63  switch (index.column())
64  {
65  case COL_ROW_NUMBER:
66  return QVariant(index.row() + 1);
67  case COL_RELATIONSHIP:
68  return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getBiologicalDescriptions()[index.row()]->getPredicate())));
69  case COL_RESOURCE_BD:
70  return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getBiologicalDescriptions()[index.row()]->getResource())));
71  case COL_ID_BD:
72  return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getBiologicalDescriptions()[index.row()]->getId())));
73  }
74  }
75  }
76 
77  return QVariant();
78 }
#define COL_ID_BD
#define COL_RESOURCE_BD
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const CCopasiVector< CBiologicalDescription > & getBiologicalDescriptions() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
#define COL_RELATIONSHIP
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_ROW_NUMBER
QVariant CQBiologicalDescriptionDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 80 of file CQBiologicalDescriptionDM.cpp.

References COL_ID_BD, COL_RELATIONSHIP, COL_RESOURCE_BD, and COL_ROW_NUMBER.

82 {
83  if (role != Qt::DisplayRole)
84  return QVariant();
85 
86  if (orientation == Qt::Horizontal)
87  {
88  switch (section)
89  {
90  case COL_ROW_NUMBER:
91  return QVariant(QString("#"));
92  case COL_RELATIONSHIP:
93  return QVariant(QString("Relationship"));
94  case COL_RESOURCE_BD:
95  return QVariant(QString(" Resource "));
96  case COL_ID_BD:
97  return QVariant(QString("ID"));
98  default:
99  return QVariant();
100  }
101  }
102  else
103  return QString("%1").arg(section + 1);
104 }
#define COL_ID_BD
#define COL_RESOURCE_BD
#define COL_RELATIONSHIP
#define COL_ROW_NUMBER
bool CQBiologicalDescriptionDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 140 of file CQBiologicalDescriptionDM.cpp.

References ListViews::ADD, CMIRIAMInfo::createBiologicalDescription(), ListViews::MIRIAM, mpMIRIAMInfo, and CQBaseDataModel::notifyGUI().

141 {
142  beginInsertRows(QModelIndex(), position, position + rows - 1);
143 
144  for (int row = 0; row < rows; ++row)
145  {
147  }
148 
149  endInsertRows();
151  return true;
152 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CBiologicalDescription * createBiologicalDescription()
bool CQBiologicalDescriptionDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 172 of file CQBiologicalDescriptionDM.cpp.

References C_INVALID_INDEX, COL_ID_BD, COL_RESOURCE_BD, data(), CMIRIAMInfo::getBiologicalDescriptions(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, CQMessageBox::question(), and CQBaseDataModel::removeRow().

Referenced by CQMiriamWidget::deleteSelectedBiologicalDescriptions().

173 {
174  if (rows.isEmpty())
175  return false;
176 
177 //Build the list of pointers to items to be deleted
178 //before actually deleting any item.
179  QList <CBiologicalDescription *> pBiologicalDescriptions;
180  QModelIndexList::const_iterator i;
181 
182  for (i = rows.begin(); i != rows.end(); ++i)
183  {
184  if (!isDefaultRow(*i) && mpMIRIAMInfo->getBiologicalDescriptions()[(*i).row()])
185  pBiologicalDescriptions.append(mpMIRIAMInfo->getBiologicalDescriptions()[(*i).row()]);
186  }
187 
188  bool retVal = false, askEveryItem = true;
189  QMessageBox::StandardButton choice = QMessageBox::NoToAll;
190  QList <CBiologicalDescription *>::const_iterator j;
191 
192  for (j = pBiologicalDescriptions.begin(); j != pBiologicalDescriptions.end(); ++j)
193  {
194  CBiologicalDescription * pBiologicalDescription = *j;
195 
196  size_t delRow =
197  mpMIRIAMInfo->getBiologicalDescriptions().CCopasiVector< CBiologicalDescription >::getIndex(pBiologicalDescription);
198 
199  if (delRow != C_INVALID_INDEX)
200  {
201  if (askEveryItem)
202  {
203 
204  QString resource = data(this->index((int) delRow, COL_RESOURCE_BD), Qt::DisplayRole).toString();
205  QString Id = data(this->index((int) delRow, COL_ID_BD), Qt::DisplayRole).toString();
206 
207  QString msg = "Do you want to delete Description '";
208 
209  if (!resource.isNull())
210  {
211  msg.append(resource);
212  }
213 
214  if (!Id.isNull())
215  {
216  msg.append(":");
217  msg.append(Id);
218  }
219 
220  msg.append("'?");
221 
222  choice = CQMessageBox::question(NULL, tr("Confirm Delete"), msg,
223  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll,
224  QMessageBox::No);
225  }
226 
227  if (choice == QMessageBox::NoToAll)
228  {return retVal;}
229  else if (choice == QMessageBox::Yes)
230  {retVal = removeRow((int) delRow);}
231  else if (choice == QMessageBox::YesToAll)
232  {
233  askEveryItem = false;
234  retVal = removeRow((int) delRow);
235  }
236  }
237  }
238 
239  return true;
240 }
#define COL_ID_BD
#define COL_RESOURCE_BD
QVariant data(const QModelIndex &index, int role) const
const CCopasiVector< CBiologicalDescription > & getBiologicalDescriptions() const
#define C_INVALID_INDEX
Definition: copasi.h:222
bool removeRow(int position)
virtual bool isDefaultRow(const QModelIndex &i) const
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
bool CQBiologicalDescriptionDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 154 of file CQBiologicalDescriptionDM.cpp.

References ListViews::DELETE, ListViews::MIRIAM, mpMIRIAMInfo, CQBaseDataModel::notifyGUI(), and CMIRIAMInfo::removeBiologicalDescription().

155 {
156  if (rows <= 0)
157  return true;
158 
159  beginRemoveRows(QModelIndex(), position, position + rows - 1);
160 
161  for (int row = 0; row < rows; ++row)
162  {
164  }
165 
166  endRemoveRows();
167 
169  return true;
170 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
bool removeBiologicalDescription(int position)
int CQBiologicalDescriptionDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 33 of file CQBiologicalDescriptionDM.cpp.

References CMIRIAMInfo::getBiologicalDescriptions(), mpMIRIAMInfo, and CCopasiVector< T >::size().

Referenced by data().

34 {
35  return (int) mpMIRIAMInfo->getBiologicalDescriptions().size() + 1;
36 }
const CCopasiVector< CBiologicalDescription > & getBiologicalDescriptions() const
virtual size_t size() const
bool CQBiologicalDescriptionDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 106 of file CQBiologicalDescriptionDM.cpp.

References ListViews::CHANGE, COL_ID_BD, COL_RELATIONSHIP, COL_RESOURCE_BD, CMIRIAMInfo::getBiologicalDescriptions(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), ListViews::MIRIAM, mpMIRIAMInfo, CQBaseDataModel::notifyGUI(), and TO_UTF8.

108 {
109  if (index.isValid() && role == Qt::EditRole)
110  {
111  if (isDefaultRow(index))
112  {
113  if (index.data() != value)
114  insertRow();
115  else
116  return false;
117  }
118 
119  switch (index.column())
120  {
121  case COL_RELATIONSHIP:
122  mpMIRIAMInfo->getBiologicalDescriptions()[index.row()]->setPredicate(TO_UTF8(value.toString()));
123  break;
124  case COL_RESOURCE_BD:
125  mpMIRIAMInfo->getBiologicalDescriptions()[index.row()]->setResource(TO_UTF8(value.toString()));
126  break;
127  case COL_ID_BD:
128  mpMIRIAMInfo->getBiologicalDescriptions()[index.row()]->setId(TO_UTF8(value.toString()));
129  break;
130  }
131 
132  emit dataChanged(index, index);
134  return true;
135  }
136 
137  return false;
138 }
#define COL_ID_BD
#define COL_RESOURCE_BD
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
const CCopasiVector< CBiologicalDescription > & getBiologicalDescriptions() const
#define COL_RELATIONSHIP
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual bool isDefaultRow(const QModelIndex &i) const

Member Data Documentation

CMIRIAMInfo* CQBiologicalDescriptionDM::mpMIRIAMInfo
protected

The documentation for this class was generated from the following files: