Refactoring.

There is no automatic disconnection when the 'receiver' is destroyed because
it's a functor with no QObject. However, since 5.2 there is an overload which
adds a "context object". When that object is destroyed, the connection is
broken (the context is also used for the thread affinity: the lambda will be
called in the thread of the event loop of the object used as context).

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-12-21 20:45:14 +02:00
parent e4c90a0809
commit 731eb9ec89
21 changed files with 112 additions and 84 deletions

View File

@ -181,7 +181,7 @@ QGroupBox *TapeConfigurationPage::LangGroup()
{
langCombo->setCurrentIndex(index);
}
connect(langCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this]()
connect(langCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), RECEIVER(this)[this]()
{
langChanged = true;
});
@ -231,7 +231,7 @@ QGroupBox *TapeConfigurationPage::PMSystemGroup()
pmSystemLayout->addRow(systemBookLabel, systemBookValueLabel);
connect(systemCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this]()
connect(systemCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), RECEIVER(this)[this]()
{
systemChanged = true;
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
@ -285,7 +285,7 @@ QGroupBox *TapeConfigurationPage::GradationGroup()
defGradationChanged = true;
};
connect(defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), RECEIVER(this)
DefGradationChanged);
gradationLayout->addRow(defHeightLabel, defHeightCombo);
@ -298,7 +298,7 @@ QGroupBox *TapeConfigurationPage::GradationGroup()
{
defSizeCombo->setCurrentIndex(index);
}
connect(defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), RECEIVER(this)
DefGradationChanged);
gradationLayout->addRow(defSizeLabel, defSizeCombo);

View File

@ -50,7 +50,7 @@ DialogAboutTape::DialogAboutTape(QWidget *parent)
//mApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale::c());
RetranslateUi();
connect(ui->pushButton_Web_Site, &QPushButton::clicked, [this]()
connect(ui->pushButton_Web_Site, &QPushButton::clicked, RECEIVER(this)[this]()
{
if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false)
{
@ -58,7 +58,8 @@ DialogAboutTape::DialogAboutTape(QWidget *parent)
}
});
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &DialogAboutTape::close);
connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, [](){
connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, []()
{
FvUpdater::sharedUpdater()->CheckForUpdatesNotSilent();
});

View File

