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

#include <CQReportDM.h>

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

Public Member Functions

virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQReportDM (QObject *parent=0)
 
QVariant data (const QModelIndex &index, int role) const
 
Qt::ItemFlags flags (const QModelIndex &index) 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)
 
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())
 

Additional Inherited Members

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

Detailed Description

Definition at line 28 of file CQReportDM.h.

Constructor & Destructor Documentation

CQReportDM::CQReportDM ( QObject *  parent = 0)

Definition at line 23 of file CQReportDM.cpp.

24  : CQBaseDataModel(parent)
25 
26 {
27 }
CQBaseDataModel(QObject *parent=0)

Member Function Documentation

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

Definition at line 33 of file CQReportDM.cpp.

References TOTAL_COLS_REPORTS.

Referenced by CQReportsWidget::keyPressEvent().

34 {
35  return TOTAL_COLS_REPORTS;
36 }
#define TOTAL_COLS_REPORTS
Definition: CQReportDM.h:26
QVariant CQReportDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 49 of file CQReportDM.cpp.

References COL_NAME_REPORTS, COL_ROW_NUMBER, flags(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CCopasiObject::getObjectName(), CQBaseDataModel::isDefaultRow(), and rowCount().

Referenced by setData().

50 {
51  if (!index.isValid())
52  return QVariant();
53 
54  if (index.row() >= rowCount())
55  return QVariant();
56 
57  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
58  return QColor(Qt::darkGray);
59 
60  if (role == Qt::DisplayRole || role == Qt::EditRole)
61  {
62  if (isDefaultRow(index))
63  {
64  switch (index.column())
65  {
66  case COL_ROW_NUMBER:
67  return QVariant(QString(""));
68  case COL_NAME_REPORTS:
69  return QVariant(QString("New Report"));
70  default:
71  return QVariant(QString(""));
72  }
73  }
74  else
75  {
76  CReportDefinition *pRepDef = (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList()->operator[](index.row());
77 
78  switch (index.column())
79  {
80  case COL_ROW_NUMBER:
81  return QVariant(index.row() + 1);
82 
83  case COL_NAME_REPORTS:
84  return QVariant(QString(FROM_UTF8(pRepDef->getObjectName())));
85  }
86  }
87  }
88 
89  return QVariant();
90 }
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: CQReportDM.cpp:38
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
#define COL_NAME_REPORTS
Definition: CQReportDM.h:25
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQReportDM.cpp:29
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_ROW_NUMBER
Qt::ItemFlags CQReportDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 38 of file CQReportDM.cpp.

References COL_NAME_REPORTS.

Referenced by data().

39 {
40  if (!index.isValid())
41  return Qt::ItemIsEnabled;
42 
43  if (index.column() == COL_NAME_REPORTS)
44  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
45  else
46  return QAbstractItemModel::flags(index);
47 }
#define COL_NAME_REPORTS
Definition: CQReportDM.h:25
QVariant CQReportDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 92 of file CQReportDM.cpp.

References COL_NAME_REPORTS, and COL_ROW_NUMBER.

94 {
95  if (role != Qt::DisplayRole)
96  return QVariant();
97 
98  if (orientation == Qt::Horizontal)
99  {
100  switch (section)
101  {
102  case COL_ROW_NUMBER:
103  return QVariant(QString("#"));
104  case COL_NAME_REPORTS:
105  return QVariant(QString("Name"));
106  default:
107  return QVariant();
108  }
109  }
110  else
111  return QString("%1").arg(section + 1);
112 }
#define COL_NAME_REPORTS
Definition: CQReportDM.h:25
#define COL_ROW_NUMBER
bool CQReportDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 144 of file CQReportDM.cpp.

References ListViews::ADD, COL_NAME_REPORTS, CQBaseDataModel::createNewName(), CCopasiRootContainer::getDatamodelList(), CReportDefinition::getKey(), CQBaseDataModel::notifyGUI(), ListViews::REPORT, and TO_UTF8.

145 {
146  beginInsertRows(QModelIndex(), position, position + rows - 1);
147 
148  for (int row = 0; row < rows; ++row)
149  {
150  CReportDefinition *pRepDef =
151  (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList()->createReportDefinition(TO_UTF8(createNewName("report", COL_NAME_REPORTS)), "");
153  }
154 
155  endInsertRows();
156 
157  return true;
158 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
#define COL_NAME_REPORTS
Definition: CQReportDM.h:25
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
virtual const std::string & getKey() const
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool CQReportDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 210 of file CQReportDM.cpp.

References C_INVALID_INDEX, CQMessageBox::confirmDelete(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CCopasiVector< T >::getIndex(), CCopasiObject::getObjectName(), CCopasiDataModel::getReportDefinitionList(), CQBaseDataModel::isDefaultRow(), and CQBaseDataModel::removeRow().

Referenced by CQReportsWidget::deleteSelectedReports().

211 {
212  if (rows.isEmpty())
213  return false;
214 
216  assert(pDataModel != NULL);
217 
218  CCopasiVector< CReportDefinition > * pReportList = pDataModel->getReportDefinitionList();
219 
220  if (pReportList == NULL)
221  return false;
222 
223  QList< CReportDefinition * > Reports;
224 
225  QModelIndexList::const_iterator i;
226 
227  for (i = rows.begin(); i != rows.end(); ++i)
228  {
229  if (!isDefaultRow(*i) && (*pReportList)[(*i).row()])
230  Reports.append((*pReportList)[(*i).row()]);
231  }
232 
233  QList< CReportDefinition * >::const_iterator j;
234 
235  for (j = Reports.begin(); j != Reports.end(); ++j)
236  {
237  CReportDefinition * pReport = *j;
238 
239  size_t delRow = pReportList->getIndex(pReport);
240 
241  if (delRow != C_INVALID_INDEX)
242  {
243  std::set< const CCopasiObject * > DeletedObjects;
244  DeletedObjects.insert(pReport);
245 
246  QMessageBox::StandardButton choice =
247  CQMessageBox::confirmDelete(NULL, "report",
248  FROM_UTF8(pReport->getObjectName()),
249  DeletedObjects);
250 
251  if (choice == QMessageBox::Ok)
252  {
253  removeRow((int) delRow);
254  }
255  }
256  }
257 
258  return true;
259 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
#define C_INVALID_INDEX
Definition: copasi.h:222
const CReportDefinitionVector * getReportDefinitionList() const
bool removeRow(int position)
static StandardButton confirmDelete(QWidget *parent, const QString &objectType, const QString &objects, const std::set< const CCopasiObject * > &deletedObjects)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual size_t getIndex(const CCopasiObject *pObject) const
virtual bool isDefaultRow(const QModelIndex &i) const
bool CQReportDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 160 of file CQReportDM.cpp.

References CCopasiDataModel::appendDependentTasks(), ListViews::DELETE, CCopasiRootContainer::getDatamodelList(), CReportDefinition::getKey(), CCopasiDataModel::getReportDefinitionList(), CQBaseDataModel::notifyGUI(), pTask, CCopasiVector< T >::remove(), and ListViews::REPORT.

161 {
162  if (rows <= 0)
163  return true;
164 
166 
167  if (pDataModel == NULL)
168  return false;
169 
170  CCopasiVector< CReportDefinition > * pReportList = pDataModel->getReportDefinitionList();
171 
172  if (pReportList == NULL)
173  return false;
174 
175  beginRemoveRows(QModelIndex(), position, position + rows - 1);
176 
177  for (int row = 0; row < rows; ++row)
178  {
179  CReportDefinition * pReport = (*pReportList)[position];
180 
181  if (pReport == NULL)
182  continue;
183 
184  std::set< const CCopasiObject * > Tasks;
185  std::set< const CCopasiObject * > DeletedObjects;
186  DeletedObjects.insert(pReport);
187 
188  if (pDataModel->appendDependentTasks(DeletedObjects, Tasks))
189  {
190  std::set< const CCopasiObject * >::iterator it = Tasks.begin();
191  std::set< const CCopasiObject * >::iterator end = Tasks.end();
192 
193  for (; it != end; ++it)
194  {
195  const CCopasiTask * pTask = static_cast< const CCopasiTask *>(*it);
196  const_cast< CCopasiTask * >(pTask)->getReport().setReportDefinition(NULL);
197  }
198  }
199 
200  std::string deletedKey = pReport->getKey();
201  pReportList->remove(pReport);
202  emit notifyGUI(ListViews::REPORT, ListViews::DELETE, deletedKey);
203  }
204 
205  endRemoveRows();
206 
207  return true;
208 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
bool appendDependentTasks(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentTasks) const
const CReportDefinitionVector * getReportDefinitionList() const
CTSSATask * pTask
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual const std::string & getKey() const
virtual void remove(const size_t &index)
int CQReportDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 29 of file CQReportDM.cpp.

References CCopasiRootContainer::getDatamodelList().

Referenced by data(), and CQReportsWidget::deleteSelectedReports().

30 {
31  return (int)(*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList()->size() + 1;
32 }
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool CQReportDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 114 of file CQReportDM.cpp.

References ListViews::CHANGE, COL_NAME_REPORTS, CQBaseDataModel::createNewName(), data(), CCopasiRootContainer::getDatamodelList(), CReportDefinition::getKey(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), CQBaseDataModel::notifyGUI(), ListViews::REPORT, CCopasiObject::setObjectName(), and TO_UTF8.

116 {
117  if (index.isValid() && role == Qt::EditRole)
118  {
119  bool defaultRow = isDefaultRow(index);
120 
121  if (defaultRow)
122  {
123  if (index.data() != value)
124  insertRow();
125  else
126  return false;
127  }
128 
129  CReportDefinition *pRepDef = (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList()->operator[](index.row());
130 
131  if (index.column() == COL_NAME_REPORTS)
132  pRepDef->setObjectName(TO_UTF8(value.toString()));
133 
134  if (defaultRow && this->index(index.row(), COL_NAME_REPORTS).data().toString() == "report")
135  pRepDef->setObjectName(TO_UTF8(createNewName("report", COL_NAME_REPORTS)));
136 
137  emit dataChanged(index, index);
139  }
140 
141  return true;
142 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
#define COL_NAME_REPORTS
Definition: CQReportDM.h:25
QVariant data(const QModelIndex &index, int role) const
Definition: CQReportDM.cpp:49
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
virtual const std::string & getKey() const
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual bool isDefaultRow(const QModelIndex &i) const
bool setObjectName(const std::string &name)

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