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

#include <CQComboDelegate.h>

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

Signals

void currentIndexChanged (int, int)
 

Public Member Functions

 CQComboDelegate (const QStringList *pComboItems, QObject *parent=NULL, bool commitOnSelect=true)
 
virtual QWidget * createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
const QStringList * getItems (int row) const
 
bool isCommitOnSelect () const
 
void setCommitOnSelect (bool commitOnSelect)
 
virtual void setEditorData (QWidget *editor, const QModelIndex &index) const
 
void setItems (int row, const QStringList *pComboItems)
 
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
 
virtual void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
virtual ~CQComboDelegate ()
 

Protected Slots

void slotCurrentIndexChanged (int index)
 
void slotEditorDeleted (QObject *pObject)
 

Private Attributes

bool mCommitOnSelect
 
QMap< QWidget *, QModelIndex > mEditorToIndex
 
const QStringList * mpComboItems
 
QMap< int, const QStringList * > mRowToItems
 

Detailed Description

Definition at line 16 of file CQComboDelegate.h.

Constructor & Destructor Documentation

CQComboDelegate::CQComboDelegate ( const QStringList *  pComboItems,
QObject *  parent = NULL,
bool  commitOnSelect = true 
)

Definition at line 18 of file CQComboDelegate.cpp.

18  :
19  QItemDelegate(parent),
20  mpComboItems(pComboItems),
22  mRowToItems(),
23  mCommitOnSelect(commitOnSelect)
24 {}
const QStringList * mpComboItems
QMap< QWidget *, QModelIndex > mEditorToIndex
QMap< int, const QStringList * > mRowToItems
CQComboDelegate::~CQComboDelegate ( )
virtual

Definition at line 26 of file CQComboDelegate.cpp.

27 {}

Member Function Documentation

QWidget * CQComboDelegate::createEditor ( QWidget *  parent,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
virtual

Definition at line 29 of file CQComboDelegate.cpp.

References currentIndexChanged(), getItems(), mEditorToIndex, slotCurrentIndexChanged(), and slotEditorDeleted().

32 {
33  QModelIndex SourceIndex = index;
34  const QAbstractItemModel *pModel = index.model();
35 
36  while (pModel->inherits("QSortFilterProxyModel"))
37  {
38  SourceIndex = static_cast< const QSortFilterProxyModel *>(pModel)->mapToSource(index);
39  pModel = SourceIndex.model();
40  }
41 
42  QComboBox *pEditor = new QComboBox(parent);
43 
44  if (getItems(SourceIndex.row()) != NULL)
45  {
46  pEditor->addItems(*getItems(SourceIndex.row()));
47  }
48 
49  mEditorToIndex[pEditor] = SourceIndex;
50 
51  connect(pEditor, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentIndexChanged(int)));
52  connect(pEditor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDeleted(QObject *)));
53 
54  return pEditor;
55 }
QMap< QWidget *, QModelIndex > mEditorToIndex
void currentIndexChanged(int, int)
const QStringList * getItems(int row) const
void slotEditorDeleted(QObject *pObject)
void slotCurrentIndexChanged(int index)
void CQComboDelegate::currentIndexChanged ( int  ,
int   
)
signal
const QStringList * CQComboDelegate::getItems ( int  row) const

Definition at line 87 of file CQComboDelegate.cpp.

References mpComboItems, and mRowToItems.

Referenced by createEditor(), and ParameterTable::slotCellChanged().

88 {
89  if (mpComboItems != NULL)
90  {
91  return mpComboItems;
92  }
93 
94  QMap< int, const QStringList * >::const_iterator found = mRowToItems.find(row);
95 
96  if (found != mRowToItems.end()) // OK to return found.value() = NULL
97  {
98  return found.value();
99  }
100 
101  return NULL;
102 }
const QStringList * mpComboItems
QMap< int, const QStringList * > mRowToItems
bool CQComboDelegate::isCommitOnSelect ( ) const

