diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-18 09:22:35 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-31 08:18:05 +0100 |
commit | a72b17aac59e99089ba5f0169f577c83fb48fd5d (patch) | |
tree | 24aeec75113f4013f0880c76dc4a2c04415b4c74 | |
parent | d3363a9bb8cdbb87046a1331141db93aef4bd4d2 (diff) |
Qt Designer: Refactor ConnectionModel::data() of the signal slot editor
The implementation was broken in the sense that it would
return column text strings for the font/color roles since enum
deprecatedMember was 0.
Restructure the code to use a switch and a helper for the column
text.
Change-Id: Ifb055519b796d4323c3aac7bf24ccac8facf1497
Pick-to: 5.15
Task-number: QTBUG-82924
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
-rw-r--r-- | src/designer/src/components/signalsloteditor/signalsloteditor_p.h | 3 | ||||
-rw-r--r-- | src/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp | 76 |
2 files changed, 45 insertions, 34 deletions
diff --git a/src/designer/src/components/signalsloteditor/signalsloteditor_p.h b/src/designer/src/components/signalsloteditor/signalsloteditor_p.h index 15d0563cf..1a44c101a 100644 --- a/src/designer/src/components/signalsloteditor/signalsloteditor_p.h +++ b/src/designer/src/components/signalsloteditor/signalsloteditor_p.h @@ -105,6 +105,9 @@ public: Connection *indexToConnection(const QModelIndex &index) const; void updateAll(); + const SignalSlotConnection *connectionAt(const QModelIndex &index) const; + static QString columnText(const SignalSlotConnection *con, int column); + private slots: void connectionAdded(Connection *con); void connectionRemoved(int idx); diff --git a/src/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp b/src/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp index 0868c9fe2..70668c362 100644 --- a/src/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp +++ b/src/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp @@ -236,62 +236,70 @@ int ConnectionModel::columnCount(const QModelIndex &parent) const return 4; } +const SignalSlotConnection *ConnectionModel::connectionAt(const QModelIndex &index) const +{ + const int row = index.row(); + return m_editor != nullptr && row >= 0 && row < m_editor->connectionCount() + ? static_cast<const SignalSlotConnection*>(m_editor->connection(row)) + : nullptr; +} + QVariant ConnectionModel::data(const QModelIndex &index, int role) const { enum { deprecatedMember = 0 }; - if ((role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::FontRole && role != Qt::ForegroundRole) || !m_editor) + const SignalSlotConnection *con = connectionAt(index); + if (con == nullptr) return QVariant(); - if (index.row() < 0 || index.row() >= m_editor->connectionCount()) { - return QVariant(); - } - - const SignalSlotConnection *con = static_cast<SignalSlotConnection*>(m_editor->connection(index.row())); - Q_ASSERT(con != nullptr); - // Mark deprecated slots red/italic. Not currently in use (historically for Qt 3 slots in Qt 4), // but may be used again in the future. - if (deprecatedMember && role == Qt::ForegroundRole) - return QColor(Qt::red); - if (deprecatedMember && role == Qt::FontRole) { - QFont font = QApplication::font(); - font.setItalic(true); - return font; + switch (role) { + case Qt::ForegroundRole: + return deprecatedMember ? QColor(Qt::red) : QVariant(); + case Qt::FontRole: + if (deprecatedMember) { + QFont font = QApplication::font(); + font.setItalic(true); + return font; + } + return QVariant(); + case Qt::DisplayRole: + case Qt::EditRole: + return ConnectionModel::columnText(con, index.column()); + default: + break; } - static const QVariant senderDefault = tr("<sender>"); - static const QVariant signalDefault = tr("<signal>"); - static const QVariant receiverDefault = tr("<receiver>"); - static const QVariant slotDefault = tr("<slot>"); + return QVariant(); +} + +QString ConnectionModel::columnText(const SignalSlotConnection *con, int column) +{ + static const QString senderDefault = tr("<sender>"); + static const QString signalDefault = tr("<signal>"); + static const QString receiverDefault = tr("<receiver>"); + static const QString slotDefault = tr("<slot>"); - switch (index.column()) { + switch (column) { case 0: { const QString sender = con->sender(); - if (sender.isEmpty()) - return senderDefault; - return sender; + return sender.isEmpty() ? senderDefault : sender; } case 1: { - const QString signal = con->signal(); - if (signal.isEmpty()) - return signalDefault; - return signal; + const QString signalName = con->signal(); + return signalName.isEmpty() ? signalDefault : signalName; } case 2: { const QString receiver = con->receiver(); - if (receiver.isEmpty()) - return receiverDefault; - return receiver; + return receiver.isEmpty() ? receiverDefault : receiver; } case 3: { - const QString slot = con->slot(); - if (slot.isEmpty()) - return slotDefault; - return slot; + const QString slotName = con->slot(); + return slotName.isEmpty() ? slotDefault : slotName; } } - return QVariant(); + return QString(); } bool ConnectionModel::setData(const QModelIndex &index, const QVariant &data, int) |