checkable and checked properties

This commit is contained in:
Marco Martin 2013-05-09 16:16:16 +02:00
parent 57b3883542
commit c13a58cf11
2 changed files with 34 additions and 0 deletions

View File

@ -38,9 +38,14 @@ QAction* QMenuItem::action() const
void QMenuItem::setAction(QAction* a) void QMenuItem::setAction(QAction* a)
{ {
if (m_action != a) { if (m_action != a) {
if (m_action) {
disconnect(m_action, 0, this, 0);
}
m_action = a; m_action = a;
connect(m_action, &QAction::changed, this, &QMenuItem::textChanged); connect(m_action, &QAction::changed, this, &QMenuItem::textChanged);
connect(m_action, &QAction::changed, this, &QMenuItem::textChanged); connect(m_action, &QAction::changed, this, &QMenuItem::textChanged);
connect(m_action, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
connect(m_action, SIGNAL(checkableChanged()), this, SIGNAL(checkableChanged()));
emit actionChanged(); emit actionChanged();
} }
} }
@ -84,6 +89,25 @@ void QMenuItem::setText(const QString& t)
} }
} }
bool QMenuItem::checkable() const
{
return m_action->isCheckable();
}
void QMenuItem::setCheckable(bool checkable)
{
m_action->setCheckable(checkable);
}
bool QMenuItem::checked() const
{
return m_action->isChecked();
}
void QMenuItem::setChecked(bool checked)
{
m_action->setChecked(checked);
}
#include "qmenuitem.moc" #include "qmenuitem.moc"

View File

@ -40,6 +40,8 @@ class QMenuItem : public QQuickItem
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QVariant icon READ icon WRITE setIcon NOTIFY iconChanged) Q_PROPERTY(QVariant icon READ icon WRITE setIcon NOTIFY iconChanged)
Q_PROPERTY(QAction* action READ action WRITE setAction NOTIFY actionChanged) Q_PROPERTY(QAction* action READ action WRITE setAction NOTIFY actionChanged)
Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged)
Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY toggled)
public: public:
QMenuItem(QQuickItem *parent = 0); QMenuItem(QQuickItem *parent = 0);
@ -53,6 +55,12 @@ public:
QString text() const; QString text() const;
void setText(const QString &t); void setText(const QString &t);
bool checkable() const;
void setCheckable(bool checkable);
bool checked() const;
void setChecked(bool checked);
Q_SIGNALS: Q_SIGNALS:
void clicked(); void clicked();
@ -60,6 +68,8 @@ Q_SIGNALS:
void iconChanged(); void iconChanged();
void separatorChanged(); void separatorChanged();
void textChanged(); void textChanged();
void toggled(bool checked);
void checkableChanged();
private: private:
QAction* m_action; QAction* m_action;