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

#include <CQFunctionsWidget.h>

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

Public Member Functions

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

Private Attributes

CQFunctionDMmpFunctionDM
 
CQSortFilterProxyModelmpProxyModel
 

Additional Inherited Members

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

Detailed Description

Definition at line 29 of file CQFunctionsWidget.h.

Constructor & Destructor Documentation

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

Definition at line 31 of file CQFunctionsWidget.cpp.

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

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

Definition at line 60 of file CQFunctionsWidget.cpp.

References mpFunctionDM, mpProxyModel, and pdelete.

61 {
64  // no need to delete child widgets, Qt does it all for us
65 }
#define pdelete(p)
Definition: copasi.h:215
CQFunctionDM * mpFunctionDM
CQSortFilterProxyModel * mpProxyModel

Member Function Documentation

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

Definition at line 186 of file CQFunctionsWidget.cpp.

References updateDeleteBtns().

Referenced by CQFunctionsWidget().

188 {
189  mpTblFunctions->resizeColumnsToContents();
191 }
void CQFunctionsWidget::deleteSelectedFunctions ( )
private

Definition at line 81 of file CQFunctionsWidget.cpp.

References mpFunctionDM, mpProxyModel, CQFunctionDM::removeRows(), and CQFunctionDM::rowCount().

Referenced by slotBtnDeleteClicked().

82 {
83  const QItemSelectionModel * pSelectionModel = mpTblFunctions->selectionModel();
84 
85  QModelIndexList mappedSelRows;
86  size_t i, imax = mpFunctionDM->rowCount();
87 
88  for (i = 0; i < imax; i++)
89  {
90  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
91  {
92  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
93  }
94  }
95 
96  if (mappedSelRows.empty())
97  {return;}
98 
99  mpFunctionDM->removeRows(mappedSelRows);
100 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
CQFunctionDM * mpFunctionDM
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
CQSortFilterProxyModel * mpProxyModel
bool CQFunctionsWidget::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 131 of file CQFunctionsWidget.cpp.

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

Referenced by update().

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

Definition at line 211 of file CQFunctionsWidget.cpp.

References CQFunctionDM::columnCount(), mpFunctionDM, mpProxyModel, and slotBtnDeleteClicked().

212 {
213  if (ev->key() == Qt::Key_Delete)
215  else if (ev->key() == Qt::Key_C && (ev->modifiers() & Qt::ControlModifier))
216  {
217  QModelIndexList selRows = mpTblFunctions->selectionModel()->selectedRows(0);
218 
219  if (selRows.empty())
220  {return;}
221 
222  QString str;
223  QModelIndexList::const_iterator i;
224 
225  for (i = selRows.begin(); i != selRows.end(); ++i)
226  {
227  for (int x = 0; x < mpFunctionDM->columnCount(); ++x)
228  {
229  if (!mpTblFunctions->isColumnHidden(x))
230  {
231  if (!str.isEmpty())
232  str += "\t";
233 
234  str += mpFunctionDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
235  }
236  }
237 
238  str += "\n";
239  }
240 
241  QApplication::clipboard()->setText(str);
242  }
243 }
CQFunctionDM * mpFunctionDM
virtual void slotBtnDeleteClicked()
CQSortFilterProxyModel * mpProxyModel
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
bool CQFunctionsWidget::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 126 of file CQFunctionsWidget.cpp.

127 {
128  return true;
129 }
void CQFunctionsWidget::slotBtnClearClicked ( )
protectedvirtualslot

Definition at line 102 of file CQFunctionsWidget.cpp.

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

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

Definition at line 73 of file CQFunctionsWidget.cpp.

References deleteSelectedFunctions(), and updateDeleteBtns().

Referenced by keyPressEvent().

74 {
75  if (mpTblFunctions->hasFocus())
77 
79 }
void CQFunctionsWidget::slotBtnNewClicked ( )
protectedvirtualslot

Definition at line 67 of file CQFunctionsWidget.cpp.

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

Referenced by slotDoubleClicked().

68 {
71 }
CQFunctionDM * mpFunctionDM
void CQFunctionsWidget::slotDoubleClicked ( const QModelIndex  proxyIndex)
protectedvirtualslot

Definition at line 193 of file CQFunctionsWidget.cpp.

References C_INVALID_INDEX, CCopasiRootContainer::getFunctionList(), CCopasiObject::getKey(), CCopasiRootContainer::getKeyFactory(), CQBaseDataModel::isDefaultRow(), CFunctionDB::loadedFunctions(), mpFunctionDM, CopasiWidget::mpListView, mpProxyModel, slotBtnNewClicked(), and ListViews::switchToOtherWidget().

194 {
195  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
196 
197  if (index.row() < 0)
198  return;
199 
200  if (mpFunctionDM->isDefaultRow(index))
201  {
203  }
204 
205  std::string key = CCopasiRootContainer::getFunctionList()->loadedFunctions()[index.row()]->getKey();
206 
207  if (CCopasiRootContainer::getKeyFactory()->get(key))
209 }
CCopasiVectorN< CFunction > & loadedFunctions()
CQFunctionDM * mpFunctionDM
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual const std::string & getKey() const
CQSortFilterProxyModel * mpProxyModel
ListViews * mpListView
Definition: copasiWidget.h:62
static CFunctionDB * getFunctionList()
static CKeyFactory * getKeyFactory()
virtual void slotBtnNewClicked()
virtual bool isDefaultRow(const QModelIndex &i) const
void CQFunctionsWidget::slotFilterChanged ( )
protectedvirtualslot

Definition at line 245 of file CQFunctionsWidget.cpp.

References mpProxyModel.

Referenced by CQFunctionsWidget().

246 {
247  QRegExp regExp(mpLEFilter->text() + "|New Function", Qt::CaseInsensitive, QRegExp::RegExp);
248  mpProxyModel->setFilterRegExp(regExp);
249 }
CQSortFilterProxyModel * mpProxyModel
void CQFunctionsWidget::slotSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
protectedvirtualslot

Definition at line 180 of file CQFunctionsWidget.cpp.

References updateDeleteBtns().

Referenced by enterProtected().

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

Reimplemented from CopasiWidget.

Definition at line 116 of file CQFunctionsWidget.cpp.

References enterProtected(), and CopasiWidget::mIgnoreUpdates.

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

Definition at line 151 of file CQFunctionsWidget.cpp.

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

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

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

Member Data Documentation

CQFunctionDM* CQFunctionsWidget::mpFunctionDM
private
CQSortFilterProxyModel* CQFunctionsWidget::mpProxyModel
private

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