~ubuntu-sdk-team/qtcreator-plugin-remotelinux/trunk

« back to all changes in this revision

Viewing changes to src/qnx/bardescriptoreditorabstractpanelwidget.cpp

  • Committer: CI bot
  • Author(s): Benjamin Zeller
  • Date: 2014-06-16 10:28:43 UTC
  • mfrom: (4.2.4 remotelinux)
  • Revision ID: ps-jenkins@lists.canonical.com-20140616102843-8juvmjvzwlzsboyw
Migrating to Qt5.3 and QtC 3.1 

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "bardescriptoreditorabstractpanelwidget.h"
33
33
 
34
34
#include <utils/pathchooser.h>
 
35
#include <utils/qtcassert.h>
35
36
 
36
37
#include <QCheckBox>
37
38
#include <QComboBox>
38
39
#include <QLineEdit>
 
40
#include <QSignalMapper>
39
41
#include <QTextEdit>
40
42
 
41
43
using namespace Qnx;
44
46
BarDescriptorEditorAbstractPanelWidget::BarDescriptorEditorAbstractPanelWidget(QWidget *parent) :
45
47
    QWidget(parent)
46
48
{
47
 
}
48
 
 
49
 
 
50
 
void BarDescriptorEditorAbstractPanelWidget::setComboBoxBlocked(QComboBox *comboBox, int index)
51
 
{
52
 
    bool blocked = comboBox->blockSignals(true);
53
 
    comboBox->setCurrentIndex(index);
54
 
    comboBox->blockSignals(blocked);
55
 
}
56
 
 
57
 
void BarDescriptorEditorAbstractPanelWidget::setCheckBoxBlocked(QCheckBox *checkBox, bool checked)
58
 
{
59
 
    bool blocked = checkBox->blockSignals(true);
60
 
    checkBox->setChecked(checked);
61
 
    checkBox->blockSignals(blocked);
62
 
}
63
 
 
64
 
void BarDescriptorEditorAbstractPanelWidget::setLineEditBlocked(QLineEdit *lineEdit, const QString &text)
65
 
{
66
 
    bool blocked = lineEdit->blockSignals(true);
67
 
    lineEdit->setText(text);
68
 
    lineEdit->blockSignals(blocked);
69
 
}
70
 
 
71
 
void BarDescriptorEditorAbstractPanelWidget::setTextEditBlocked(QTextEdit *textEdit, const QString &text)
72
 
{
73
 
    bool blocked = textEdit->blockSignals(true);
74
 
    textEdit->setPlainText(text);
75
 
    textEdit->blockSignals(blocked);
76
 
}
77
 
 
78
 
void BarDescriptorEditorAbstractPanelWidget::setPathChooserBlocked(Utils::PathChooser *pathChooser, const QString &path)
79
 
{
80
 
    bool blocked = pathChooser->blockSignals(true);
81
 
    pathChooser->setPath(path);
82
 
    pathChooser->blockSignals(blocked);
 
49
    m_signalMapper = new QSignalMapper(this);
 
50
    connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(handleSignalMapped(int)));
 
51
}
 
52
 
 
53
void BarDescriptorEditorAbstractPanelWidget::setValue(BarDescriptorDocument::Tag tag, const QVariant &value)
 
54
{
 
55
    if (m_blockedSignals.contains(tag))
 
56
        return;
 
57
 
 
58
    blockSignalMapping(tag);
 
59
    updateWidgetValue(tag, value);
 
60
    unblockSignalMapping(tag);
 
61
}
 
62
 
 
63
void BarDescriptorEditorAbstractPanelWidget::addSignalMapping(BarDescriptorDocument::Tag tag, QObject *object, const char *signal)
 
64
{
 
65
    m_signalMapper->setMapping(object, tag);
 
66
    connect(object, signal, m_signalMapper, SLOT(map()));
 
67
}
 
68
 
 
69
void BarDescriptorEditorAbstractPanelWidget::blockSignalMapping(BarDescriptorDocument::Tag tag)
 
70
{
 
71
    m_blockedSignals.prepend(tag);
 
72
}
 
73
 
 
74
void BarDescriptorEditorAbstractPanelWidget::unblockSignalMapping(BarDescriptorDocument::Tag tag)
 
75
{
 
76
    BarDescriptorDocument::Tag removedTag = m_blockedSignals.takeFirst();
 
77
    QTC_CHECK(removedTag == tag);
 
78
}
 
79
 
 
80
void BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
 
81
{
 
82
    QObject *object = m_signalMapper->mapping(static_cast<int>(tag));
 
83
    if (!object)
 
84
        return;
 
85
 
 
86
    if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(object))
 
87
        lineEdit->setText(value.toString());
 
88
    else if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(object))
 
89
        textEdit->setPlainText(value.toString());
 
90
    else if (Utils::PathChooser *pathChooser = qobject_cast<Utils::PathChooser *>(object))
 
91
        pathChooser->setPath(value.toString());
 
92
    else if (QComboBox *comboBox = qobject_cast<QComboBox *>(object))
 
93
        comboBox->setCurrentIndex(comboBox->findData(value.toString()));
 
94
    else if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(object))
 
95
        checkBox->setChecked(value.toBool());
 
96
    else
 
97
        QTC_CHECK(false);
 
98
}
 
99
 
 
100
void BarDescriptorEditorAbstractPanelWidget::emitChanged(BarDescriptorDocument::Tag tag)
 
101
{
 
102
    QObject *sender = m_signalMapper->mapping(tag);
 
103
 
 
104
    if (!sender)
 
105
        return;
 
106
 
 
107
    if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(sender))
 
108
        emit changed(tag, lineEdit->text());
 
109
    else if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(sender))
 
110
        emit changed(tag, textEdit->toPlainText());
 
111
    else if (Utils::PathChooser *pathChooser = qobject_cast<Utils::PathChooser *>(sender))
 
112
        emit changed(tag, pathChooser->path());
 
113
    else if (QComboBox *comboBox = qobject_cast<QComboBox *>(sender))
 
114
        emit changed(tag, comboBox->itemData(comboBox->currentIndex()));
 
115
    else if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender))
 
116
        emit changed(tag, checkBox->isChecked());
 
117
    else
 
118
        QTC_CHECK(false);
 
119
}
 
120
 
 
121
void BarDescriptorEditorAbstractPanelWidget::handleSignalMapped(int id)
 
122
{
 
123
    BarDescriptorDocument::Tag tag = static_cast<BarDescriptorDocument::Tag>(id);
 
124
 
 
125
    if (m_blockedSignals.contains(tag))
 
126
        return;
 
127
 
 
128
    blockSignalMapping(tag);
 
129
    emitChanged(tag);
 
130
    unblockSignalMapping(tag);
83
131
}