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

#include <CQCreatorDM.h>

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

Public Member Functions

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

Constructor & Destructor Documentation

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

Definition at line 25 of file CQCreatorDM.cpp.

References mpMIRIAMInfo.

26  : CQBaseDataModel(parent)
27 
28 {
29  mpMIRIAMInfo = MIRIAMInfo;
30 }
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQCreatorDM.h:50
CQBaseDataModel(QObject *parent=0)

Member Function Documentation

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

Definition at line 36 of file CQCreatorDM.cpp.

References TOTAL_COLS_CREATORS.

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

Implements CQBaseDataModel.

Definition at line 41 of file CQCreatorDM.cpp.

References COL_EMAIL, COL_FAMILY_NAME, COL_GIVEN_NAME, COL_ORG, COL_ROW_NUMBER, FROM_UTF8, CMIRIAMInfo::getCreators(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, and rowCount().

Referenced by removeRows().

42 {
43  if (!index.isValid())
44  return QVariant();
45 
46  if (index.row() >= rowCount())
47  return QVariant();
48 
49  if (role == Qt::DisplayRole || role == Qt::EditRole)
50  {
51  if (isDefaultRow(index))
52  {
53  if (index.column() == COL_ROW_NUMBER)
54  return QVariant(QString(""));
55  else
56  return QVariant(QString(""));
57  }
58  else
59  {
60  switch (index.column())
61  {
62  case COL_ROW_NUMBER:
63  return QVariant(index.row() + 1);
64  case COL_FAMILY_NAME:
65  return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getFamilyName())));
66  case COL_GIVEN_NAME:
67  return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getGivenName())));
68  case COL_EMAIL:
69  return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getEmail())));
70  case COL_ORG:
71  return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getORG())));
72  }
73  }
74  }
75 
76  return QVariant();
77 }
const CCopasiVector< CCreator > & getCreators() const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
#define COL_FAMILY_NAME
Definition: CQCreatorDM.h:26
#define COL_EMAIL
Definition: CQCreatorDM.h:28
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQCreatorDM.h:50
#define COL_GIVEN_NAME
Definition: CQCreatorDM.h:27
virtual bool isDefaultRow(const QModelIndex &i) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQCreatorDM.cpp:32
#define COL_ORG
Definition: CQCreatorDM.h:29
#define COL_ROW_NUMBER
QVariant CQCreatorDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 79 of file CQCreatorDM.cpp.

References COL_EMAIL, COL_FAMILY_NAME, COL_GIVEN_NAME, COL_ORG, and COL_ROW_NUMBER.

81 {
82  if (role != Qt::DisplayRole)
83  return QVariant();
84 
85  if (orientation == Qt::Horizontal)
86  {
87  switch (section)
88  {
89  case COL_ROW_NUMBER:
90  return QVariant(QString("#"));
91  case COL_FAMILY_NAME:
92  return QVariant(QString("Family Name"));
93  case COL_GIVEN_NAME:
94  return QVariant(QString("Given Name"));
95  case COL_EMAIL:
96  return QVariant(QString("Email"));
97  case COL_ORG:
98  return QVariant(QString("Organization"));
99  default:
100  return QVariant();
101  }
102  }
103  else
104  return QString("%1").arg(section + 1);
105 }
#define COL_FAMILY_NAME
Definition: CQCreatorDM.h:26
#define COL_EMAIL
Definition: CQCreatorDM.h:28
#define COL_GIVEN_NAME
Definition: CQCreatorDM.h:27
#define COL_ORG
Definition: CQCreatorDM.h:29
#define COL_ROW_NUMBER
bool CQCreatorDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 144 of file CQCreatorDM.cpp.

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

