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

#include <CQCompartmentsWidget.h>

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

Public Member Functions

 CQCompartmentsWidget (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
virtual ~CQCompartmentsWidget ()
 
- Public Member Functions inherited from CopasiWidget
 CopasiWidget (QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
 
bool enter (const std::string &key)
 
CCopasiDataModelgetDataModel ()
 
bool getIgnoreUpdates ()
 
virtual void setFramework (int framework)
 
void setIgnoreUpdates (bool v)
 

Protected Slots

virtual void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 
virtual void slotBtnClearClicked ()
 
virtual void slotBtnDeleteClicked ()
 
virtual void slotBtnNewClicked ()
 
virtual void slotDoubleClicked (const QModelIndex proxyIndex)
 
virtual void slotFilterChanged ()
 
virtual void slotSelectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 
- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Protected Member Functions

virtual void keyPressEvent (QKeyEvent *ev)
 

Private Member Functions

void deleteSelectedCompartments ()
 
virtual bool enterProtected ()
 
void updateDeleteBtns ()
 

Private Attributes

CQCompartmentDMmpCompartmentDM
 
CQSortFilterProxyModelmpProxyModel
 
CQIndexComboDelegatempTypeDelegate
 

Additional Inherited Members

- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Detailed Description

Definition at line 30 of file CQCompartmentsWidget.h.

Constructor & Destructor Documentation

CQCompartmentsWidget::CQCompartmentsWidget ( QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 29 of file CQCompartmentsWidget.cpp.

References COL_ROW_NUMBER, COL_TYPE_COMPARTMENTS, dataChanged(), CQCompartmentDM::getTypes(), mpCompartmentDM, mpProxyModel, mpTypeDelegate, CopasiWidget::protectedNotify(), and slotFilterChanged().

30  : CopasiWidget(parent, name)
31 {
32  setupUi(this);
33 
34  //Create Source Data Model.
35  mpCompartmentDM = new CQCompartmentDM(this);
36 
37  //Create the Proxy Model for sorting/filtering and set its properties.
39  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
40  mpProxyModel->setFilterKeyColumn(-1);
41 
42  //Setting values for Types comboBox
44  mpTblCompartments->setItemDelegateForColumn(COL_TYPE_COMPARTMENTS, mpTypeDelegate);
45 
46  mpTblCompartments->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
47  mpTblCompartments->verticalHeader()->hide();
48  mpTblCompartments->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
49 
50  // Connect the table widget
51  connect(mpCompartmentDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
52  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
53  connect(mpCompartmentDM, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
54  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
55  connect(mpLEFilter, SIGNAL(textChanged(const QString &)),
56  this, SLOT(slotFilterChanged()));
57 }
#define COL_TYPE_COMPARTMENTS
CQIndexComboDelegate * mpTypeDelegate
CQCompartmentDM * mpCompartmentDM
const QStringList & getTypes()
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CQSortFilterProxyModel * mpProxyModel
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
#define COL_ROW_NUMBER
CQCompartmentsWidget::~CQCompartmentsWidget ( )
virtual

Definition at line 62 of file CQCompartmentsWidget.cpp.

References mpCompartmentDM, mpProxyModel, mpTypeDelegate, and pdelete.

63 {
67  // no need to delete child widgets, Qt does it all for us
68 }
#define pdelete(p)
Definition: copasi.h:215
CQIndexComboDelegate * mpTypeDelegate
CQCompartmentDM * mpCompartmentDM
CQSortFilterProxyModel * mpProxyModel

Member Function Documentation

void CQCompartmentsWidget::dataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
)
protectedvirtualslot

Definition at line 188 of file CQCompartmentsWidget.cpp.

References updateDeleteBtns().

Referenced by CQCompartmentsWidget().

190 {
191  mpTblCompartments->resizeColumnsToContents();
193 }
void CQCompartmentsWidget::deleteSelectedCompartments ( )
private

Definition at line 84 of file CQCompartmentsWidget.cpp.

References mpCompartmentDM, mpProxyModel, CQCompartmentDM::removeRows(), and CQCompartmentDM::rowCount().

Referenced by slotBtnDeleteClicked().

85 {
86  const QItemSelectionModel * pSelectionModel = mpTblCompartments->selectionModel();
87 
88  QModelIndexList mappedSelRows;
89  size_t i, imax = mpCompartmentDM->rowCount();
90 
91  for (i = 0; i < imax; i++)
92  {
93  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
94  {
95  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
96  }
97  }
98 
99  if (mappedSelRows.empty())
100  {return;}
101 
102  mpCompartmentDM->removeRows(mappedSelRows);
103 }
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
CQCompartmentDM * mpCompartmentDM
CQSortFilterProxyModel * mpProxyModel
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
bool CQCompartmentsWidget::enterProtected ( )
privatevirtual

Reimplemented from CopasiWidget.

Definition at line 133 of file CQCompartmentsWidget.cpp.

References mpCompartmentDM, mpProxyModel, slotSelectionChanged(), and updateDeleteBtns().

Referenced by update().

134 {
135  if (mpTblCompartments->selectionModel() != NULL)
136  {
137  disconnect(mpTblCompartments->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
138  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
139  }
140 
141  mpProxyModel->setSourceModel(mpCompartmentDM);
142  //Set Model for the TableView
143  mpTblCompartments->setModel(NULL);
144  mpTblCompartments->setModel(mpProxyModel);
145  connect(mpTblCompartments->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
146  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
148  mpTblCompartments->resizeColumnsToContents();
149 
150  return true;
151 }
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
CQCompartmentDM * mpCompartmentDM
CQSortFilterProxyModel * mpProxyModel
void CQCompartmentsWidget::keyPressEvent ( QKeyEvent *  ev)
protectedvirtual

Definition at line 221 of file CQCompartmentsWidget.cpp.

References CQCompartmentDM::columnCount(), mpCompartmentDM, mpProxyModel, and slotBtnDeleteClicked().

222 {
223  if (ev->key() == Qt::Key_Delete)
225  else if (ev->key() == Qt::Key_C && (ev->modifiers() & Qt::ControlModifier))
226  {
227  QModelIndexList selRows = mpTblCompartments->selectionModel()->selectedRows(0);
228 
229  if (selRows.empty())
230  {return;}
231 
232  QString str;
233  QModelIndexList::const_iterator i;
234 
235  for (i = selRows.begin(); i != selRows.end(); ++i)
236  {
237  for (int x = 0; x < mpCompartmentDM->columnCount(); ++x)
238  {
239  if (!mpTblCompartments->isColumnHidden(x))
240  {
241  if (!str.isEmpty())
242  str += "\t";
243 
244  str += mpCompartmentDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
245  }
246  }
247 
248  str += "\n";
249  }
250 
251  QApplication::clipboard()->setText(str);
252  }
253 }
CQCompartmentDM * mpCompartmentDM
virtual void slotBtnDeleteClicked()
CQSortFilterProxyModel * mpProxyModel
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
bool CQCompartmentsWidget::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 128 of file CQCompartmentsWidget.cpp.

129 {
130  return true;
131 }
void CQCompartmentsWidget::slotBtnClearClicked ( )
protectedvirtualslot

Definition at line 105 of file CQCompartmentsWidget.cpp.

References CQBaseDataModel::clear(), mpCompartmentDM, CQMessageBox::question(), and updateDeleteBtns().

106 {
107  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Compartments?",
108  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
109 
110  if (ret == QMessageBox::Yes)
111  {
113  }
114 
116 }
CQCompartmentDM * mpCompartmentDM
virtual bool clear()
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void CQCompartmentsWidget::slotBtnDeleteClicked ( )
protectedvirtualslot

Definition at line 76 of file CQCompartmentsWidget.cpp.

References deleteSelectedCompartments(), and updateDeleteBtns().

Referenced by keyPressEvent().

77 {
78  if (mpTblCompartments->hasFocus())
80 
82 }
void CQCompartmentsWidget::slotBtnNewClicked ( )
protectedvirtualslot
void CQCompartmentsWidget::slotDoubleClicked ( const QModelIndex  proxyIndex)
protectedvirtualslot

Definition at line 195 of file CQCompartmentsWidget.cpp.

References C_INVALID_INDEX, CModel::getCompartments(), CCopasiRootContainer::getDatamodelList(), CCopasiObject::getKey(), CCopasiRootContainer::getKeyFactory(), CCopasiDataModel::getModel(), CQBaseDataModel::isDefaultRow(), mpCompartmentDM, CopasiWidget::mpListView, mpProxyModel, slotBtnNewClicked(), and ListViews::switchToOtherWidget().

196 {
197  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
198 
199  if (index.row() < 0)
200  return;
201 
202  if (mpCompartmentDM->isDefaultRow(index))
203  {
205  }
206 
207  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
209  assert(pDataModel != NULL);
210  CModel * pModel = pDataModel->getModel();
211 
212  if (pModel == NULL)
213  return;
214 
215  std::string key = pModel->getCompartments()[index.row()]->getKey();
216 
217  if (CCopasiRootContainer::getKeyFactory()->get(key))
219 }
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
CQCompartmentDM * mpCompartmentDM
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual const std::string & getKey() const
ListViews * mpListView
Definition: copasiWidget.h:62
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CQSortFilterProxyModel * mpProxyModel
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
static CKeyFactory * getKeyFactory()
Definition: CModel.h:50
virtual void slotBtnNewClicked()
virtual bool isDefaultRow(const QModelIndex &i) const
void CQCompartmentsWidget::slotFilterChanged ( )
protectedvirtualslot

Definition at line 255 of file CQCompartmentsWidget.cpp.

References mpProxyModel.

Referenced by CQCompartmentsWidget().

256 {
257  QRegExp regExp(mpLEFilter->text() + "|New Compartment", Qt::CaseInsensitive, QRegExp::RegExp);
258  mpProxyModel->setFilterRegExp(regExp);
259 }
CQSortFilterProxyModel * mpProxyModel
void CQCompartmentsWidget::slotSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
protectedvirtualslot

Definition at line 182 of file CQCompartmentsWidget.cpp.

References updateDeleteBtns().

Referenced by enterProtected().

184 {
186 }
bool CQCompartmentsWidget::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Reimplemented from CopasiWidget.

Definition at line 118 of file CQCompartmentsWidget.cpp.

References enterProtected(), and CopasiWidget::mIgnoreUpdates.

119 {
120  if (!mIgnoreUpdates)
121  {
122  enterProtected();
123  }
124 
125  return true;
126 }
bool mIgnoreUpdates
Definition: copasiWidget.h:67
void CQCompartmentsWidget::updateDeleteBtns ( )
private

Definition at line 153 of file CQCompartmentsWidget.cpp.

References CQBaseDataModel::isDefaultRow(), mpCompartmentDM, and mpProxyModel.

Referenced by dataChanged(), enterProtected(), slotBtnClearClicked(), slotBtnDeleteClicked(), slotBtnNewClicked(), and slotSelectionChanged().

154 {
155  bool selected = false;
156 
157  QModelIndexList selRows = mpTblCompartments->selectionModel()->selectedRows();
158 
159  if (selRows.size() == 0)
160  selected = false;
161  else
162  {
163  if (selRows.size() == 1)
164  {
165  if (mpCompartmentDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
166  selected = false;
167  else
168  selected = true;
169  }
170  else
171  selected = true;
172  }
173 
174  mpBtnDelete->setEnabled(selected);
175 
176  if (mpProxyModel->rowCount() - 1)
177  mpBtnClear->setEnabled(true);
178  else
179  mpBtnClear->setEnabled(false);
180 }
CQCompartmentDM * mpCompartmentDM
CQSortFilterProxyModel * mpProxyModel
virtual bool isDefaultRow(const QModelIndex &i) const

Member Data Documentation

CQCompartmentDM* CQCompartmentsWidget::mpCompartmentDM
private
CQSortFilterProxyModel* CQCompartmentsWidget::mpProxyModel
private
CQIndexComboDelegate* CQCompartmentsWidget::mpTypeDelegate
private

Definition at line 44 of file CQCompartmentsWidget.h.

Referenced by CQCompartmentsWidget(), and ~CQCompartmentsWidget().


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