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

#include <CQPlotDM.h>

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

Public Member Functions

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

Constructor & Destructor Documentation

CQPlotDM::CQPlotDM ( QObject *  parent = 0)

Definition at line 22 of file CQPlotDM.cpp.

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

Member Function Documentation

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

Definition at line 32 of file CQPlotDM.cpp.

References TOTAL_COLS_PLOTS.

Referenced by CQPlotsWidget::keyPressEvent().

33 {
34  return TOTAL_COLS_PLOTS;
35 }
#define TOTAL_COLS_PLOTS
Definition: CQPlotDM.h:28
QVariant CQPlotDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 50 of file CQPlotDM.cpp.

References COL_ACTIVE_PLOTS, COL_CURVES_PLOTS, COL_NAME_PLOTS, COL_ROW_NUMBER, flags(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CPlotSpecification::getItems(), CCopasiObject::getObjectName(), CPlotSpecification::isActive(), CQBaseDataModel::isDefaultRow(), rowCount(), and CCopasiVector< T >::size().

Referenced by setData().

51 {
52  if (!index.isValid())
53  return QVariant();
54 
55  if (index.row() >= rowCount())
56  return QVariant();
57 
58  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
59  return QColor(Qt::darkGray);
60 
61  if (role == Qt::DisplayRole || role == Qt::EditRole)
62  {
63  if (isDefaultRow(index))
64  {
65  switch (index.column())
66  {
67  case COL_ROW_NUMBER:
68  return QVariant(QString(""));
69  case COL_NAME_PLOTS:
70  return QVariant(QString("New Plot"));
71  case COL_ACTIVE_PLOTS:
72 
73  if (role == Qt::DisplayRole)
74  return QVariant();
75  else
76  return QVariant(true);
77 
78  default:
79  return QVariant(QString(""));
80  }
81  }
82  else
83  {
84  const CPlotSpecification *pPS = dynamic_cast<const CPlotSpecification*>((*CCopasiRootContainer::getDatamodelList())[0]->getPlotDefinitionList()->operator[](index.row()));
85 
86  switch (index.column())
87  {
88  case COL_ROW_NUMBER:
89  return QVariant(index.row() + 1);
90 
91  case COL_NAME_PLOTS:
92  return QVariant(QString(FROM_UTF8(pPS->getObjectName())));
93 
94  case COL_CURVES_PLOTS:
95  return QVariant((unsigned int)pPS->getItems().size());
96 
97  case COL_ACTIVE_PLOTS:
98 
99  if (role == Qt::DisplayRole)
100  return QVariant();
101  else
102  return QVariant(pPS->isActive());
103  }
104  }
105  }
106  else if (role == Qt::CheckStateRole && index.column() == COL_ACTIVE_PLOTS)
107  return index.data(Qt::EditRole).toBool() ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
108 
109  return QVariant();
110 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQPlotDM.cpp:28
#define COL_NAME_PLOTS
Definition: CQPlotDM.h:25
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
#define COL_CURVES_PLOTS
Definition: CQPlotDM.h:26
const std::string & getObjectName() const
virtual size_t size() const
const bool & isActive() const
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: CQPlotDM.cpp:37
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const CCopasiVector< CPlotItem > & getItems() const
#define COL_ACTIVE_PLOTS
Definition: CQPlotDM.h:27
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_ROW_NUMBER
Qt::ItemFlags CQPlotDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 37 of file CQPlotDM.cpp.

References COL_ACTIVE_PLOTS, and COL_NAME_PLOTS.

Referenced by data().

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

Implements CQBaseDataModel.

Definition at line 112 of file CQPlotDM.cpp.

References COL_ACTIVE_PLOTS, COL_CURVES_PLOTS, COL_NAME_PLOTS, and COL_ROW_NUMBER.

114 {
115  if (role != Qt::DisplayRole)
116  return QVariant();
117 
118  if (orientation == Qt::Horizontal)
119  {
120  switch (section)
121  {
122  case COL_ROW_NUMBER:
123  return QVariant(QString("#"));
124  case COL_NAME_PLOTS:
125  return QVariant(QString("Name"));
126  case COL_CURVES_PLOTS:
127  return QVariant(QString("Nr. of Curves"));
128  case COL_ACTIVE_PLOTS:
129  return QVariant(QString("Active"));
130  default:
131  return QVariant();
132  }
133  }
134  else
135  return QString("%1").arg(section + 1);
136 }
#define COL_NAME_PLOTS
Definition: CQPlotDM.h:25
#define COL_CURVES_PLOTS
Definition: CQPlotDM.h:26
#define COL_ACTIVE_PLOTS
Definition: CQPlotDM.h:27
#define COL_ROW_NUMBER
bool CQPlotDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 206 of file CQPlotDM.cpp.

References ListViews::ADD, COL_NAME_PLOTS, CQBaseDataModel::createNewName(), CCopasiRootContainer::getDatamodelList(), CQBaseDataModel::notifyGUI(), ListViews::PLOT, CPlotItem::plot2d, and TO_UTF8.

207 {
208  beginInsertRows(QModelIndex(), position, position + rows - 1);
209 
210  for (int row = 0; row < rows; ++row)
211  {
212  CPlotSpecification *pPS = (*CCopasiRootContainer::getDatamodelList())[0]->getPlotDefinitionList()->createPlotSpec(TO_UTF8(createNewName("plot", COL_NAME_PLOTS)), CPlotItem::plot2d);
213  emit notifyGUI(ListViews::PLOT, ListViews::ADD, pPS->CCopasiParameter::getKey());
214  }
215 
216  endInsertRows();
217 
218  return true;
219 }
#define COL_NAME_PLOTS
Definition: CQPlotDM.h:25
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool CQPlotDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 242 of file CQPlotDM.cpp.

References CCopasiRootContainer::getDatamodelList(), CCopasiDataModel::getModel(), CCopasiDataModel::getPlotDefinitionList(), CQBaseDataModel::isDefaultRow(), and CQBaseDataModel::removeRow().

Referenced by CQPlotsWidget::deleteSelectedPlots().

243 {
244  if (rows.isEmpty())
245  return false;
246 
248  assert(pDataModel != NULL);
249 
250  if (!pDataModel->getModel())
251  return false;
252 
253 //Build the list of pointers to items to be deleted
254 //before actually deleting any item.
255  QList <CPlotSpecification *> pPSs;
256  QModelIndexList::const_iterator i;
257  CPlotSpecification * pPS = NULL;
258 
259  for (i = rows.begin(); i != rows.end(); ++i)
260  {
261  if (!isDefaultRow(*i) && pDataModel->getPlotDefinitionList()->operator[]((*i).row()))
262  {
263  pPS = pDataModel->getPlotDefinitionList()->operator[]((*i).row());
264  pPSs.append(pPS);
265  }
266  }
267 
268  QList <CPlotSpecification *>::const_iterator j;
269 
270  for (j = pPSs.begin(); j != pPSs.end(); ++j)
271  {
272  pPS = *j;
273 
274  size_t delRow =
275  pDataModel->getPlotDefinitionList()->CCopasiVector< CPlotSpecification >::getIndex(pPS);
276  removeRow((int) delRow);
277  }
278 
279  return true;
280 }
bool removeRow(int position)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const COutputDefinitionVector * getPlotDefinitionList() const
virtual bool isDefaultRow(const QModelIndex &i) const
bool CQPlotDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 221 of file CQPlotDM.cpp.

References ListViews::DELETE, CCopasiRootContainer::getDatamodelList(), CQBaseDataModel::notifyGUI(), and ListViews::PLOT.

222 {
223  if (rows <= 0)
224  return true;
225 
226  beginRemoveRows(QModelIndex(), position, position + rows - 1);
227 
228  for (int row = 0; row < rows; ++row)
229  {
230  CPlotSpecification* pPS =
231  (CPlotSpecification*)(*CCopasiRootContainer::getDatamodelList())[0]->getPlotDefinitionList()->operator[](position);
232  std::string deletedKey = pPS->CCopasiParameter::getKey();
233  (*CCopasiRootContainer::getDatamodelList())[0]->getPlotDefinitionList()->CCopasiVector< CPlotSpecification >::remove(position);
234  emit notifyGUI(ListViews::PLOT, ListViews::DELETE, deletedKey);
235  }
236 
237  endRemoveRows();
238 
239  return true;
240 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
int CQPlotDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 28 of file CQPlotDM.cpp.

References CCopasiRootContainer::getDatamodelList().

Referenced by data(), and CQPlotsWidget::deleteSelectedPlots().

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

Implements CQBaseDataModel.

Definition at line 138 of file CQPlotDM.cpp.

References ListViews::CHANGE, COL_ACTIVE_PLOTS, COL_NAME_PLOTS, CQBaseDataModel::createNewName(), data(), CCopasiRootContainer::getDatamodelList(), CCopasiObject::getObjectName(), CQBaseDataModel::insertRow(), CPlotSpecification::isActive(), CQBaseDataModel::isDefaultRow(), CQBaseDataModel::notifyGUI(), ListViews::PLOT, CPlotSpecification::setActive(), CCopasiObject::setObjectName(), and TO_UTF8.

140 {
141  if (index.isValid() && role == Qt::EditRole)
142  {
143  bool changed = false;
144  bool defaultRow = isDefaultRow(index);
145 
146  if (defaultRow)
147  {
148  if (index.data() != value)
149  {
150  insertRow();
151  changed = true;
152  }
153  else
154  return false;
155  }
156 
157  CPlotSpecification *pPS = (CPlotSpecification*)(*CCopasiRootContainer::getDatamodelList())[0]->getPlotDefinitionList()->operator[](index.row());
158 
159  switch (index.column())
160  {
161  case COL_NAME_PLOTS:
162 
163  if (pPS->getObjectName() != TO_UTF8(value.toString()))
164  {
165  pPS->setObjectName(TO_UTF8(value.toString()));
166  changed = true;
167  }
168 
169  break;
170 
171  case COL_ACTIVE_PLOTS:
172 
173  if (pPS->isActive() != value.toBool())
174  {
175  pPS->setActive(value.toBool());
176  changed = true;
177  }
178 
179  break;
180 
181  default:
182  break;
183  }
184 
185  if (defaultRow && this->index(index.row(), COL_NAME_PLOTS).data().toString() == "plot")
186  {
188  changed = true;
189  }
190 
191  if (changed)
192  {
193  emit dataChanged(index, index);
194  emit notifyGUI(ListViews::PLOT, ListViews::CHANGE, pPS->CCopasiParameter::getKey());
195  }
196  }
197  else if (role == Qt::CheckStateRole && index.column() == COL_ACTIVE_PLOTS)
198  {
199  QVariant data = value.toInt() == Qt::Checked ? QVariant(true) : QVariant(false);
200  return setData(index, data, Qt::EditRole);
201  }
202 
203  return true;
204 }
#define COL_NAME_PLOTS
Definition: CQPlotDM.h:25
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
const std::string & getObjectName() const
void setActive(const bool &active)
const bool & isActive() const
QVariant data(const QModelIndex &index, int role) const
Definition: CQPlotDM.cpp:50
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: CQPlotDM.cpp:138
#define COL_ACTIVE_PLOTS
Definition: CQPlotDM.h:27
#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: