8#include <signalslotdialog_p.h>
9#include <metadatabase_p.h>
11#include <QtDesigner/abstractformwindow.h>
12#include <QtDesigner/abstractformeditor.h>
13#include <QtDesigner/abstractwidgetdatabase.h>
14#include <QtDesigner/qextensionmanager.h>
15#include <QtDesigner/abstractlanguage.h>
17#include <QtWidgets/qpushbutton.h>
21using namespace Qt::StringLiterals;
25 QString class_name = QLatin1StringView(widget->metaObject()->className());
26 const QDesignerWidgetDataBaseInterface *wdb = core->widgetDataBase();
27 const int idx = wdb->indexOfObject(widget);
29 class_name = wdb->item(idx)->name();
36 .arg(qdesigner_internal::realObjectName(core, widget),
37 realClassName(core, widget));
43 QWidget *source, QWidget *destination,
47 m_destination(destination),
48 m_sourceMode(widgetMode(m_source, formWindow)),
49 m_destinationMode(widgetMode(m_destination, formWindow)),
50 m_formWindow(formWindow)
54 connect(m_ui.signalList, &QListWidget::itemClicked,
55 this, &ConnectDialog::selectSignal);
56 connect(m_ui.slotList, &QListWidget::itemClicked,
57 this, &ConnectDialog::selectSlot);
58 m_ui.slotList->setEnabled(
false);
60 QPushButton *ok_button = okButton();
61 ok_button->setDefault(
true);
62 ok_button->setEnabled(
false);
64 connect(m_ui.showAllCheckBox, &QCheckBox::toggled,
this, &ConnectDialog::populateLists);
66 QDesignerFormEditorInterface *core = m_formWindow->core();
67 m_ui.signalGroupBox->setTitle(widgetLabel(core, source));
68 m_ui.slotGroupBox->setTitle(widgetLabel(core, destination));
70 m_ui.editSignalsButton->setEnabled(m_sourceMode != NormalWidget);
71 connect(m_ui.editSignalsButton, &QAbstractButton::clicked,
74 m_ui.editSlotsButton->setEnabled(m_destinationMode != NormalWidget);
75 connect(m_ui.editSlotsButton, &QAbstractButton::clicked,
83 QDesignerFormEditorInterface *core = formWindow->core();
84 if (qt_extension<QDesignerLanguageExtension*>(core->extensionManager(), core))
87 if (w == formWindow || formWindow->mainContainer() == w)
90 if (isPromoted(formWindow->core(), w))
91 return PromotedWidget;
98 return m_ui.buttonBox->button(QDialogButtonBox::Ok);
103 okButton()->setEnabled(e);
108 populateSignalList();
113 auto sigItems = m_ui.signalList->findItems(signal, Qt::MatchExactly);
115 if (sigItems.isEmpty()) {
116 m_ui.showAllCheckBox->setChecked(
true);
117 sigItems = m_ui.signalList->findItems(signal, Qt::MatchExactly);
120 if (!sigItems.isEmpty()) {
121 selectSignal(sigItems.constFirst());
122 auto slotItems = m_ui.slotList->findItems(slot, Qt::MatchExactly);
123 if (slotItems.isEmpty()) {
124 m_ui.showAllCheckBox->setChecked(
true);
125 slotItems = m_ui.slotList->findItems(slot, Qt::MatchExactly);
127 if (!slotItems.isEmpty())
128 selectSlot(slotItems.constFirst());
134 return m_ui.showAllCheckBox->isChecked();
139 m_ui.showAllCheckBox->setChecked(showIt);
145 m_ui.signalList->setCurrentItem(item);
146 populateSlotList(item->text());
147 m_ui.slotList->setEnabled(
true);
148 setOkButtonEnabled(!m_ui.slotList->selectedItems().isEmpty());
150 m_ui.signalList->clearSelection();
152 m_ui.slotList->setEnabled(
false);
153 setOkButtonEnabled(
false);
160 m_ui.slotList->setCurrentItem(item);
162 m_ui.slotList->clearSelection();
164 setOkButtonEnabled(
true);
169 const auto item_list = m_ui.signalList->selectedItems();
170 if (item_list.size() != 1)
172 return item_list.at(0)->text();
177 const auto item_list = m_ui.slotList->selectedItems();
178 if (item_list.size() != 1)
180 return item_list.at(0)->text();
185 enum { deprecatedSlot = 0 };
186 QString selectedName;
187 if (
const QListWidgetItem * item = m_ui.slotList->currentItem())
188 selectedName = item->text();
190 m_ui.slotList->clear();
192 QMap<QString, QString> memberToClassName = getMatchingSlots(m_formWindow->core(), m_destination, signal, showAllSignalsSlots());
194 QFont font = QApplication::font();
195 font.setItalic(
true);
196 QVariant variantFont = QVariant::fromValue(font);
198 QListWidgetItem *curr =
nullptr;
199 for (
auto itMember = memberToClassName.cbegin(), itMemberEnd = memberToClassName.cend(); itMember != itMemberEnd; ++itMember) {
200 const QString member = itMember.key();
201 QListWidgetItem *item =
new QListWidgetItem(m_ui.slotList);
202 item->setText(member);
203 if (member == selectedName)
208 if (deprecatedSlot) {
209 item->setData(Qt::FontRole, variantFont);
210 item->setData(Qt::ForegroundRole, QColor(Qt::red));
215 m_ui.slotList->setCurrentItem(curr);
217 if (m_ui.slotList->selectedItems().isEmpty())
218 setOkButtonEnabled(
false);
223 enum { deprecatedSignal = 0 };
225 QString selectedName;
226 if (
const QListWidgetItem *item = m_ui.signalList->currentItem())
227 selectedName = item->text();
229 m_ui.signalList->clear();
231 QMap<QString, QString> memberToClassName = getSignals(m_formWindow->core(), m_source, showAllSignalsSlots());
233 QFont font = QApplication::font();
234 font.setItalic(
true);
235 QVariant variantFont = QVariant::fromValue(font);
237 QListWidgetItem *curr =
nullptr;
238 for (
auto itMember = memberToClassName.cbegin(), itMemberEnd = memberToClassName.cend(); itMember != itMemberEnd; ++itMember) {
239 const QString member = itMember.key();
241 QListWidgetItem *item =
new QListWidgetItem(m_ui.signalList);
242 item->setText(member);
243 if (!selectedName.isEmpty() && member == selectedName)
248 if (deprecatedSignal) {
249 item->setData(Qt::FontRole, variantFont);
250 item->setData(Qt::ForegroundRole, QColor(Qt::red));
255 m_ui.signalList->setCurrentItem(curr);
257 selectedName.clear();
260 populateSlotList(selectedName);
262 m_ui.slotList->setEnabled(
false);
267 editSignalsSlots(m_source, m_sourceMode, SignalSlotDialog::FocusSignals);
272 editSignalsSlots(m_destination, m_destinationMode, SignalSlotDialog::FocusSlots);
275void ConnectDialog::editSignalsSlots(QWidget *w, WidgetMode mode,
int signalSlotDialogModeInt)
277 const SignalSlotDialog::FocusMode signalSlotDialogMode =
static_cast<SignalSlotDialog::FocusMode>(signalSlotDialogModeInt);
282 if (SignalSlotDialog::editMetaDataBase(m_formWindow, w,
this, signalSlotDialogMode))
286 if (SignalSlotDialog::editPromotedClass(m_formWindow->core(), w,
this, signalSlotDialogMode))
296#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.