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

#include <CQParameterSetsDM.h>

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

Public Member Functions

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

Protected Member Functions

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

Private Attributes

CCopasiVectorN
< CModelParameterSet > * 
mpListOfParameterSets
 

Additional Inherited Members

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

Detailed Description

Definition at line 18 of file CQParameterSetsDM.h.

Constructor & Destructor Documentation

CQParameterSetsDM::CQParameterSetsDM ( QObject *  parent = 0)

Definition at line 17 of file CQParameterSetsDM.cpp.

17  :
18  CQBaseDataModel(parent),
20 {}
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets
CQBaseDataModel(QObject *parent=0)
CQParameterSetsDM::~CQParameterSetsDM ( )
virtual

Definition at line 22 of file CQParameterSetsDM.cpp.

23 {}

Member Function Documentation

bool CQParameterSetsDM::clear ( )
virtual

Reimplemented from CQBaseDataModel.

Definition at line 32 of file CQParameterSetsDM.cpp.

References removeRows(), and rowCount().

Referenced by CQParameterSetsWidget::slotBtnClearClicked().

33 {
34  return removeRows(0, rowCount());
35 }
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
int CQParameterSetsDM::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 37 of file CQParameterSetsDM.cpp.

References TOTAL_COLS.

Referenced by CQParameterSetsWidget::keyPressEvent().

38 {
39  return TOTAL_COLS;
40 }
#define TOTAL_COLS
Definition: CQLayoutsDM.h:22
QVariant CQParameterSetsDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 61 of file CQParameterSetsDM.cpp.

References COL_NAME, COL_ROW_NUMBER, FROM_UTF8, mpListOfParameterSets, and rowCount().

62 {
63  if (mpListOfParameterSets == NULL) return QVariant();
64 
65  if (!index.isValid()) return QVariant();
66 
67  if (index.row() >= rowCount()) return QVariant();
68 
69  if (role == Qt::DisplayRole || role == Qt::EditRole)
70  {
71  switch (index.column())
72  {
73  case COL_ROW_NUMBER:
74  return QVariant(index.row() + 1);
75  break;
76 
77  case COL_NAME:
78  return QVariant(FROM_UTF8((*mpListOfParameterSets)[index.row()]->getObjectName()));
79  break;
80  }
81  }
82 
83  return QVariant();
84 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets
#define COL_NAME
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
#define COL_ROW_NUMBER
Qt::ItemFlags CQParameterSetsDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 42 of file CQParameterSetsDM.cpp.

References COL_NAME, and COL_ROW_NUMBER.

43 {
44  if (!index.isValid())
45  return QAbstractItemModel::flags(index);
46 
47  switch (index.column())
48  {
49  case COL_ROW_NUMBER:
50  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
51  break;
52 
53  case COL_NAME:
54  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
55  break;
56  }
57 
58  return QAbstractItemModel::flags(index);
59 }
#define COL_NAME
#define COL_ROW_NUMBER
QVariant CQParameterSetsDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 86 of file CQParameterSetsDM.cpp.

References COL_NAME, 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  break;
99 
100  case COL_NAME:
101  return QVariant(QString("Name"));
102  break;
103 
104  default:
105  return QVariant();
106  break;
107  }
108  }
109 
110  return QString("%1").arg(section + 1);
111 }
#define COL_NAME
#define COL_ROW_NUMBER
bool CQParameterSetsDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
virtual

Implements CQBaseDataModel.

Definition at line 148 of file CQParameterSetsDM.cpp.

References ListViews::ADD, ListViews::LAYOUT, mpListOfParameterSets, CQBaseDataModel::notifyGUI(), and CCopasiVector< T >::size().

