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

#include <CQEventsWidget.h>

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

Public Member Functions

 CQEventsWidget (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~CQEventsWidget ()
 
- 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 bool enterProtected ()
 
virtual void keyPressEvent (QKeyEvent *ev)
 

Private Member Functions

void deleteSelectedEvents ()
 
void updateDeleteBtns ()
 

Private Attributes

CQEventDMmpEventDM
 
CQSortFilterProxyModelmpProxyModel
 

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 CQEventsWidget.h.

Constructor & Destructor Documentation

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

Definition at line 33 of file CQEventsWidget.cpp.

References COL_ROW_NUMBER, dataChanged(), mpEventDM, mpProxyModel, CopasiWidget::protectedNotify(), and slotFilterChanged().

34  : CopasiWidget(parent, name)
35 {
36  setupUi(this);
37 
38  //Create Source Data Model.
39  mpEventDM = new CQEventDM(this);
40 
41  //Create the Proxy Model for sorting/filtering and set its properties.
43  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
44  mpProxyModel->setFilterKeyColumn(-1);
45 
46  mpTblEvents->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
47  mpTblEvents->verticalHeader()->hide();
48  mpTblEvents->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
49 
50  // Connect the table widget
51  connect(mpEventDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
52  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
53  connect(mpEventDM, 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 }
virtual void slotFilterChanged()
CQEventDM * mpEventDM
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
CQSortFilterProxyModel * mpProxyModel
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="")
#define COL_ROW_NUMBER
CQEventsWidget::~CQEventsWidget ( )

Definition at line 62 of file CQEventsWidget.cpp.

References mpEventDM, mpProxyModel, and pdelete.

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

Member Function Documentation

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

Definition at line 188 of file CQEventsWidget.cpp.

References updateDeleteBtns().

Referenced by CQEventsWidget().

190 {
191  mpTblEvents->resizeColumnsToContents();
193 }
void CQEventsWidget::deleteSelectedEvents ( )
private

Definition at line 83 of file CQEventsWidget.cpp.

References mpEventDM, mpProxyModel, CQEventDM::removeRows(), and CQEventDM::rowCount().

Referenced by slotBtnDeleteClicked().

84 {
85  const QItemSelectionModel * pSelectionModel = mpTblEvents->selectionModel();
86 
87  QModelIndexList mappedSelRows;
88  size_t i, imax = mpEventDM->rowCount();
89 
90  for (i = 0; i < imax; i++)
91  {
92  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
93  {
94  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
95  }
96  }
97 
98  if (mappedSelRows.empty())
99  {return;}
100 
101  mpEventDM->removeRows(mappedSelRows);
102 }
CQEventDM * mpEventDM
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQEventDM.cpp:27
CQSortFilterProxyModel * mpProxyModel
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
Definition: CQEventDM.cpp:277
bool CQEventsWidget::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 133 of file CQEventsWidget.cpp.

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

Referenced by update().

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

Definition at line 221 of file CQEventsWidget.cpp.

References CQEventDM::columnCount(), mpEventDM, 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 = mpTblEvents->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 < mpEventDM->columnCount(); ++x)
238  {
239  if (!mpTblEvents->isColumnHidden(x))
240  {
241  if (!str.isEmpty())
242  str += "\t";
243 
244  str += mpEventDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
245  }
246  }
247 
248  str += "\n";
249  }
250 
251  QApplication::clipboard()->setText(str);
252  }
253 }
CQEventDM * mpEventDM
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQEventDM.cpp:31
CQSortFilterProxyModel * mpProxyModel
virtual void slotBtnDeleteClicked()
bool CQEventsWidget::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 128 of file CQEventsWidget.cpp.

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

Definition at line 104 of file CQEventsWidget.cpp.

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

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

Definition at line 75 of file CQEventsWidget.cpp.

References deleteSelectedEvents(), and updateDeleteBtns().

Referenced by keyPressEvent().

76 {
77  if (mpTblEvents->hasFocus())
79 
81 }
void deleteSelectedEvents()
void CQEventsWidget::slotBtnNewClicked ( )
protectedvirtualslot

Definition at line 69 of file CQEventsWidget.cpp.

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

Referenced by slotDoubleClicked().

70 {
73 }
CQEventDM * mpEventDM
void CQEventsWidget::slotDoubleClicked ( const QModelIndex  proxyIndex)
protectedvirtualslot

Definition at line 195 of file CQEventsWidget.cpp.

References C_INVALID_INDEX, CCopasiRootContainer::getDatamodelList(), CModel::getEvents(), CCopasiObject::getKey(), CCopasiRootContainer::getKeyFactory(), CCopasiDataModel::getModel(), CQBaseDataModel::isDefaultRow(), mpEventDM, 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 (mpEventDM->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->getEvents()[index.row()]->getKey();
216 
217  if (CCopasiRootContainer::getKeyFactory()->get(key))
219 }
CQEventDM * mpEventDM
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual void slotBtnNewClicked()
CQSortFilterProxyModel * mpProxyModel
virtual const std::string & getKey() const
ListViews * mpListView
Definition: copasiWidget.h:62
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
static CKeyFactory * getKeyFactory()
Definition: CModel.h:50
virtual bool isDefaultRow(const QModelIndex &i) const
void CQEventsWidget::slotFilterChanged ( )
protectedvirtualslot

Definition at line 255 of file CQEventsWidget.cpp.

References mpProxyModel.

Referenced by CQEventsWidget().

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

Definition at line 182 of file CQEventsWidget.cpp.

References updateDeleteBtns().

Referenced by enterProtected().

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

Reimplemented from CopasiWidget.

Definition at line 118 of file CQEventsWidget.cpp.

References enterProtected(), and CopasiWidget::mIgnoreUpdates.

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

Definition at line 153 of file CQEventsWidget.cpp.

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

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

154 {
155  bool selected = false;
156 
157  QModelIndexList selRows = mpTblEvents->selectionModel()->selectedRows();
158 
159  if (selRows.size() == 0)
160  selected = false;
161  else
162  {
163  if (selRows.size() == 1)
164  {
165  if (mpEventDM->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 }
CQEventDM * mpEventDM
CQSortFilterProxyModel * mpProxyModel
virtual bool isDefaultRow(const QModelIndex &i) const

Member Data Documentation

CQEventDM* CQEventsWidget::mpEventDM
private
CQSortFilterProxyModel* CQEventsWidget::mpProxyModel
private

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