@ -57,7 +57,7 @@ DialogExportToCSV::DialogExportToCSV(QWidget *parent)
QPushButton *bDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults);
SCASSERT(bDefaults != nullptr)
connect(bDefaults, &QPushButton::clicked, [this]()
connect(bDefaults, &QPushButton::clicked, RECEIVER(this)[this]()
{
ui->checkBoxWithHeader->setChecked(qApp->TapeSettings()->GetDefCSVWithHeader());
ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->TapeSettings()->GetDefCSVCodec()));

View File

@ -71,7 +71,7 @@ TapeConfigDialog::TapeConfigDialog(QWidget *parent)
createIcons();
connect(contentsWidget, &QListWidget::currentItemChanged,
[this](QListWidgetItem *current, QListWidgetItem *previous)
RECEIVER(this)[this](QListWidgetItem *current, QListWidgetItem *previous)
{
if (current == nullptr)
{

View File

@ -1787,7 +1787,7 @@ void TMainWindow::SetupMenu()
{
QAction *action = new QAction(this);
recentFileActs[i] = action;
connect(action, &QAction::triggered, [action, this]()
connect(action, &QAction::triggered, RECEIVER(this)[action, this]()
{
if (action != nullptr)
{
@ -1828,8 +1828,11 @@ void TMainWindow::SetupMenu()
AboutToShowWindowMenu();
// Help
connect(ui->actionAboutQt, &QAction::triggered, [this](){QMessageBox::aboutQt(this, tr("About Qt"));});
connect(ui->actionAboutTape, &QAction::triggered, [this]()
connect(ui->actionAboutQt, &QAction::triggered, RECEIVER(this)[this]()
{
QMessageBox::aboutQt(this, tr("About Qt"));
});
connect(ui->actionAboutTape, &QAction::triggered, RECEIVER(this)[this]()
{
DialogAboutTape *aboutDialog = new DialogAboutTape(this);
aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true);
@ -2007,7 +2010,10 @@ void TMainWindow::InitWindow()
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription);
connect(ui->lineEditFullName, &QLineEdit::textEdited, this, &TMainWindow::SaveMFullName);
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, [this](){ShowInGraphicalShell(curFile);});
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, RECEIVER(this)[this]()
{
ShowInGraphicalShell(curFile);
});
InitUnits();
@ -2822,7 +2828,7 @@ void TMainWindow::CreateWindowMenu(QMenu *menu)
SCASSERT(menu != nullptr)
QAction *action = menu->addAction(tr("&New Window"));
connect(action, &QAction::triggered, [this]()
connect(action, &QAction::triggered, RECEIVER(this)[this]()
{
qApp->NewMainWindow();
qApp->MainWindow()->activateWindow();

View File

@ -168,7 +168,7 @@ void ConfigDialog::createIcons()
createIcon("://icon/path_config.png", tr("Paths"));
connect(contentsWidget, &QListWidget::currentItemChanged,
[this](QListWidgetItem *current, QListWidgetItem *previous)
RECEIVER(this)[this](QListWidgetItem *current, QListWidgetItem *previous)
{
if (current == nullptr)
{

View File

@ -233,7 +233,7 @@ void PathPage::InitTable()
pathTable->resizeRowsToContents();
pathTable->horizontalHeader()->setStretchLastSection(true);
connect(pathTable, &QTableWidget::itemSelectionChanged, [this]()
connect(pathTable, &QTableWidget::itemSelectionChanged, RECEIVER(this)[this]()
{
defaultButton->setEnabled(true);
defaultButton->setDefault(false);

View File

@ -61,7 +61,7 @@ DialogAboutApp::DialogAboutApp(QWidget *parent) :
ui->pushButton_Web_Site->setText(tr("Web site : %1").arg(VER_COMPANYDOMAIN_STR));
connect(ui->pushButton_Web_Site, &QPushButton::clicked, [this]()
connect(ui->pushButton_Web_Site, &QPushButton::clicked, RECEIVER(this)[this]()
{
if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false)
{

View File

@ -62,7 +62,10 @@ DialogHistory::DialogHistory(VContainer *data, VPattern *doc, QWidget *parent)
FillTable();
InitialTable();
connect(ui->tableWidget, &QTableWidget::cellClicked, this, &DialogHistory::cellClicked);
connect(this, &DialogHistory::ShowHistoryTool, [doc](quint32 id, bool enable){emit doc->ShowTool(id, enable);});
connect(this, &DialogHistory::ShowHistoryTool, RECEIVER(doc)[doc](quint32 id, bool enable)
{
emit doc->ShowTool(id, enable);
});
connect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor);
connect(doc, &VPattern::patternChanged, this, &DialogHistory::UpdateHistory);
ShowPoint();

View File

@ -110,15 +110,15 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
connect(ui->lineEditName, &QLineEdit::editingFinished, this, &DialogIncrements::SaveIncrName);
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrDescription);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrFormula);
connect(ui->lineEditFind, &QLineEdit::textEdited, [this](const QString &term){search->Find(term);});
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, [this](){search->FindPrevious();});
connect(ui->toolButtonFindNext, &QToolButton::clicked, [this](){search->FindNext();});
connect(ui->lineEditFind, &QLineEdit::textEdited, RECEIVER(this)[this](const QString &term){search->Find(term);});
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, RECEIVER(this)[this](){search->FindPrevious();});
connect(ui->toolButtonFindNext, &QToolButton::clicked, RECEIVER(this)[this](){search->FindNext();});
connect(search.data(), &VTableSearch::HasResult, [this] (bool state)
connect(search.data(), &VTableSearch::HasResult, RECEIVER(this)[this] (bool state)
{
ui->toolButtonFindPrevious->setEnabled(state);
});
connect(search.data(), &VTableSearch::HasResult, [this] (bool state)
connect(search.data(), &VTableSearch::HasResult, RECEIVER(this)[this] (bool state)
{
ui->toolButtonFindNext->setEnabled(state);
});

View File

@ -55,7 +55,7 @@ DialogLayoutProgress::DialogLayoutProgress(int count, QWidget *parent)
QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
SCASSERT(bCancel != nullptr)
connect(bCancel, &QPushButton::clicked, [this](){emit Abort();});
connect(bCancel, &QPushButton::clicked, RECEIVER(this)[this](){emit Abort();});
setModal(true);
this->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
@ -91,11 +91,10 @@ void DialogLayoutProgress::Error(const LayoutErrors &state)
case LayoutErrors::PrepareLayoutError:
qCritical() << tr("Couldn't prepare data for creation layout");
break;
case LayoutErrors::ProcessStoped:
break;
case LayoutErrors::EmptyPaperError:
qCritical() << tr("Several workpieces left not arranged, but none of them match for paper");
break;
case LayoutErrors::ProcessStoped:
default:
break;
}

View File

@ -87,7 +87,10 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte
}
ui->lineEditPathToFile->setCursorPosition(0);
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, [this](){ShowInGraphicalShell(m_filePath);});
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, RECEIVER(this)[this]()
{
ShowInGraphicalShell(m_filePath);
});
#if defined(Q_OS_MAC)
ui->pushButtonShowInExplorer->setText(tr("Show in Finder"));
#endif //defined(Q_OS_MAC)
@ -135,7 +138,7 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte
const QString size = QString().setNum(doc->GetDefCustomSize());
SetDefaultSize(size);
connect(ui->radioButtonDefFromP, &QRadioButton::toggled, [this]()
connect(ui->radioButtonDefFromP, &QRadioButton::toggled, RECEIVER(this)[this]()
{
ui->comboBoxHeight->setEnabled(ui->radioButtonDefFromP->isChecked());
ui->comboBoxSize->setEnabled(ui->radioButtonDefFromP->isChecked());
@ -143,19 +146,20 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte
auto DefValueChanged = [this](){defaultChanged = true;};
connect(ui->radioButtonDefFromP, &QRadioButton::toggled, DefValueChanged);
connect(ui->radioButtonDefFromP, &QRadioButton::toggled, RECEIVER(this)DefValueChanged);
ui->radioButtonDefFromP->setChecked(doc->IsDefCustom());
connect(ui->comboBoxHeight, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
DefValueChanged);
connect(ui->comboBoxSize, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), DefValueChanged);
RECEIVER(this)DefValueChanged);
connect(ui->comboBoxSize, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
RECEIVER(this)DefValueChanged);
const bool readOnly = doc->IsReadOnly();
ui->checkBoxPatternReadOnly->setChecked(readOnly);
if (not readOnly)
{
connect(ui->checkBoxPatternReadOnly, &QRadioButton::toggled, [this](){securityChanged = true;});
connect(ui->checkBoxPatternReadOnly, &QRadioButton::toggled, RECEIVER(this)[this](){securityChanged = true;});
}
else
{
@ -725,7 +729,7 @@ void DialogPatternProperties::InitImage()
{
ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu);
ui->imageLabel->setScaledContents(true);
connect(ui->imageLabel, &QWidget::customContextMenuRequested, [this]()
connect(ui->imageLabel, &QWidget::customContextMenuRequested, RECEIVER(this)[this]()
{
QMenu menu(this);
menu.addAction(deleteAction);
@ -741,7 +745,7 @@ void DialogPatternProperties::InitImage()
saveImageAction = new QAction(tr("Save image to file"), this);
showImageAction = new QAction(tr("Show image"), this);
connect(deleteAction, &QAction::triggered, [this]()
connect(deleteAction, &QAction::triggered, RECEIVER(this)[this]()
{
doc->DeleteImage();
ui->imageLabel->setText(tr("Change image"));
@ -752,7 +756,7 @@ void DialogPatternProperties::InitImage()
connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::ChangeImage);
connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage);
connect(showImageAction, &QAction::triggered, [this]()
connect(showImageAction, &QAction::triggered, RECEIVER(this)[this]()
{
QLabel *label = new QLabel(this, Qt::Window);
const QImage image = GetImage();

View File

@ -97,9 +97,10 @@ DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget *
ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + Format());
};
connect(ui->lineEditFileName, &QLineEdit::textChanged, ShowExample);
connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), ShowExample);
connect(ui->pushButtonBrowse, &QPushButton::clicked, [this]()
connect(ui->lineEditFileName, &QLineEdit::textChanged, RECEIVER(this)ShowExample);
connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
RECEIVER(this)ShowExample);
connect(ui->pushButtonBrowse, &QPushButton::clicked, RECEIVER(this)[this]()
{
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder"),
qApp->ValentinaSettings()->GetPathLayout(),

View File

@ -132,7 +132,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternChangesWereSaved);
connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile);
connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI);
connect(doc, &VPattern::CheckLayout, [this]()
connect(doc, &VPattern::CheckLayout, RECEIVER(this)[this]()
{
if (pattern->DataDetails()->count() == 0)
{
@ -171,7 +171,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->dockWidgetLayoutPages->setVisible(false);
connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::MeasurementsChanged);
connect(qApp, &QApplication::focusChanged, [this](QWidget *old, QWidget *now)
connect(qApp, &QApplication::focusChanged, RECEIVER(this)[this](QWidget *old, QWidget *now)
{
if (old == nullptr && isAncestorOf(now) == true)
{// focus IN
@ -616,7 +616,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
connect(dialogTool.data(), &DialogTool::DialogClosed, this, closeDialogSlot);
connect(dialogTool.data(), &DialogTool::DialogApplied, this, applyDialogSlot);
connect(dialogTool.data(), &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
connect(ui->view, &VMainGraphicsView::MouseRelease, [this](){EndVisualization(true);});
connect(ui->view, &VMainGraphicsView::MouseRelease, RECEIVER(this)[this](){EndVisualization(true);});
ui->view->itemClicked(nullptr);
}
else
@ -1659,9 +1659,9 @@ void MainWindow::ToolBarDraws()
comboBoxDraws->setSizeAdjustPolicy(QComboBox::AdjustToContents);
comboBoxDraws->setEnabled(false);
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int index){ChangePP(index);});
RECEIVER(this)[this](int index){ChangePP(index);});
connect(ui->actionOptionDraw, &QAction::triggered, [this]()
connect(ui->actionOptionDraw, &QAction::triggered, RECEIVER(this)[this]()
{
const QString activDraw = doc->GetNameActivPP();
const QString nameDraw = PatternPieceName(activDraw);
@ -2019,8 +2019,6 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
ArrowTool();
break;
case Qt::Key_Return:
EndVisualization();
break;
case Qt::Key_Enter:
EndVisualization();
break;
@ -3511,13 +3509,15 @@ void MainWindow::AddDocks()
//Add dock
actionDockWidgetToolOptions = ui->dockWidgetToolOptions->toggleViewAction();
ui->menuPatternPiece->insertAction(ui->actionPattern_properties, actionDockWidgetToolOptions);
connect(ui->dockWidgetToolOptions, &QDockWidget::visibilityChanged, [this](bool visible){
connect(ui->dockWidgetToolOptions, &QDockWidget::visibilityChanged, RECEIVER(this)[this](bool visible)
{
isDockToolOptionsVisible = visible;
});
actionDockWidgetGroups = ui->dockWidgetGroups->toggleViewAction();
ui->menuPatternPiece->insertAction(ui->actionPattern_properties, actionDockWidgetGroups);
connect(ui->dockWidgetGroups, &QDockWidget::visibilityChanged, [this](bool visible){
connect(ui->dockWidgetGroups, &QDockWidget::visibilityChanged, RECEIVER(this)[this](bool visible)
{
isDockGroupsVisible = visible;
});
@ -3568,14 +3568,14 @@ void MainWindow::CreateActions()
connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::ActionDetails);
connect(ui->actionLayout, &QAction::triggered, this, &MainWindow::ActionLayout);
connect(ui->actionHistory, &QAction::triggered, [this](bool checked)
connect(ui->actionHistory, &QAction::triggered, RECEIVER(this)[this](bool checked)
{
if (checked)
{
dialogHistory = new DialogHistory(pattern, doc, this);
dialogHistory->setWindowFlags(Qt::Window);
connect(this, &MainWindow::RefreshHistory, dialogHistory.data(), &DialogHistory::UpdateHistory);
connect(dialogHistory.data(), &DialogHistory::DialogClosed, [this]()
connect(dialogHistory.data(), &DialogHistory::DialogClosed, RECEIVER(this)[this]()
{
ui->actionHistory->setChecked(false);
delete dialogHistory;
@ -3591,7 +3591,7 @@ void MainWindow::CreateActions()
}
});
connect(ui->actionNewDraw, &QAction::triggered, [this]()
connect(ui->actionNewDraw, &QAction::triggered, RECEIVER(this)[this]()
{
qCDebug(vMainWindow, "New PP.");
QString patternPieceName = tr("Pattern piece %1").arg(comboBoxDraws->count()+1);
@ -3614,12 +3614,12 @@ void MainWindow::CreateActions()
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::Open);
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::New);
connect(ui->actionTable, &QAction::triggered, [this](bool checked)
connect(ui->actionTable, &QAction::triggered, RECEIVER(this)[this](bool checked)
{
if (checked)
{
dialogTable = new DialogIncrements(pattern, doc, this);
connect(dialogTable.data(), &DialogIncrements::DialogClosed, [this]()
connect(dialogTable.data(), &DialogIncrements::DialogClosed, RECEIVER(this)[this]()
{
ui->actionTable->setChecked(false);
delete dialogTable;
@ -3633,12 +3633,12 @@ void MainWindow::CreateActions()
}
});
connect(ui->actionAbout_Qt, &QAction::triggered, [this]()
connect(ui->actionAbout_Qt, &QAction::triggered, RECEIVER(this)[this]()
{
QMessageBox::aboutQt(this, tr("About Qt"));
});
connect(ui->actionAbout_Valentina, &QAction::triggered, [this]()
connect(ui->actionAbout_Valentina, &QAction::triggered, RECEIVER(this)[this]()
{
DialogAboutApp *aboutDialog = new DialogAboutApp(this);
aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true);
@ -3648,13 +3648,13 @@ void MainWindow::CreateActions()
connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
connect(ui->actionPreferences, &QAction::triggered, this, &MainWindow::Preferences);
connect(ui->actionReportBug, &QAction::triggered, [this]()
connect(ui->actionReportBug, &QAction::triggered, RECEIVER(this)[this]()
{
qCDebug(vMainWindow, "Reporting bug");
QDesktopServices::openUrl(QUrl(QStringLiteral("https://bitbucket.org/dismine/valentina/issues/new")));
});
connect(ui->actionOnlineHelp, &QAction::triggered, [this]()
connect(ui->actionOnlineHelp, &QAction::triggered, RECEIVER(this)[this]()
{
qCDebug(vMainWindow, "Showing online help");
QDesktopServices::openUrl(QUrl(QStringLiteral("https://bitbucket.org/dismine/valentina/wiki/manual/Content")));
@ -3662,10 +3662,10 @@ void MainWindow::CreateActions()
connect(ui->actionLast_tool, &QAction::triggered, this, &MainWindow::LastUsedTool);
connect(ui->actionPattern_properties, &QAction::triggered, [this]()
connect(ui->actionPattern_properties, &QAction::triggered, RECEIVER(this)[this]()
{
DialogPatternProperties proper(curFile, doc, pattern, this);
connect(&proper, &DialogPatternProperties::UpdateGradation, [this]()
connect(&proper, &DialogPatternProperties::UpdateGradation, RECEIVER(this)[this]()
{
UpdateHeightsList(VMeasurement::ListHeights(doc->GetGradationHeights(), qApp->patternUnit()));
UpdateSizesList(VMeasurement::ListSizes(doc->GetGradationSizes(), qApp->patternUnit()));
@ -3674,14 +3674,14 @@ void MainWindow::CreateActions()
});
ui->actionPattern_properties->setEnabled(false);
connect(ui->actionEdit_pattern_code, &QAction::triggered, [this]()
connect(ui->actionEdit_pattern_code, &QAction::triggered, RECEIVER(this)[this]()
{
DialogPatternXmlEdit *pattern = new DialogPatternXmlEdit (this, doc);
pattern->setAttribute(Qt::WA_DeleteOnClose, true);
pattern->show();
});
connect(ui->actionClosePattern, &QAction::triggered, [this]()
connect(ui->actionClosePattern, &QAction::triggered, RECEIVER(this)[this]()
{
if (MaybeSave())
{
@ -3690,7 +3690,7 @@ void MainWindow::CreateActions()
}
});
connect(ui->actionShowCurveDetails, &QAction::triggered, [this](bool checked)
connect(ui->actionShowCurveDetails, &QAction::triggered, RECEIVER(this)[this](bool checked)
{
ui->view->itemClicked(nullptr);
sceneDraw->EnableDetailsMode(checked);
@ -3699,7 +3699,7 @@ void MainWindow::CreateActions()
connect(ui->actionLoadIndividual, &QAction::triggered, this, &MainWindow::LoadIndividual);
connect(ui->actionLoadStandard, &QAction::triggered, this, &MainWindow::LoadStandard);
connect(ui->actionCreateNew, &QAction::triggered, [this]()
connect(ui->actionCreateNew, &QAction::triggered, RECEIVER(this)[this]()
{
const QString tape = qApp->TapeFilePath();
const QString workingDirectory = QFileInfo(tape).absoluteDir().absolutePath();
@ -3721,7 +3721,7 @@ void MainWindow::CreateActions()
QAction *action = new QAction(this);
action->setVisible(false);
recentFileActs[i] = action;
connect(recentFileActs[i], &QAction::triggered, [action, this]()
connect(recentFileActs[i], &QAction::triggered, RECEIVER(this)[action, this]()
{
// cppcheck-suppress nullPointerRedundantCheck
if (action != nullptr)

View File

@ -281,7 +281,7 @@ void FvUpdater::startDownloadFeed(const QUrl &url)
m_reply = m_qnam.get(request);
connect(m_reply, &QNetworkReply::readyRead, [this]()
connect(m_reply, &QNetworkReply::readyRead, RECEIVER(this)[this]()
{
// this slot gets called every time the QNetworkReply has new data.
// We read all of its new data and write it into the file.
@ -289,7 +289,7 @@ void FvUpdater::startDownloadFeed(const QUrl &url)
// signal of the QNetworkReply
m_xml.addData(m_reply->readAll());
});
connect(m_reply, &QNetworkReply::downloadProgress, [this](qint64 bytesRead, qint64 totalBytes)
connect(m_reply, &QNetworkReply::downloadProgress, RECEIVER(this)[this](qint64 bytesRead, qint64 totalBytes)
{
Q_UNUSED(bytesRead)
Q_UNUSED(totalBytes)

View File

@ -49,6 +49,17 @@ template <class T> class QSharedPointer;
#include <ciso646>
#endif /* Q_CC_MSVC */
//There is no automatic disconnection when the 'receiver' is destroyed because it's a functor with no QObject. However,
//since 5.2 there is an overload which adds a "context object". When that object is destroyed, the connection is broken
//(the context is also used for the thread affinity: the lambda will be called in the thread of the event loop of the
// object used as context).
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
#define RECEIVER(obj) (obj),
#else
#define RECEIVER(obj)
#endif
class QComboBox;
class QMarginsF;
class VTranslateMeasurements;

View File

@ -118,7 +118,7 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
connect(this, &QApplication::aboutToQuit, [this]()
connect(this, &QApplication::aboutToQuit, RECEIVER(this)[this]()
{
// If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
// instance. Solution is to call sync() before quit.

View File

@ -407,31 +407,31 @@ void DialogEditWrongFormula::InitVariables()
auto ClearFilterFormulaInputs = [this] () { ui->filterFormulaInputs->clear(); };
connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogEditWrongFormula::Measurements);
connect(ui->radioButtonStandardTable, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonStandardTable, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogEditWrongFormula::Increments);
connect(ui->radioButtonIncrements, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonIncrements, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogEditWrongFormula::LengthLines);
connect(ui->radioButtonLengthLine, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonLengthLine, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogEditWrongFormula::LengthCurves);
connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonAngleLine, &QRadioButton::clicked, this, &DialogEditWrongFormula::AngleLines);
connect(ui->radioButtonAngleLine, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonAngleLine, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonRadiusesArcs, &QRadioButton::clicked, this, &DialogEditWrongFormula::RadiusArcs);
connect(ui->radioButtonRadiusesArcs, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonRadiusesArcs, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonAnglesCurves, &QRadioButton::clicked, this, &DialogEditWrongFormula::AnglesCurves);
connect(ui->radioButtonAnglesCurves, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonAnglesCurves, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonCLength, &QRadioButton::clicked, this, &DialogEditWrongFormula::CurvesCLength);
connect(ui->radioButtonCLength, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonCLength, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->radioButtonFunctions, &QRadioButton::clicked, this, &DialogEditWrongFormula::Functions);
connect(ui->radioButtonFunctions, &QRadioButton::clicked, ClearFilterFormulaInputs);
connect(ui->radioButtonFunctions, &QRadioButton::clicked, RECEIVER(this)ClearFilterFormulaInputs);
connect(ui->checkBoxHideEmpty, &QCheckBox::stateChanged, this, &DialogEditWrongFormula::Measurements);
}

View File

@ -55,13 +55,13 @@ DialogUndo::DialogUndo(QWidget *parent)
}
else
{
connect(ui->pushButtonUndo, &QPushButton::clicked, [this]()
connect(ui->pushButtonUndo, &QPushButton::clicked, RECEIVER(this)[this]()
{
result = UndoButton::Undo;
accept();
});
}
connect(ui->pushButtonFix, &QPushButton::clicked, [this]()
connect(ui->pushButtonFix, &QPushButton::clicked, RECEIVER(this)[this]()
{
result = UndoButton::Fix;
accept();

View File

@ -475,7 +475,7 @@ VSimpleCurve *VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType
curve->setParentItem(this);
curve->SetType(curveType);
connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected);
connect(curve, &VSimpleCurve::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event)
connect(curve, &VSimpleCurve::ShowContextMenu, RECEIVER(this)[this](QGraphicsSceneContextMenuEvent * event)
{
contextMenuEvent(event);
});
@ -569,12 +569,13 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
*VAbstractTool::data.GetPatternUnit(), &factor);
point->setParentItem(this);
point->SetType(GOType::Point);
connect(point, &VSimplePoint::Choosed, [this](quint32 id)
connect(point, &VSimplePoint::Choosed, RECEIVER(this)[this](quint32 id)
{
emit ChoosedTool(id, SceneObject::Point);
});
connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected);
connect(point, &VSimplePoint::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event)
connect(point, &VSimplePoint::ShowContextMenu,
RECEIVER(this)[this](QGraphicsSceneContextMenuEvent * event)
{
contextMenuEvent(event);
});
@ -587,7 +588,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
case GOType::Arc:
{
VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), obj->getType());
connect(curve, &VSimpleCurve::Choosed, [this](quint32 id)
connect(curve, &VSimpleCurve::Choosed, RECEIVER(this)[this](quint32 id)
{
emit ChoosedTool(id, SceneObject::Arc);
});
@ -596,7 +597,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
case GOType::EllipticalArc:
{
VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), obj->getType());
connect(curve, &VSimpleCurve::Choosed, [this](quint32 id)
connect(curve, &VSimpleCurve::Choosed, RECEIVER(this)[this](quint32 id)
{
emit ChoosedTool(id, SceneObject::ElArc);
});
@ -606,7 +607,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
case GOType::CubicBezier:
{
VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), obj->getType());
connect(curve, &VSimpleCurve::Choosed, [this](quint32 id)
connect(curve, &VSimpleCurve::Choosed, RECEIVER(this)[this](quint32 id)
{
emit ChoosedTool(id, SceneObject::Spline);
});
@ -616,7 +617,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
case GOType::CubicBezierPath:
{
VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), obj->getType());
connect(curve, &VSimpleCurve::Choosed, [this](quint32 id)
connect(curve, &VSimpleCurve::Choosed, RECEIVER(this)[this](quint32 id)
{
emit ChoosedTool(id, SceneObject::SplinePath);
});

View File

@ -84,7 +84,9 @@ VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quin
lineName = new QGraphicsLineItem(this);
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this,
&VNodePoint::NameChangePosition);
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent *event) {
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu,
RECEIVER(this)[this](QGraphicsSceneContextMenuEvent *event)
{
emit ShowContextMenu(event);
});
this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))));