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

#include <CQModifiedDM.h>

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

Public Member Functions

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

Constructor & Destructor Documentation

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

Definition at line 28 of file CQModifiedDM.cpp.

References mpMIRIAMInfo.

29  : CQBaseDataModel(parent)
30 
31 {
32  mpMIRIAMInfo = MIRIAMInfo;
33 }
CQBaseDataModel(QObject *parent=0)
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQModifiedDM.h:47

Member Function Documentation

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

Definition at line 39 of file CQModifiedDM.cpp.

References TOTAL_COLS_MODIFIEDS.

40 {
41  return TOTAL_COLS_MODIFIEDS;
42 }
#define TOTAL_COLS_MODIFIEDS
Definition: CQModifiedDM.h:27
QVariant CQModifiedDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 44 of file CQModifiedDM.cpp.

References COL_DATE_MODIFIED, COL_ROW_NUMBER, FROM_UTF8, CMIRIAMInfo::getModifications(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, and rowCount().

Referenced by removeRows().

45 {
46  if (!index.isValid())
47  return QVariant();
48 
49  if (index.row() >= rowCount())
50  return QVariant();
51 
52  if (role == Qt::DisplayRole || role == Qt::EditRole)
53  {
54  if (isDefaultRow(index))
55  {
56  if (index.column() == COL_ROW_NUMBER)
57  return QVariant(QString(""));
58  else if (index.column() == COL_DATE_MODIFIED)
59  {
60  if (role == Qt::DisplayRole)
61  return QVariant(QDateTime());
62  else
63  return QVariant(QDateTime::currentDateTime());
64  }
65  else
66  return QVariant(QString(""));
67  }
68  else
69  {
70  switch (index.column())
71  {
72  case COL_ROW_NUMBER:
73  return QVariant(index.row() + 1);
74  case COL_DATE_MODIFIED:
75  QDateTime dt(QDateTime::fromString(FROM_UTF8(mpMIRIAMInfo->getModifications()[index.row()]->getDate()), Qt::ISODate));
76 
77  if (dt.isValid())
78  return QVariant(dt);
79  }
80  }
81  }
82 
83  return QVariant();
84 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQModifiedDM.h:47
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_DATE_MODIFIED
Definition: CQModifiedDM.h:26
const CCopasiVector< CModification > & getModifications() const
#define COL_ROW_NUMBER
QVariant CQModifiedDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 86 of file CQModifiedDM.cpp.

References COL_DATE_MODIFIED, and COL_ROW_NUMBER.

88 {
89  if (role != Qt::DisplayRole)
90  return QVariant();
91 
92  if (orientation == Qt::Horizontal)
93  {
94  switch (section)
95  {
96  case COL_ROW_NUMBER:
97  return QVariant(QString("#"));
98  case COL_DATE_MODIFIED:
99  return QVariant(QString("Date and Time Modified"));
100  default:
101  return QVariant();
102  }
103  }
104  else
105  return QString("%1").arg(section + 1);
106 }
#define COL_DATE_MODIFIED
Definition: CQModifiedDM.h:26
#define COL_ROW_NUMBER
bool CQModifiedDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 136 of file CQModifiedDM.cpp.

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

137 {
138  beginInsertRows(QModelIndex(), position, position + rows - 1);
139 
140  for (int row = 0; row < rows; ++row)
141  {
142  //mpMIRIAMInfo->createModification(TO_UTF8(QDateTime::currentDateTime().toString(Qt::ISODate)));
144  }
145 
146  endInsertRows();
147 
149  return true;
150 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQModifiedDM.h:47
CModification * createModification(const std::string &objectName)
bool CQModifiedDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 170 of file CQModifiedDM.cpp.

References C_INVALID_INDEX, COL_DATE_MODIFIED, data(), CMIRIAMInfo::getModifications(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, CQMessageBox::question(), and CQBaseDataModel::removeRow().

Referenced by CQMiriamWidget::deleteSelectedModifieds().

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

Implements CQBaseDataModel.

Definition at line 152 of file CQModifiedDM.cpp.

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

153 {
154  if (rows <= 0)
155  return true;
156 
157  beginRemoveRows(QModelIndex(), position, position + rows - 1);
158 
159  for (int row = 0; row < rows; ++row)
160  {
161  mpMIRIAMInfo->removeModification(position);
162  }
163 
164  endRemoveRows();
165 
167  return true;
168 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
bool removeModification(int position)
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQModifiedDM.h:47
int CQModifiedDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 35 of file CQModifiedDM.cpp.

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

Referenced by data().

36 {
37  return (int) mpMIRIAMInfo->getModifications().size() + 1;
38 }
virtual size_t size() const
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQModifiedDM.h:47
const CCopasiVector< CModification > & getModifications() const
bool CQModifiedDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 108 of file CQModifiedDM.cpp.

References ListViews::CHANGE, COL_DATE_MODIFIED, CMIRIAMInfo::getModifications(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), ListViews::MIRIAM, mpMIRIAMInfo, CQBaseDataModel::notifyGUI(), and TO_UTF8.

110 {
111  if (index.isValid() && role == Qt::EditRole)
112  {
113  if (isDefaultRow(index))
114  {
115  if (index.data() != value)
116  insertRow();
117  else
118  return false;
119  }
120 
121  switch (index.column())
122  {
123  case COL_DATE_MODIFIED:
124  mpMIRIAMInfo->getModifications()[index.row()]->setDate(TO_UTF8(value.toDateTime().toString(Qt::ISODate)));
125  break;
126  }
127 
128  emit dataChanged(index, index);
130  return true;
131  }
132 
133  return false;
134 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQModifiedDM.h:47
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_DATE_MODIFIED
Definition: CQModifiedDM.h:26
const CCopasiVector< CModification > & getModifications() const

Member Data Documentation

CMIRIAMInfo* CQModifiedDM::mpMIRIAMInfo
protected

Definition at line 47 of file CQModifiedDM.h.

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


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