COPASI API  4.16.103
CQBaseDataModel.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQBaseDataModel.cpp,v $
3 // $Revision: 1.10 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/03/19 12:20:16 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "copasi.h"
20 #include "CQBaseDataModel.h"
21 
23  : QAbstractTableModel(parent)
24 
25 {}
26 
27 Qt::ItemFlags CQBaseDataModel::flags(const QModelIndex &index) const
28 {
29  if (!index.isValid())
30  return Qt::ItemIsEnabled;
31 
32  if (index.column() == COL_ROW_NUMBER)
33  return QAbstractItemModel::flags(index);
34  else
35  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
36 }
37 
39 {
40  return insertRows(rowCount() - 1, 1);
41 }
42 
43 bool CQBaseDataModel::removeRow(int position)
44 {
45  if (0 <= position && position < rowCount() && !isDefaultRow(index(position, 0)))
46  return removeRows(position, 1);
47  else
48  return false;
49 }
50 
52 {
53  return removeRows(0, rowCount() - 1);
54 }
55 
56 bool CQBaseDataModel::isDefaultRow(const QModelIndex& i) const
57 {
58  //Index has to be from this model and should be valid.
59  if ((i.model() != this) ||
60  !i.isValid())
61  {
62  return false;
63  }
64 
65  return (i.row() == rowCount() - 1);
66 }
67 
68 QString CQBaseDataModel::createNewName(const QString name, const int nameCol)
69 {
70  QString nname = name;
71  unsigned C_INT32 j, jmax = rowCount();
72 
73  for (unsigned C_INT32 i = 1;; ++i)
74  {
75  nname = name + "_" + QString::number(i);
76 
77  for (j = 0; j < jmax; ++j)
78  if (index(j, nameCol).data() == nname) break;
79 
80  if (j == jmax) break;
81  }
82 
83  return nname;
84 }
virtual bool clear()
#define C_INT32
Definition: copasi.h:90
virtual bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex())=0
bool removeRow(int position)
QString createNewName(const QString name, const int nameCol)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
CQBaseDataModel(QObject *parent=0)
virtual QVariant data(const QModelIndex &index, int role) const =0
virtual bool isDefaultRow(const QModelIndex &i) const
virtual bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex())=0
#define COL_ROW_NUMBER