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

#include <CQPlotsWidget.h>

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

Public Member Functions

 CQPlotsWidget (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual void setFramework (int framework)
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~CQPlotsWidget ()
 
- 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 ()
 
void setIgnoreUpdates (bool v)
 

Protected Slots

virtual void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 
virtual void slotBtnActivateAllClicked ()
 
virtual void slotBtnClearClicked ()
 
virtual void slotBtnDeactivateAllClicked ()
 
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 bool enterProtected ()
 
virtual void keyPressEvent (QKeyEvent *ev)
 

Private Member Functions

void deleteSelectedPlots ()
 
void updateDeleteBtns ()
 

Private Attributes

CQPlotDMmpPlotDM
 
CQSortFilterProxyModelmpProxyModel
 

Additional Inherited Members

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

Detailed Description

Definition at line 21 of file CQPlotsWidget.h.

Constructor & Destructor Documentation

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

Definition at line 32 of file CQPlotsWidget.cpp.

References COL_ROW_NUMBER, dataChanged(), CopasiWidget::mFramework, mpPlotDM, mpProxyModel, CopasiWidget::protectedNotify(), setFramework(), slotBtnActivateAllClicked(), slotBtnDeactivateAllClicked(), and slotFilterChanged().

33  : CopasiWidget(parent, name)
34 {
35  setupUi(this);
36 
37  //Create Source Data Model.
38  mpPlotDM = new CQPlotDM(this);
39 
40  //Create the Proxy Model for sorting/filtering and set its properties.
42  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
43  mpProxyModel->setFilterKeyColumn(-1);
44 
45  mpTblPlots->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
46  mpTblPlots->verticalHeader()->hide();
47  mpTblPlots->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
48 
50 
51  // Connect the table widget
52  connect(mpPlotDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
53  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
54  connect(mpPlotDM, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
55  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
56  connect(mpLEFilter, SIGNAL(textChanged(const QString &)),
57  this, SLOT(slotFilterChanged()));
58  connect(mpBtnActivateAll, SIGNAL(pressed()), this, SLOT(slotBtnActivateAllClicked()));
59  connect(mpBtnDeactivateAll, SIGNAL(pressed()), this, SLOT(slotBtnDeactivateAllClicked()));
60 }
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
virtual void slotFilterChanged()
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
virtual void slotBtnActivateAllClicked()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual void setFramework(int framework)
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
virtual void slotBtnDeactivateAllClicked()
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
#define COL_ROW_NUMBER
CQPlotsWidget::~CQPlotsWidget ( )

Definition at line 65 of file CQPlotsWidget.cpp.

References mpPlotDM, mpProxyModel, and pdelete.

66 {
69  // no need to delete child widgets, Qt does it all for us
70 }
#define pdelete(p)
Definition: copasi.h:215
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34

Member Function Documentation

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

Definition at line 226 of file CQPlotsWidget.cpp.

References CopasiWidget::mFramework, setFramework(), and updateDeleteBtns().

Referenced by CQPlotsWidget().

228 {
229  mpTblPlots->resizeColumnsToContents();
232 }
void updateDeleteBtns()
virtual void setFramework(int framework)
void CQPlotsWidget::deleteSelectedPlots ( )
private

Definition at line 120 of file CQPlotsWidget.cpp.

References mpPlotDM, mpProxyModel, CQPlotDM::removeRows(), and CQPlotDM::rowCount().

Referenced by slotBtnDeleteClicked().

121 {
122  const QItemSelectionModel * pSelectionModel = mpTblPlots->selectionModel();
123 
124  QModelIndexList mappedSelRows;
125  size_t i, imax = mpPlotDM->rowCount();
126 
127  for (i = 0; i < imax; i++)
128  {
129  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
130  {
131  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
132  }
133  }
134 
135  if (mappedSelRows.empty())
136  {return;}
137 
138  mpPlotDM->removeRows(mappedSelRows);
139 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQPlotDM.cpp:28
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
Definition: CQPlotDM.cpp:242
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
bool CQPlotsWidget::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 170 of file CQPlotsWidget.cpp.

References CopasiWidget::mFramework, mpPlotDM, mpProxyModel, setFramework(), slotSelectionChanged(), and updateDeleteBtns().

Referenced by update().

171 {
172  if (mpTblPlots->selectionModel() != NULL)
173  {
174  disconnect(mpTblPlots->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
175  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
176  }
177 
178  mpProxyModel->setSourceModel(mpPlotDM);
179  //Set Model for the TableView
180  mpTblPlots->setModel(NULL);
181  mpTblPlots->setModel(mpProxyModel);
182  connect(mpTblPlots->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
183  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
185  mpTblPlots->resizeColumnsToContents();
187 
188  return true;
189 }
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
void updateDeleteBtns()
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
virtual void setFramework(int framework)
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
void CQPlotsWidget::keyPressEvent ( QKeyEvent *  ev)
protectedvirtual

Definition at line 260 of file CQPlotsWidget.cpp.

References CQPlotDM::columnCount(), mpPlotDM, mpProxyModel, and slotBtnDeleteClicked().

261 {
262  if (ev->key() == Qt::Key_Delete)
264  else if (ev->key() == Qt::Key_C &&
265  (ev->modifiers() & Qt::ControlModifier))
266  {
267  QModelIndexList selRows = mpTblPlots->selectionModel()->selectedRows(0);
268 
269  if (selRows.empty())
270  {return;}
271 
272  QString str;
273  QModelIndexList::const_iterator i;
274 
275  for (i = selRows.begin(); i != selRows.end(); ++i)
276  {
277  for (int x = 0; x < mpPlotDM->columnCount(); ++x)
278  {
279  if (!mpTblPlots->isColumnHidden(x))
280  {
281  if (!str.isEmpty())
282  str += "\t";
283 
284  str += mpPlotDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
285  }
286  }
287 
288  str += "\n";
289  }
290 
291  QApplication::clipboard()->setText(str);
292  }
293 }
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
virtual void slotBtnDeleteClicked()
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQPlotDM.cpp:32
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
bool CQPlotsWidget::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 165 of file CQPlotsWidget.cpp.

166 {
167  return true;
168 }
void CQPlotsWidget::setFramework ( int  framework)
virtual

Reimplemented from CopasiWidget.

Definition at line 301 of file CQPlotsWidget.cpp.

References CopasiWidget::setFramework().

Referenced by CQPlotsWidget(), dataChanged(), and enterProtected().

302 {
303  CopasiWidget::setFramework(framework);
304 }
virtual void setFramework(int framework)
void CQPlotsWidget::slotBtnActivateAllClicked ( )
protectedvirtualslot

Definition at line 72 of file CQPlotsWidget.cpp.

References CCopasiRootContainer::getDatamodelList(), CCopasiDataModel::getModel(), CCopasiDataModel::getPlotDefinitionList(), CPlotSpecification::setActive(), and CCopasiVector< T >::size().

Referenced by CQPlotsWidget().

73 {
75  assert(pDataModel != NULL);
76 
77  if (!pDataModel->getModel())
78  return;
79 
80  for (size_t i = 0; i < pDataModel->getPlotDefinitionList()->size(); i++)
81  {
82  CPlotSpecification *pPS = static_cast<CPlotSpecification *>(pDataModel->getPlotDefinitionList()->operator[](i));
83  pPS->setActive(true);
84  }
85 
86  mpTblPlots->doItemsLayout();
87 }
virtual size_t size() const
void setActive(const bool &active)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const COutputDefinitionVector * getPlotDefinitionList() const
void CQPlotsWidget::slotBtnClearClicked ( )
protectedvirtualslot

Definition at line 141 of file CQPlotsWidget.cpp.

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

142 {
143 
144  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Plots?",
145  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
146 
147  if (ret == QMessageBox::Yes)
148  {
149  mpPlotDM->clear();
150  }
151 
153 }
void updateDeleteBtns()
virtual bool clear()
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void CQPlotsWidget::slotBtnDeactivateAllClicked ( )
protectedvirtualslot

Definition at line 89 of file CQPlotsWidget.cpp.

References CCopasiRootContainer::getDatamodelList(), CCopasiDataModel::getModel(), CCopasiDataModel::getPlotDefinitionList(), CPlotSpecification::setActive(), and CCopasiVector< T >::size().

Referenced by CQPlotsWidget().

90 {
92  assert(pDataModel != NULL);
93 
94  if (!pDataModel->getModel())
95  return;
96 
97  for (size_t i = 0; i < pDataModel->getPlotDefinitionList()->size(); i++)
98  {
99  CPlotSpecification *pPS = static_cast<CPlotSpecification *>(pDataModel->getPlotDefinitionList()->operator[](i));
100  pPS->setActive(false);
101  }
102 
103  mpTblPlots->doItemsLayout();
104 }
virtual size_t size() const
void setActive(const bool &active)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const COutputDefinitionVector * getPlotDefinitionList() const
void CQPlotsWidget::slotBtnDeleteClicked ( )
protectedvirtualslot

Definition at line 112 of file CQPlotsWidget.cpp.

References deleteSelectedPlots(), and updateDeleteBtns().

Referenced by keyPressEvent().

113 {
114  if (mpTblPlots->hasFocus())
116 
118 }
void updateDeleteBtns()
void deleteSelectedPlots()
void CQPlotsWidget::slotBtnNewClicked ( )
protectedvirtualslot

Definition at line 106 of file CQPlotsWidget.cpp.

References CQBaseDataModel::insertRow(), mpPlotDM, and updateDeleteBtns().

Referenced by slotDoubleClicked().

107 {
108  mpPlotDM->insertRow();
110 }
void updateDeleteBtns()
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
void CQPlotsWidget::slotDoubleClicked ( const QModelIndex  proxyIndex)
protectedvirtualslot

Definition at line 234 of file CQPlotsWidget.cpp.

References C_INVALID_INDEX, CKeyFactory::get(), CCopasiRootContainer::getDatamodelList(), CCopasiRootContainer::getKeyFactory(), CCopasiDataModel::getModel(), CCopasiDataModel::getPlotDefinitionList(), CQBaseDataModel::isDefaultRow(), CopasiWidget::mpListView, mpPlotDM, mpProxyModel, slotBtnNewClicked(), and ListViews::switchToOtherWidget().

235 {
236  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
237 
238  if (index.row() < 0)
239  return;
240 
241  if (mpPlotDM->isDefaultRow(index))
242  {
244  }
245 
246  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
248  assert(pDataModel != NULL);
249 
250  if (!pDataModel->getModel())
251  return;
252 
253  CPlotSpecification *pPS = static_cast<CPlotSpecification *>(pDataModel->getPlotDefinitionList()->operator[](index.row()));
254  const std::string key = static_cast<CCopasiParameter *>(pPS)->getKey();
255 
258 }
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
CCopasiObject * get(const std::string &key)
#define C_INVALID_INDEX
Definition: copasi.h:222
ListViews * mpListView
Definition: copasiWidget.h:62
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
static CKeyFactory * getKeyFactory()
const COutputDefinitionVector * getPlotDefinitionList() const
virtual bool isDefaultRow(const QModelIndex &i) const
virtual void slotBtnNewClicked()
void CQPlotsWidget::slotFilterChanged ( )
protectedvirtualslot

Definition at line 295 of file CQPlotsWidget.cpp.

References mpProxyModel.

Referenced by CQPlotsWidget().

296 {
297  QRegExp regExp(mpLEFilter->text() + "|New Plot", Qt::CaseInsensitive, QRegExp::RegExp);
298  mpProxyModel->setFilterRegExp(regExp);
299 }
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
void CQPlotsWidget::slotSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
protectedvirtualslot

Definition at line 220 of file CQPlotsWidget.cpp.

References updateDeleteBtns().

Referenced by enterProtected().

222 {
224 }
void updateDeleteBtns()
bool CQPlotsWidget::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Reimplemented from CopasiWidget.

Definition at line 155 of file CQPlotsWidget.cpp.

References enterProtected(), and CopasiWidget::mIgnoreUpdates.

156 {
157  if (!mIgnoreUpdates)
158  {
159  enterProtected();
160  }
161 
162  return true;
163 }
bool mIgnoreUpdates
Definition: copasiWidget.h:67
virtual bool enterProtected()
void CQPlotsWidget::updateDeleteBtns ( )
private

Definition at line 191 of file CQPlotsWidget.cpp.

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

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

192 {
193  bool selected = false;
194 
195  QModelIndexList selRows = mpTblPlots->selectionModel()->selectedRows();
196 
197  if (selRows.size() == 0)
198  selected = false;
199  else
200  {
201  if (selRows.size() == 1)
202  {
203  if (mpPlotDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
204  selected = false;
205  else
206  selected = true;
207  }
208  else
209  selected = true;
210  }
211 
212  mpBtnDelete->setEnabled(selected);
213 
214  if (mpProxyModel->rowCount() - 1)
215  mpBtnClear->setEnabled(true);
216  else
217  mpBtnClear->setEnabled(false);
218 }
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
virtual bool isDefaultRow(const QModelIndex &i) const

Member Data Documentation

CQPlotDM* CQPlotsWidget::mpPlotDM
private
CQSortFilterProxyModel* CQPlotsWidget::mpProxyModel
private

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