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

#include <CQLayoutsDM.h>

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

Public Member Functions

virtual bool clear ()
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQLayoutsDM (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 setListOfLayouts (CListOfLayouts *pListOfLayouts)
 
virtual ~CQLayoutsDM ()
 
- 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

CListOfLayoutsmpListOfLayouts
 

Additional Inherited Members

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

Detailed Description

Definition at line 26 of file CQLayoutsDM.h.

Constructor & Destructor Documentation

CQLayoutsDM::CQLayoutsDM ( QObject *  parent = 0)

Definition at line 16 of file CQLayoutsDM.cpp.

16  :
17  CQBaseDataModel(parent),
18  mpListOfLayouts(NULL)
19 {}
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54
CQBaseDataModel(QObject *parent=0)
CQLayoutsDM::~CQLayoutsDM ( )
virtual

Definition at line 21 of file CQLayoutsDM.cpp.

22 {}

Member Function Documentation

bool CQLayoutsDM::clear ( )
virtual

Reimplemented from CQBaseDataModel.

Definition at line 31 of file CQLayoutsDM.cpp.

References removeRows(), and rowCount().

Referenced by CQLayoutsWidget::slotBtnClearClicked().

32 {
33  return removeRows(0, rowCount());
34 }
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQLayoutsDM.cpp:24
int CQLayoutsDM::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 36 of file CQLayoutsDM.cpp.

References TOTAL_COLS.

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

Implements CQBaseDataModel.

Definition at line 64 of file CQLayoutsDM.cpp.

References COL_NAME, COL_ROW_NUMBER, COL_SHOW, FROM_UTF8, mpListOfLayouts, and rowCount().

65 {
66  if (mpListOfLayouts == NULL) return QVariant();
67 
68  if (!index.isValid()) return QVariant();
69 
70  if (index.row() >= rowCount()) return QVariant();
71 
72  if (role == Qt::DisplayRole || role == Qt::EditRole)
73  {
74  switch (index.column())
75  {
76  case COL_ROW_NUMBER:
77  return QVariant(index.row() + 1);
78  break;
79 
80  case COL_NAME:
81  return QVariant(FROM_UTF8((*mpListOfLayouts)[index.row()]->getObjectName()));
82  break;
83 
84  case COL_SHOW:
85  return (role == Qt::EditRole) ? QVariant("Show") : QVariant();
86  break;
87  }
88  }
89 
90  return QVariant();
91 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQLayoutsDM.cpp:24
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54
#define COL_NAME
#define COL_SHOW
Definition: CQLayoutsDM.h:21
#define COL_ROW_NUMBER
Qt::ItemFlags CQLayoutsDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 41 of file CQLayoutsDM.cpp.

References COL_NAME, COL_ROW_NUMBER, and COL_SHOW.

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

Implements CQBaseDataModel.

Definition at line 93 of file CQLayoutsDM.cpp.

References COL_NAME, COL_ROW_NUMBER, and COL_SHOW.

95 {
96  if (role != Qt::DisplayRole)
97  return QVariant();
98 
99  if (orientation == Qt::Horizontal)
100  {
101  switch (section)
102  {
103  case COL_ROW_NUMBER:
104  return QVariant(QString("#"));
105  break;
106 
107  case COL_NAME:
108  return QVariant(QString("Name"));
109  break;
110 
111  case COL_SHOW:
112  return QVariant("Show");
113  break;
114 
115  default:
116  return QVariant();
117  break;
118  }
119  }
120 
121  return QString("%1").arg(section + 1);
122 }
#define COL_NAME
#define COL_SHOW
Definition: CQLayoutsDM.h:21
#define COL_ROW_NUMBER
bool CQLayoutsDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
virtual

Implements CQBaseDataModel.

Definition at line 163 of file CQLayoutsDM.cpp.

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

Referenced by CQLayoutsWidget::slotBtnNewClicked().

164 {
165  if (mpListOfLayouts == NULL) return false;
166 
167  if (position + rows > (int) mpListOfLayouts->size()) return false;
168 
169  beginInsertRows(QModelIndex(), position, position + rows - 1);
170 
171  for (int row = 0; row < rows; ++row)
172  {
173  emit notifyGUI(ListViews::LAYOUT, ListViews::ADD, (*mpListOfLayouts)[position + row]->getKey());
174  }
175 
176  endInsertRows();
177 
178  return true;
179 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual size_t size() const
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54
bool CQLayoutsDM::isDefaultRow ( const QModelIndex &  i) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 158 of file CQLayoutsDM.cpp.

159 {
160  return false;
161 }
bool CQLayoutsDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 216 of file CQLayoutsDM.cpp.

References C_INVALID_INDEX, CQMessageBox::confirmDelete(), FROM_UTF8, CCopasiVector< T >::getIndex(), CCopasiObject::getObjectName(), mpListOfLayouts, and CQBaseDataModel::removeRow().

Referenced by clear(), and CQLayoutsWidget::deleteSelectedLayouts().

217 {
218  if (rows.isEmpty()) return false;
219 
220  if (mpListOfLayouts == NULL) return false;
221 
222  // Build the list of pointers to items to be deleted
223  // before actually deleting any item.
224  QList< CLayout * > Layouts;
225  QModelIndexList::const_iterator i;
226 
227  for (i = rows.begin(); i != rows.end(); ++i)
228  {
229  Layouts.append((*mpListOfLayouts)[(*i).row()]);
230  }
231 
232  QList< CLayout * >::const_iterator j;
233 
234  for (j = Layouts.begin(); j != Layouts.end(); ++j)
235  {
236  CLayout * pLayout = *j;
237 
238  size_t delRow = mpListOfLayouts->getIndex(pLayout);
239 
240  if (delRow != C_INVALID_INDEX)
241  {
242  QMessageBox::StandardButton choice =
243  CQMessageBox::confirmDelete(NULL, "layout",
244  FROM_UTF8(pLayout->getObjectName()),
245  std::set< const CCopasiObject * >());
246 
247  if (choice == QMessageBox::Ok)
248  removeRow((int) delRow);
249  }
250  }
251 
252  return true;
253 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54
#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)
virtual size_t getIndex(const CCopasiObject *pObject) const
bool CQLayoutsDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 181 of file CQLayoutsDM.cpp.

References CCopasiVector< T >::begin(), ListViews::DELETE, ListViews::LAYOUT, mpListOfLayouts, CQBaseDataModel::notifyGUI(), and pdelete.

182 {
183  if (rows <= 0) return true;
184 
185  if (mpListOfLayouts == NULL) return false;
186 
187  beginRemoveRows(QModelIndex(), position, position + rows - 1);
188 
189  std::vector< CLayout * > DeletedLayouts;
190  DeletedLayouts.resize(rows);
191 
192  std::vector< CLayout * >::iterator itDeletedLayout;
193  std::vector< CLayout * >::iterator endDeletedLayout = DeletedLayouts.end();
194 
196 
197  for (itDeletedLayout = DeletedLayouts.begin(); itDeletedLayout != endDeletedLayout; ++itDeletedLayout, ++itRow)
198  {
199  *itDeletedLayout = *itRow;
200  }
201 
202  for (itDeletedLayout = DeletedLayouts.begin(); itDeletedLayout != endDeletedLayout; ++itDeletedLayout)
203  {
204  std::string Key = (*itDeletedLayout)->getKey();
205 
206  pdelete(*itDeletedLayout);
207 
209  }
210 
211  endRemoveRows();
212 
213  return true;
214 }
#define pdelete(p)
Definition: copasi.h:215
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54
iterator begin()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
int CQLayoutsDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 24 of file CQLayoutsDM.cpp.

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

Referenced by clear(), data(), CQLayoutsWidget::deleteSelectedLayouts(), setData(), CQLayoutsWidget::showButtons(), and CQLayoutsWidget::slotDoubleClicked().

25 {
26  if (mpListOfLayouts == NULL) return 0;
27 
28  return (int) mpListOfLayouts->size();
29 }
virtual size_t size() const
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54
bool CQLayoutsDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 124 of file CQLayoutsDM.cpp.

References COL_NAME, COL_ROW_NUMBER, COL_SHOW, mpListOfLayouts, and rowCount().

125 {
126  if (mpListOfLayouts == NULL) return false;
127 
128  if (!index.isValid()) return false;
129 
130  if (index.row() >= rowCount()) return false;
131 
132  if (index.isValid() && role == Qt::EditRole)
133  {
134  switch (index.column())
135  {
136  case COL_ROW_NUMBER:
137  return false;
138  break;
139 
140  case COL_NAME:
141  return false;
142  break;
143 
144  case COL_SHOW:
145  return true;
146  break;
147 
148  default:
149  return false;
150  break;
151  }
152  }
153 
154  return true;
155 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQLayoutsDM.cpp:24
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54
#define COL_NAME
#define COL_SHOW
Definition: CQLayoutsDM.h:21
#define COL_ROW_NUMBER
void CQLayoutsDM::setListOfLayouts ( CListOfLayouts pListOfLayouts)

Definition at line 255 of file CQLayoutsDM.cpp.

References mpListOfLayouts.

Referenced by CQLayoutsWidget::enterProtected().

256 {
257  if (mpListOfLayouts != pListOfLayouts)
258  {
259  mpListOfLayouts = pListOfLayouts;
260  reset();
261  }
262 }
CListOfLayouts * mpListOfLayouts
Definition: CQLayoutsDM.h:54

Member Data Documentation

CListOfLayouts* CQLayoutsDM::mpListOfLayouts
private

Definition at line 54 of file CQLayoutsDM.h.

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


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