7#include <signalslotdialog_p.h>
8#include <metadatabase_p.h>
10#include <QtDesigner/abstractformwindow.h>
11#include <QtDesigner/abstractformeditor.h>
12#include <QtDesigner/abstractwidgetdatabase.h>
13#include <QtDesigner/qextensionmanager.h>
14#include <QtDesigner/abstractlanguage.h>
16#include <QtWidgets/qpushbutton.h>
20using namespace Qt::StringLiterals;
24 QString class_name = QLatin1StringView(widget->metaObject()->className());
25 const QDesignerWidgetDataBaseInterface *wdb = core->widgetDataBase();
26 const int idx = wdb->indexOfObject(widget);
28 class_name = wdb->item(idx)->name();
35 .arg(qdesigner_internal::realObjectName(core, widget),
36 realClassName(core, widget));
42 QWidget *source, QWidget *destination,
46 m_destination(destination),
47 m_sourceMode(widgetMode(m_source, formWindow)),
48 m_destinationMode(widgetMode(m_destination, formWindow)),
49 m_formWindow(formWindow)
53 connect(m_ui.signalList, &QListWidget::itemClicked,
54 this, &ConnectDialog::selectSignal);
55 connect(m_ui.slotList, &QListWidget::itemClicked,
56 this, &ConnectDialog::selectSlot);
57 m_ui.slotList->setEnabled(
false);
59 QPushButton *ok_button = okButton();
60 ok_button->setDefault(
true);
61 ok_button->setEnabled(
false);
63 connect(m_ui.showAllCheckBox, &QCheckBox::toggled,
this, &ConnectDialog::populateLists);
65 QDesignerFormEditorInterface *core = m_formWindow->core();
66 m_ui.signalGroupBox->setTitle(widgetLabel(core, source));
67 m_ui.slotGroupBox->setTitle(widgetLabel(core, destination));
69 m_ui.editSignalsButton->setEnabled(m_sourceMode != NormalWidget);
70 connect(m_ui.editSignalsButton, &QAbstractButton::clicked,
71 this, &ConnectDialog::editSignals);
73 m_ui.editSlotsButton->setEnabled(m_destinationMode != NormalWidget);
74 connect(m_ui.editSlotsButton, &QAbstractButton::clicked,
75 this, &ConnectDialog::editSlots);
82 QDesignerFormEditorInterface *core = formWindow->core();
83 if (qt_extension<QDesignerLanguageExtension*>(core->extensionManager(), core))
86 if (w == formWindow || formWindow->mainContainer() == w)
89 if (isPromoted(formWindow->core(), w))
90 return PromotedWidget;
97 return m_ui.buttonBox->button(QDialogButtonBox::Ok);
102 okButton()->setEnabled(e);
107 populateSignalList();
112 auto sigItems = m_ui.signalList->findItems(signal, Qt::MatchExactly);
114 if (sigItems.isEmpty()) {
115 m_ui.showAllCheckBox->setChecked(
true);
116 sigItems = m_ui.signalList->findItems(signal, Qt::MatchExactly);
119 if (!sigItems.isEmpty()) {
120 selectSignal(sigItems.constFirst());
121 auto slotItems = m_ui.slotList->findItems(slot, Qt::MatchExactly);
122 if (slotItems.isEmpty()) {
123 m_ui.showAllCheckBox->setChecked(
true);
124 slotItems = m_ui.slotList->findItems(slot, Qt::MatchExactly);
126 if (!slotItems.isEmpty())
127 selectSlot(slotItems.constFirst());
133 return m_ui.showAllCheckBox->isChecked();
138 m_ui.showAllCheckBox->setChecked(showIt);
144 m_ui.signalList->setCurrentItem(item);
145 populateSlotList(item->text());
146 m_ui.slotList->setEnabled(
true);
147 setOkButtonEnabled(!m_ui.slotList->selectedItems().isEmpty());
149 m_ui.signalList->clearSelection();
151 m_ui.slotList->setEnabled(
false);
152 setOkButtonEnabled(
false);
159 m_ui.slotList->setCurrentItem(item);
161 m_ui.slotList->clearSelection();
163 setOkButtonEnabled(
true);
168 const auto item_list = m_ui.signalList->selectedItems();
169 if (item_list.size() != 1)
171 return item_list.at(0)->text();
176 const auto item_list = m_ui.slotList->selectedItems();
177 if (item_list.size() != 1)
179 return item_list.at(0)->text();
184 enum { deprecatedSlot = 0 };
185 QString selectedName;
186 if (
const QListWidgetItem * item = m_ui.slotList->currentItem())
187 selectedName = item->text();
189 m_ui.slotList->clear();
191 QMap<QString, QString> memberToClassName = getMatchingSlots(m_formWindow->core(), m_destination, signal, showAllSignalsSlots());
193 QFont font = QApplication::font();
194 font.setItalic(
true);
195 QVariant variantFont = QVariant::fromValue(font);
197 QListWidgetItem *curr =
nullptr;
198 for (
auto itMember = memberToClassName.cbegin(), itMemberEnd = memberToClassName.cend(); itMember != itMemberEnd; ++itMember) {
199 const QString member = itMember.key();
200 QListWidgetItem *item =
new QListWidgetItem(m_ui.slotList);
201 item->setText(member);
202 if (member == selectedName)
207 if (deprecatedSlot) {
208 item->setData(Qt::FontRole, variantFont);
209 item->setData(Qt::ForegroundRole, QColor(Qt::red));
214 m_ui.slotList->setCurrentItem(curr);
216 if (m_ui.slotList->selectedItems().isEmpty())
217 setOkButtonEnabled(
false);
222 enum { deprecatedSignal = 0 };
224 QString selectedName;
225 if (
const QListWidgetItem *item = m_ui.signalList->currentItem())
226 selectedName = item->text();
228 m_ui.signalList->clear();
230 QMap<QString, QString> memberToClassName = getSignals(m_formWindow->core(), m_source, showAllSignalsSlots());
232 QFont font = QApplication::font();
233 font.setItalic(
true);
234 QVariant variantFont = QVariant::fromValue(font);
236 QListWidgetItem *curr =
nullptr;
237 for (
auto itMember = memberToClassName.cbegin(), itMemberEnd = memberToClassName.cend(); itMember != itMemberEnd; ++itMember) {
238 const QString member = itMember.key();
240 QListWidgetItem *item =
new QListWidgetItem(m_ui.signalList);
241 item->setText(member);
242 if (!selectedName.isEmpty() && member == selectedName)
247 if (deprecatedSignal) {
248 item->setData(Qt::FontRole, variantFont);
249 item->setData(Qt::ForegroundRole, QColor(Qt::red));
254 m_ui.signalList->setCurrentItem(curr);
256 selectedName.clear();
259 populateSlotList(selectedName);
261 m_ui.slotList->setEnabled(
false);
266 editSignalsSlots(m_source, m_sourceMode, SignalSlotDialog::FocusSignals);
271 editSignalsSlots(m_destination, m_destinationMode, SignalSlotDialog::FocusSlots);
274void ConnectDialog::editSignalsSlots(QWidget *w, WidgetMode mode,
int signalSlotDialogModeInt)
276 const SignalSlotDialog::FocusMode signalSlotDialogMode =
static_cast<SignalSlotDialog::FocusMode>(signalSlotDialogModeInt);
281 if (SignalSlotDialog::editMetaDataBase(m_formWindow, w,
this, signalSlotDialogMode))
285 if (SignalSlotDialog::editPromotedClass(m_formWindow->core(), w,
this, signalSlotDialogMode))
295#include "moc_connectdialog_p.cpp"
bool showAllSignalsSlots() const
void setShowAllSignalsSlots(bool showIt)
void setSignalSlot(const QString &signal, const QString &slot)
static QString widgetLabel(QDesignerFormEditorInterface *core, QWidget *widget)
static QString realClassName(QDesignerFormEditorInterface *core, QWidget *widget)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.