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

#include <CQReferenceDM.h>

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

Public Member Functions

virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQReferenceDM (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 CQReferenceDM.h.

Constructor & Destructor Documentation

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

Definition at line 25 of file CQReferenceDM.cpp.

References mpMIRIAMInfo.

26  : CQBaseDataModel(parent)
27 
28 {
29  mpMIRIAMInfo = MIRIAMInfo;
30 }
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQReferenceDM.h:49
CQBaseDataModel(QObject *parent=0)

Member Function Documentation

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

Definition at line 36 of file CQReferenceDM.cpp.

References TOTAL_COLS_REFERENCES.

37 {
38  return TOTAL_COLS_REFERENCES;
39 }
#define TOTAL_COLS_REFERENCES
Definition: CQReferenceDM.h:29
QVariant CQReferenceDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 41 of file CQReferenceDM.cpp.

References COL_DESCRIPTION, COL_ID_REFERENCE, COL_RESOURCE_REFERENCE, COL_ROW_NUMBER, FROM_UTF8, CMIRIAMInfo::getReferences(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, and rowCount().

Referenced by removeRows().

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

Implements CQBaseDataModel.

Definition at line 79 of file CQReferenceDM.cpp.

References COL_DESCRIPTION, COL_ID_REFERENCE, COL_RESOURCE_REFERENCE, and COL_ROW_NUMBER.

81 {
82  if (role != Qt::DisplayRole)
83  return QVariant();
84 
85  if (orientation == Qt::Horizontal)
86  {
87  switch (section)
88  {
89  case COL_ROW_NUMBER:
90  return QVariant(QString("#"));
92  return QVariant(QString(" Resource "));
93  case COL_ID_REFERENCE:
94  return QVariant(QString("ID "));
95  case COL_DESCRIPTION:
96  return QVariant(QString("Description"));
97  default:
98  return QVariant();
99  }
100  }
101  else
102  return QString("%1").arg(section + 1);
103 }
#define COL_RESOURCE_REFERENCE
Definition: CQReferenceDM.h:26
#define COL_DESCRIPTION
Definition: CQReferenceDM.h:28
#define COL_ID_REFERENCE
Definition: CQReferenceDM.h:27
#define COL_ROW_NUMBER
bool CQReferenceDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 139 of file CQReferenceDM.cpp.

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

140 {
141  beginInsertRows(QModelIndex(), position, position + rows - 1);
142 
143  for (int row = 0; row < rows; ++row)
144  {
146  }
147 
148  endInsertRows();
149 
151  return true;
152 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CReference * createReference(const std::string &objectName)
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQReferenceDM.h:49
bool CQReferenceDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 172 of file CQReferenceDM.cpp.

References C_INVALID_INDEX, COL_ID_REFERENCE, COL_RESOURCE_REFERENCE, data(), CMIRIAMInfo::getReferences(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, CQMessageBox::question(), and CQBaseDataModel::removeRow().

Referenced by CQMiriamWidget::deleteSelectedReferences().

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 <CReference *> pReferences;
180  QModelIndexList::const_iterator i;
181 
182  for (i = rows.begin(); i != rows.end(); ++i)
183  {
184  if (!isDefaultRow(*i) && mpMIRIAMInfo->getReferences()[(*i).row()])
185  pReferences.append(mpMIRIAMInfo->getReferences()[(*i).row()]);
186  }
187 
188  bool retVal = false, askEveryItem = true;
189  QMessageBox::StandardButton choice = QMessageBox::NoToAll;
190  QList <CReference *>::const_iterator j;
191 
192  for (j = pReferences.begin(); j != pReferences.end(); ++j)
193  {
194  CReference * pReference = *j;
195 
196  size_t delRow =
197  mpMIRIAMInfo->getReferences().CCopasiVector< CReference >::getIndex(pReference);
198 
199  if (delRow != C_INVALID_INDEX)
200  {
201  if (askEveryItem)
202  {
203  QString resource = data(this->index((int) delRow, COL_RESOURCE_REFERENCE), Qt::DisplayRole).toString();
204  QString Id = data(this->index((int) delRow, COL_ID_REFERENCE), Qt::DisplayRole).toString();
205  QString msg = "Do you want to delete Reference '";
206 
207  if (!resource.isNull())
208  {
209  msg.append(resource);
210  }
211 
212  if (!Id.isNull())
213  {
214  msg.append(":");
215  msg.append(Id);
216  }
217 
218  msg.append("'?");
219 
220  choice = CQMessageBox::question(NULL, tr("Confirm Delete"), msg,
221  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll,
222  QMessageBox::No);
223  }
224 
225  if (choice == QMessageBox::NoToAll)
226  {return retVal;}
227  else if (choice == QMessageBox::Yes)
228  {retVal = removeRow((int) delRow);}
229  else if (choice == QMessageBox::YesToAll)
230  {
231  askEveryItem = false;
232  retVal = removeRow((int) delRow);
233  }
234  }
235  }
236 
237  return true;
238 }
#define C_INVALID_INDEX
Definition: copasi.h:222
bool removeRow(int position)
#define COL_RESOURCE_REFERENCE
Definition: CQReferenceDM.h:26
const CCopasiVector< CReference > & getReferences() const
QVariant data(const QModelIndex &index, int role) const
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQReferenceDM.h:49
virtual bool isDefaultRow(const QModelIndex &i) const
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define COL_ID_REFERENCE
Definition: CQReferenceDM.h:27
bool CQReferenceDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 154 of file CQReferenceDM.cpp.

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

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  {
163  mpMIRIAMInfo->removeReference(position);
164  }
165 
166  endRemoveRows();
167 
169  return true;
170 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
bool removeReference(int position)
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQReferenceDM.h:49
int CQReferenceDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 32 of file CQReferenceDM.cpp.

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

Referenced by data().

33 {
34  return (int) mpMIRIAMInfo->getReferences().size() + 1;
35 }
virtual size_t size() const
const CCopasiVector< CReference > & getReferences() const
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQReferenceDM.h:49
bool CQReferenceDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 105 of file CQReferenceDM.cpp.

References ListViews::CHANGE, COL_DESCRIPTION, COL_ID_REFERENCE, COL_RESOURCE_REFERENCE, CMIRIAMInfo::getReferences(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), ListViews::MIRIAM, mpMIRIAMInfo, CQBaseDataModel::notifyGUI(), and TO_UTF8.

107 {
108  if (index.isValid() && role == Qt::EditRole)
109  {
110  if (isDefaultRow(index))
111  {
112  if (index.data() != value)
113  insertRow();
114  else
115  return false;
116  }
117 
118  switch (index.column())
119  {
121  mpMIRIAMInfo->getReferences()[index.row()]->setResource(TO_UTF8(value.toString()));
122  break;
123  case COL_ID_REFERENCE:
124  mpMIRIAMInfo->getReferences()[index.row()]->setId(TO_UTF8(value.toString()));
125  break;
126  case COL_DESCRIPTION:
127  mpMIRIAMInfo->getReferences()[index.row()]->setDescription(TO_UTF8(value.toString()));
128  break;
129  }
130 
131  emit dataChanged(index, index);
133  return true;
134  }
135 
136  return false;
137 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
#define COL_RESOURCE_REFERENCE
Definition: CQReferenceDM.h:26
const CCopasiVector< CReference > & getReferences() const
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQReferenceDM.h:49
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_DESCRIPTION
Definition: CQReferenceDM.h:28
#define COL_ID_REFERENCE
Definition: CQReferenceDM.h:27

Member Data Documentation

CMIRIAMInfo* CQReferenceDM::mpMIRIAMInfo
protected

Definition at line 49 of file CQReferenceDM.h.

Referenced by CQReferenceDM(), data(), insertRows(), removeRows(), rowCount(), and setData().


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