145 {
146  beginInsertRows(QModelIndex(), position, position + rows - 1);
147 
148  for (int row = 0; row < rows; ++row)
149  {
151  }
152 
153  endInsertRows();
154 
156  return true;
157 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQCreatorDM.h:50
CCreator * createCreator(const std::string &objectName)
bool CQCreatorDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 177 of file CQCreatorDM.cpp.

References C_INVALID_INDEX, COL_FAMILY_NAME, COL_GIVEN_NAME, data(), CMIRIAMInfo::getCreators(), CQBaseDataModel::isDefaultRow(), mpMIRIAMInfo, CQMessageBox::question(), and CQBaseDataModel::removeRow().

Referenced by CQMiriamWidget::deleteSelectedAuthors().

178 {
179  if (rows.isEmpty())
180  return false;
181 
182 //Build the list of pointers to items to be deleted
183 //before actually deleting any item.
184  QList <CCreator *> pCreators;
185  QModelIndexList::const_iterator i;
186 
187  for (i = rows.begin(); i != rows.end(); ++i)
188  {
189  if (!isDefaultRow(*i) && mpMIRIAMInfo->getCreators()[(*i).row()])
190  pCreators.append(mpMIRIAMInfo->getCreators()[(*i).row()]);
191  }
192 
193  bool retVal = false, askEveryItem = true;
194  QMessageBox::StandardButton choice = QMessageBox::NoToAll;
195  QList <CCreator *>::const_iterator j;
196 
197  for (j = pCreators.begin(); j != pCreators.end(); ++j)
198  {
199  CCreator * pCreator = *j;
200 
201  size_t delRow =
202  mpMIRIAMInfo->getCreators().CCopasiVector< CCreator >::getIndex(pCreator);
203 
204  if (delRow != C_INVALID_INDEX)
205  {
206  if (askEveryItem)
207  {
208  QString givenName = data(this->index((int) delRow, COL_GIVEN_NAME), Qt::DisplayRole).toString();
209  QString familyName = data(this->index((int) delRow, COL_FAMILY_NAME), Qt::DisplayRole).toString();
210  QString msg = "Do you want to delete author '";
211 
212  if (!givenName.isNull())
213  {
214  msg.append(givenName);
215  }
216 
217  if (!familyName.isNull())
218  {
219  msg.append(" ");
220  msg.append(familyName);
221  }
222 
223  msg.append("'?");
224 
225  choice = CQMessageBox::question(NULL, tr("Confirm Delete"), msg,
226  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll,
227  QMessageBox::No);
228  }
229 
230  if (choice == QMessageBox::NoToAll)
231  {return retVal;}
232  else if (choice == QMessageBox::Yes)
233  {retVal = removeRow((int) delRow);}
234  else if (choice == QMessageBox::YesToAll)
235  {
236  askEveryItem = false;
237  retVal = removeRow((int) delRow);
238  }
239  }
240  }
241 
242  return true;
243 }
const CCopasiVector< CCreator > & getCreators() const
#define COL_FAMILY_NAME
Definition: CQCreatorDM.h:26
#define C_INVALID_INDEX
Definition: copasi.h:222
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQCreatorDM.h:50
bool removeRow(int position)
QVariant data(const QModelIndex &index, int role) const
Definition: CQCreatorDM.cpp:41
#define COL_GIVEN_NAME
Definition: CQCreatorDM.h:27
virtual bool isDefaultRow(const QModelIndex &i) const
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
bool CQCreatorDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 159 of file CQCreatorDM.cpp.

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

160 {
161  if (rows <= 0)
162  return true;
163 
164  beginRemoveRows(QModelIndex(), position, position + rows - 1);
165 
166  for (int row = 0; row < rows; ++row)
167  {
168  mpMIRIAMInfo->removeCreator(position);
169  }
170 
171  endRemoveRows();
172 
174  return true;
175 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQCreatorDM.h:50
bool removeCreator(int position)
int CQCreatorDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 32 of file CQCreatorDM.cpp.

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

Referenced by data().

33 {
34  return (int) mpMIRIAMInfo->getCreators().size() + 1;
35 }
const CCopasiVector< CCreator > & getCreators() const
virtual size_t size() const
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQCreatorDM.h:50
bool CQCreatorDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 107 of file CQCreatorDM.cpp.

References ListViews::CHANGE, COL_EMAIL, COL_FAMILY_NAME, COL_GIVEN_NAME, COL_ORG, CMIRIAMInfo::getCreators(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), ListViews::MIRIAM, mpMIRIAMInfo, CQBaseDataModel::notifyGUI(), and TO_UTF8.

109 {
110  if (index.isValid() && role == Qt::EditRole)
111  {
112  if (isDefaultRow(index))
113  {
114  if (index.data() != value)
115  insertRow();
116  else
117  return false;
118  }
119 
120  switch (index.column())
121  {
122  case COL_FAMILY_NAME:
123  mpMIRIAMInfo->getCreators()[index.row()]->setFamilyName(TO_UTF8(value.toString()));
124  break;
125  case COL_GIVEN_NAME:
126  mpMIRIAMInfo->getCreators()[index.row()]->setGivenName(TO_UTF8(value.toString()));
127  break;
128  case COL_EMAIL:
129  mpMIRIAMInfo->getCreators()[index.row()]->setEmail(TO_UTF8(value.toString()));
130  break;
131  case COL_ORG:
132  mpMIRIAMInfo->getCreators()[index.row()]->setORG(TO_UTF8(value.toString()));
133  break;
134  }
135 
136  emit dataChanged(index, index);
138  return true;
139  }
140 
141  return false;
142 }
const CCopasiVector< CCreator > & getCreators() const
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
#define COL_FAMILY_NAME
Definition: CQCreatorDM.h:26
#define COL_EMAIL
Definition: CQCreatorDM.h:28
CMIRIAMInfo * mpMIRIAMInfo
Definition: CQCreatorDM.h:50
#define COL_GIVEN_NAME
Definition: CQCreatorDM.h:27
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_ORG
Definition: CQCreatorDM.h:29

Member Data Documentation

CMIRIAMInfo* CQCreatorDM::mpMIRIAMInfo
protected

Definition at line 50 of file CQCreatorDM.h.

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


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