uic: Generate parameters for ambiguous signals
Fixes: PYSIDE-1720 Pick-to: 6.2 Change-Id: I71b77db73471bdec7826bf69c7df521d7686537e Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
parent
c001216eed
commit
49a8ab50ba
@ -27,6 +27,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "cppwriteinitialization.h"
|
||||
#include "customwidgetsinfo.h"
|
||||
#include "driver.h"
|
||||
#include "ui4.h"
|
||||
#include "utils.h"
|
||||
@ -2640,10 +2641,14 @@ void WriteInitialization::acceptConnection(DomConnection *connection)
|
||||
return;
|
||||
}
|
||||
const QString senderSignature = connection->elementSignal();
|
||||
language::SignalSlotOptions signalOptions;
|
||||
if (m_uic->customWidgetsInfo()->isAmbiguousSignal(senderDecl.className, senderSignature))
|
||||
signalOptions.setFlag(language::SignalSlotOption::Ambiguous);
|
||||
|
||||
language::SignalSlot theSignal{senderDecl.name, senderSignature,
|
||||
senderDecl.className};
|
||||
senderDecl.className, signalOptions};
|
||||
language::SignalSlot theSlot{receiverDecl.name, connection->elementSlot(),
|
||||
receiverDecl.className};
|
||||
receiverDecl.className, {}};
|
||||
|
||||
m_output << m_indent;
|
||||
language::formatConnection(m_output, theSignal, theSlot,
|
||||
|
@ -101,6 +101,21 @@ bool CustomWidgetsInfo::isCustomWidgetContainer(const QString &className) const
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is it ambiguous, resulting in different signals for Python
|
||||
// "QAbstractButton::clicked(checked=false)"
|
||||
bool CustomWidgetsInfo::isAmbiguousSignal(const QString &className,
|
||||
const QString &signalSignature) const
|
||||
{
|
||||
if (signalSignature.startsWith(u"triggered") && extends(className, "QAction"))
|
||||
return true;
|
||||
if (signalSignature.startsWith(u"clicked(")
|
||||
&& extendsOneOf(className, {u"QCommandLinkButton"_qs, u"QCheckBox"_qs,
|
||||
u"QPushButton"_qs, u"QRadioButton"_qs, u"QToolButton"_qs})) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString CustomWidgetsInfo::realClassName(const QString &className) const
|
||||
{
|
||||
if (className == QLatin1String("Line"))
|
||||
|
@ -61,6 +61,9 @@ public:
|
||||
|
||||
bool isCustomWidgetContainer(const QString &className) const;
|
||||
|
||||
bool isAmbiguousSignal(const QString &className,
|
||||
const QString &signalSignature) const;
|
||||
|
||||
private:
|
||||
using NameCustomWidgetMap = QMap<QString, DomCustomWidget*>;
|
||||
NameCustomWidgetMap m_customWidgets;
|
||||
|
@ -456,12 +456,22 @@ void formatConnection(QTextStream &str, const SignalSlot &sender, const SignalSl
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Language::Python:
|
||||
str << sender.name << '.'
|
||||
<< QStringView{sender.signature}.left(sender.signature.indexOf(QLatin1Char('(')))
|
||||
<< ".connect(" << receiver.name << '.'
|
||||
case Language::Python: {
|
||||
const auto paren = sender.signature.indexOf(u'(');
|
||||
auto senderSignature = QStringView{sender.signature};
|
||||
str << sender.name << '.' << senderSignature.left(paren);
|
||||
// Signals like "QAbstractButton::clicked(checked=false)" require
|
||||
// the parameter if it is used.
|
||||
if (sender.options.testFlag(SignalSlotOption::Ambiguous)) {
|
||||
const QStringView parameters =
|
||||
senderSignature.mid(paren + 1, senderSignature.size() - paren - 2);
|
||||
if (!parameters.isEmpty() && !parameters.contains(u','))
|
||||
str << "[\"" << parameters << "\"]";
|
||||
}
|
||||
str << ".connect(" << receiver.name << '.'
|
||||
<< QStringView{receiver.signature}.left(receiver.signature.indexOf(QLatin1Char('(')))
|
||||
<< ')';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -198,11 +198,19 @@ inline QTextStream &operator<<(QTextStream &str, const _stackVariable<withInitPa
|
||||
using stackVariable = _stackVariable<false>;
|
||||
using stackVariableWithInitParameters = _stackVariable<true>;
|
||||
|
||||
enum class SignalSlotOption
|
||||
{
|
||||
Ambiguous = 0x1
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(SignalSlotOptions, SignalSlotOption)
|
||||
|
||||
struct SignalSlot
|
||||
{
|
||||
QString name;
|
||||
QString signature;
|
||||
QString className;
|
||||
SignalSlotOptions options;
|
||||
};
|
||||
|
||||
void formatConnection(QTextStream &str, const SignalSlot &sender, const SignalSlot &receiver,
|
||||
|
Loading…
Reference in New Issue
Block a user