summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-03-18 09:22:35 +0100
committercherrypickbot <cherrypickbot@codereview.qt-project.org>2020-03-31 10:12:35 +0000
commitebb0380a4ef3410f5957b472203360fd67fe3b1d (patch)
tree994393061d3981b80855aebeb176e016b9c3e8cb
parent739e404eee420257f217001c5df753585b8a9031 (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. Cherry-picked from branch: dev Change-Id: Ifb055519b796d4323c3aac7bf24ccac8facf1497 Change-Id: I43a9c7e9f48ecb2e51849ce53e939c80aae54d5a Task-number: QTBUG-82924 Reviewed-by: cherrypickbot
-rw-r--r--src/designer/src/components/signalsloteditor/signalsloteditor_p.h3
-rw-r--r--src/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp76
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)