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

#include <CQPushButtonDelegate.h>

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

Public Types

enum  ButtonType { PushButton, ToolButton }
 

Signals

void clicked (const QModelIndex &)
 

Public Member Functions

 CQPushButtonDelegate (const ButtonType &buttonType, QObject *parent=0)
 
 CQPushButtonDelegate (const QIcon &icon, const QString &text, const ButtonType &buttonType, QObject *parent=0)
 
virtual QWidget * createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
virtual void setEditorData (QWidget *pEditor, const QModelIndex &index) const
 
virtual void setModelData (QWidget *pEditor, QAbstractItemModel *pModel, const QModelIndex &index) const
 
virtual void updateEditorGeometry (QWidget *pEditor, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
virtual ~CQPushButtonDelegate ()
 

Protected Slots

void slotButtonClicked ()
 
void slotEditorDeleted (QObject *pObject)
 

Private Attributes

ButtonType mButtonType
 
QMap< QAbstractButton
*, QModelIndex > 
mEditorToIndex
 
QIcon mIcon
 
QString mText
 

Detailed Description

Definition at line 13 of file CQPushButtonDelegate.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CQPushButtonDelegate::CQPushButtonDelegate ( const ButtonType buttonType,
QObject *  parent = 0 
)

Definition at line 14 of file CQPushButtonDelegate.cpp.

15  :
16  QStyledItemDelegate(parent),
17  mIcon(),
18  mText(),
19  mButtonType(buttonType),
21 {}
QMap< QAbstractButton *, QModelIndex > mEditorToIndex
CQPushButtonDelegate::CQPushButtonDelegate ( const QIcon &  icon,
const QString &  text,
const ButtonType buttonType,
QObject *  parent = 0 
)

Definition at line 23 of file CQPushButtonDelegate.cpp.

26  :
27  QStyledItemDelegate(parent),
28  mIcon(icon),
29  mText(text),
30  mButtonType(buttonType),
32 {}
QMap< QAbstractButton *, QModelIndex > mEditorToIndex
CQPushButtonDelegate::~CQPushButtonDelegate ( )
virtual

Definition at line 34 of file CQPushButtonDelegate.cpp.

35 {}

Member Function Documentation

void CQPushButtonDelegate::clicked ( const QModelIndex &  )
signal

Referenced by createEditor(), and slotButtonClicked().

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

Definition at line 37 of file CQPushButtonDelegate.cpp.

References clicked(), mButtonType, mEditorToIndex, mIcon, mText, PushButton, slotButtonClicked(), slotEditorDeleted(), and ToolButton.

40 {
41  QModelIndex SourceIndex = index;
42  const QAbstractItemModel *pModel = index.model();
43 
44  while (pModel->inherits("QSortFilterProxyModel"))
45  {
46  SourceIndex = static_cast< const QSortFilterProxyModel *>(pModel)->mapToSource(index);
47  pModel = SourceIndex.model();
48  }
49 
50  QAbstractButton * pEditor;
51  QVariant Data;
52 
53  Data = SourceIndex.model()->data(SourceIndex, Qt::UserRole);
54 
55  if (Data.type() == QVariant::Icon)
56  {
57  mIcon = Data.value< QIcon >();
58  }
59 
60  switch (mButtonType)
61  {
62  case PushButton:
63  pEditor = new QPushButton(mIcon, mText, parent);
64  break;
65 
66  case ToolButton:
67  pEditor = new QToolButton(parent);
68 
69  if (mIcon.isNull())
70  {
71  Data = SourceIndex.model()->data(SourceIndex, Qt::DisplayRole);
72 
73  if (Data.type() == QVariant::String)
74  {
75  mText = Data.toString();
76  }
77 
78  pEditor->setText(mText);
79  }
80  else
81  {
82  pEditor->setIcon(mIcon);
83  }
84 
85  break;
86  }
87 
88  mEditorToIndex[pEditor] = SourceIndex;
89 
90  connect(pEditor, SIGNAL(clicked(bool)), this, SLOT(slotButtonClicked()));
91  connect(pEditor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDeleted(QObject *)));
92 
93  return pEditor;
94 }
void slotEditorDeleted(QObject *pObject)
QMap< QAbstractButton *, QModelIndex > mEditorToIndex
void clicked(const QModelIndex &)
void CQPushButtonDelegate::setEditorData ( QWidget *  pEditor,
const QModelIndex &  index 
) const
virtual

Definition at line 96 of file CQPushButtonDelegate.cpp.

97 {
98  QString value = index.model()->data(index, Qt::EditRole).toString();
99  QPushButton * pButton = static_cast< QPushButton * >(pEditor);
100 
101  if (pButton->icon().isNull())
102  {
103  pButton->setText(value);
104  }
105 }
void CQPushButtonDelegate::setModelData ( QWidget *  pEditor,
QAbstractItemModel *  pModel,
const QModelIndex &  index 
) const
virtual

Definition at line 108 of file CQPushButtonDelegate.cpp.

111 {}
void CQPushButtonDelegate::slotButtonClicked ( )
protectedslot

Definition at line 120 of file CQPushButtonDelegate.cpp.

References clicked(), and mEditorToIndex.

Referenced by createEditor().

121 {
122  QAbstractButton * pEditor = dynamic_cast< QAbstractButton *>(sender());
123 
124  if (pEditor)
125  {
126  QMap< QAbstractButton *, QModelIndex >::const_iterator found = mEditorToIndex.find(pEditor);
127 
128  if (found != mEditorToIndex.end())
129  {
130  emit clicked(found.value());
131  }
132  }
133 }
QMap< QAbstractButton *, QModelIndex > mEditorToIndex
void clicked(const QModelIndex &)
void CQPushButtonDelegate::slotEditorDeleted ( QObject *  pObject)
protectedslot

Definition at line 135 of file CQPushButtonDelegate.cpp.

References mEditorToIndex.

Referenced by createEditor().

136 {
137  QAbstractButton * pEditor = dynamic_cast< QAbstractButton *>(sender());
138 
139  if (pEditor)
140  {
141  mEditorToIndex.remove(pEditor);
142  }
143 }
QMap< QAbstractButton *, QModelIndex > mEditorToIndex
void CQPushButtonDelegate::updateEditorGeometry ( QWidget *  pEditor,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
virtual

Definition at line 113 of file CQPushButtonDelegate.cpp.

116 {
117  pEditor->setGeometry(option.rect);
118 }

Member Data Documentation

ButtonType CQPushButtonDelegate::mButtonType
private

Definition at line 48 of file CQPushButtonDelegate.h.

Referenced by createEditor().

QMap< QAbstractButton * , QModelIndex > CQPushButtonDelegate::mEditorToIndex
mutableprivate

Definition at line 50 of file CQPushButtonDelegate.h.

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

QIcon CQPushButtonDelegate::mIcon
mutableprivate

Definition at line 46 of file CQPushButtonDelegate.h.

Referenced by createEditor().

QString CQPushButtonDelegate::mText
mutableprivate

Definition at line 47 of file CQPushButtonDelegate.h.

Referenced by createEditor().


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