Definition at line 128 of file CQComboDelegate.cpp.

References mCommitOnSelect.

129 {
130  return mCommitOnSelect;
131 }
void CQComboDelegate::setCommitOnSelect ( bool  commitOnSelect)

Definition at line 134 of file CQComboDelegate.cpp.

References mCommitOnSelect.

135 {
136  mCommitOnSelect = commitOnSelect;
137 }
void CQComboDelegate::setEditorData ( QWidget *  editor,
const QModelIndex &  index 
) const
virtual

Definition at line 57 of file CQComboDelegate.cpp.

59 {
60  QString value = index.model()->data(index, Qt::DisplayRole).toString();
61  QComboBox *comboBox = static_cast<QComboBox*>(editor);
62 
63  comboBox->blockSignals(true);
64  comboBox->setCurrentIndex(comboBox->findText(value));
65  comboBox->blockSignals(false);
66 }
void CQComboDelegate::setItems ( int  row,
const QStringList *  pComboItems 
)

Definition at line 82 of file CQComboDelegate.cpp.

References mRowToItems.

Referenced by CQExperimentData::setTypeItems(), and ParameterTable::updateTable().

83 {
84  mRowToItems[row] = pComboItems;
85 }
QMap< int, const QStringList * > mRowToItems
void CQComboDelegate::setModelData ( QWidget *  editor,
QAbstractItemModel *  model,
const QModelIndex &  index 
) const
virtual

Reimplemented in CQIndexComboDelegate.

Definition at line 68 of file CQComboDelegate.cpp.

70 {
71  QComboBox *comboBox = static_cast<QComboBox*>(editor);
72  QVariant value(comboBox->currentText());
73  model->setData(index, value, Qt::EditRole);
74 }
void CQComboDelegate::slotCurrentIndexChanged ( int  index)
protectedslot

Definition at line 104 of file CQComboDelegate.cpp.

References currentIndexChanged(), mCommitOnSelect, and mEditorToIndex.

Referenced by createEditor().

105 {
106  QComboBox * pEditor = dynamic_cast< QComboBox * >(sender());
107 
108  if (pEditor)
109  {
110  QMap< QWidget * , QModelIndex >::const_iterator found = mEditorToIndex.find(pEditor);
111 
112  if (found != mEditorToIndex.end())
113  {
114  emit currentIndexChanged(found.value().row(), index);
115 
116  if (mCommitOnSelect)
117  commitData(pEditor);
118  }
119  }
120 }
QMap< QWidget *, QModelIndex > mEditorToIndex
void currentIndexChanged(int, int)
void CQComboDelegate::slotEditorDeleted ( QObject *  pObject)
protectedslot

Definition at line 122 of file CQComboDelegate.cpp.

References mEditorToIndex.

Referenced by createEditor().

123 {
124  mEditorToIndex.remove(static_cast< QWidget * >(pObject));
125 }
QMap< QWidget *, QModelIndex > mEditorToIndex
void CQComboDelegate::updateEditorGeometry ( QWidget *  editor,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
virtual

Definition at line 76 of file CQComboDelegate.cpp.

78 {
79  editor->setGeometry(option.rect);
80 }

Member Data Documentation

bool CQComboDelegate::mCommitOnSelect
private

Definition at line 61 of file CQComboDelegate.h.

Referenced by isCommitOnSelect(), setCommitOnSelect(), and slotCurrentIndexChanged().

QMap< QWidget * , QModelIndex > CQComboDelegate::mEditorToIndex
mutableprivate

Definition at line 58 of file CQComboDelegate.h.

Referenced by createEditor(), slotCurrentIndexChanged(), and slotEditorDeleted().

const QStringList* CQComboDelegate::mpComboItems
private

Definition at line 56 of file CQComboDelegate.h.

Referenced by getItems().

QMap< int, const QStringList * > CQComboDelegate::mRowToItems
mutableprivate

Definition at line 59 of file CQComboDelegate.h.

Referenced by getItems(), and setItems().


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