149 {
150  if (mpListOfParameterSets == NULL) return false;
151 
152  if (position + rows > (int) mpListOfParameterSets->size()) return false;
153 
154  beginInsertRows(QModelIndex(), position, position + rows - 1);
155 
156  for (int row = 0; row < rows; ++row)
157  {
158  emit notifyGUI(ListViews::LAYOUT, ListViews::ADD, (*mpListOfParameterSets)[position + row]->getKey());
159  }
160 
161  endInsertRows();
162 
163  return true;
164 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual size_t size() const
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets
bool CQParameterSetsDM::isDefaultRow ( const QModelIndex &  i) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 143 of file CQParameterSetsDM.cpp.

Referenced by CQParameterSetsWidget::slotDoubleClicked(), and CQParameterSetsWidget::updateDeleteBtns().

144 {
145  return false;
146 }
bool CQParameterSetsDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 201 of file CQParameterSetsDM.cpp.

References C_INVALID_INDEX, CQMessageBox::confirmDelete(), FROM_UTF8, CCopasiObject::getObjectName(), mpListOfParameterSets, and CQBaseDataModel::removeRow().

Referenced by clear(), and CQParameterSetsWidget::deleteSelected().

202 {
203  if (rows.isEmpty()) return false;
204 
205  if (mpListOfParameterSets == NULL) return false;
206 
207  // Build the list of pointers to items to be deleted
208  // before actually deleting any item.
209  QList< CModelParameterSet * > ModelParameterSets;
210  QModelIndexList::const_iterator i;
211 
212  for (i = rows.begin(); i != rows.end(); ++i)
213  {
214  ModelParameterSets.append((*mpListOfParameterSets)[(*i).row()]);
215  }
216 
217  QList< CModelParameterSet * >::const_iterator j;
218 
219  for (j = ModelParameterSets.begin(); j != ModelParameterSets.end(); ++j)
220  {
221  CModelParameterSet * pModelParameterSet = *j;
222 
223  size_t delRow = mpListOfParameterSets->CCopasiVector< CModelParameterSet >::getIndex(pModelParameterSet);
224 
225  if (delRow != C_INVALID_INDEX)
226  {
227  QMessageBox::StandardButton choice =
228  CQMessageBox::confirmDelete(NULL, "layout",
229  FROM_UTF8(pModelParameterSet->getObjectName()),
230  std::set< const CCopasiObject * >());
231 
232  if (choice == QMessageBox::Ok)
233  removeRow((int) delRow);
234  }
235  }
236 
237  return true;
238 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets
#define C_INVALID_INDEX
Definition: copasi.h:222
bool removeRow(int position)
static StandardButton confirmDelete(QWidget *parent, const QString &objectType, const QString &objects, const std::set< const CCopasiObject * > &deletedObjects)
bool CQParameterSetsDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 166 of file CQParameterSetsDM.cpp.

References CCopasiVector< T >::begin(), ListViews::DELETE, CCopasiObject::getKey(), ListViews::MODELPARAMETERSET, mpListOfParameterSets, CQBaseDataModel::notifyGUI(), and pdelete.

167 {
168  if (rows <= 0) return true;
169 
170  if (mpListOfParameterSets == NULL) return false;
171 
172  beginRemoveRows(QModelIndex(), position, position + rows - 1);
173 
174  std::vector< CModelParameterSet * > DeletedModelParameterSets;
175  DeletedModelParameterSets.resize(rows);
176 
177  std::vector< CModelParameterSet * >::iterator itDeletedModelParameterSet;
178  std::vector< CModelParameterSet * >::iterator endDeletedModelParameterSet = DeletedModelParameterSets.end();
179 
181 
182  for (itDeletedModelParameterSet = DeletedModelParameterSets.begin(); itDeletedModelParameterSet != endDeletedModelParameterSet; ++itDeletedModelParameterSet, ++itRow)
183  {
184  *itDeletedModelParameterSet = *itRow;
185  }
186 
187  for (itDeletedModelParameterSet = DeletedModelParameterSets.begin(); itDeletedModelParameterSet != endDeletedModelParameterSet; ++itDeletedModelParameterSet)
188  {
189  std::string Key = (*itDeletedModelParameterSet)->getKey();
190 
191  pdelete(*itDeletedModelParameterSet);
192 
194  }
195 
196  endRemoveRows();
197 
198  return true;
199 }
#define pdelete(p)
Definition: copasi.h:215
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets
iterator begin()
virtual const std::string & getKey() const
int CQParameterSetsDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 25 of file CQParameterSetsDM.cpp.

References mpListOfParameterSets, and CCopasiVector< T >::size().

Referenced by clear(), data(), CQParameterSetsWidget::deleteSelected(), and setData().

26 {
27  if (mpListOfParameterSets == NULL) return 0;
28 
29  return (int) mpListOfParameterSets->size();
30 }
virtual size_t size() const
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets
bool CQParameterSetsDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 113 of file CQParameterSetsDM.cpp.

References COL_NAME, COL_ROW_NUMBER, mpListOfParameterSets, and rowCount().

114 {
115  if (mpListOfParameterSets == NULL) return false;
116 
117  if (!index.isValid()) return false;
118 
119  if (index.row() >= rowCount()) return false;
120 
121  if (index.isValid() && role == Qt::EditRole)
122  {
123  switch (index.column())
124  {
125  case COL_ROW_NUMBER:
126  return false;
127  break;
128 
129  case COL_NAME:
130  return false;
131  break;
132 
133  default:
134  return false;
135  break;
136  }
137  }
138 
139  return true;
140 }
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets
#define COL_NAME
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
#define COL_ROW_NUMBER
void CQParameterSetsDM::setListOfModelParameterSets ( CCopasiVectorN< CModelParameterSet > *  pListOfModelParameterSets)

Definition at line 240 of file CQParameterSetsDM.cpp.

References mpListOfParameterSets.

Referenced by CQParameterSetsWidget::enterProtected().

242 {
243  if (mpListOfParameterSets != pListOfModelParameterSets)
244  {
245  mpListOfParameterSets = pListOfModelParameterSets;
246  reset();
247  }
248 }
CCopasiVectorN< CModelParameterSet > * mpListOfParameterSets

Member Data Documentation

CCopasiVectorN< CModelParameterSet >* CQParameterSetsDM::mpListOfParameterSets
private

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