OpenToonz - An open-source full-featured 2D animation creation software
C
Refactor: replace QRegExp, foreach, and legacy SIGNAL/SLOT
Anderson Prado124b1e2ab85d
diff --git a/toonz/sources/toonz/custompaneleditorpopup.cpp b/toonz/sources/toonz/custompaneleditorpopup.cppindex ae9fc3ecf..e0a5d1984 100644--- a/toonz/sources/toonz/custompaneleditorpopup.cpp+++ b/toonz/sources/toonz/custompaneleditorpopup.cpp@@ -1,3 +1,5 @@++#include "custompaneleditorpopup.h"// Tnz includes@@ -34,6 +36,7 @@#include <QTextStream>#include <QBuffer>#include <QToolButton>+#include <QRegularExpression>namespace {const TFilePath CustomPanelTemplateFolderName("custom panel templates");@@ -96,7 +99,8 @@ bool CustomPanelUIField::setCommand(QString commandId) {m_commandId = commandId;QString tempText = action->text();// removing accelerator key indicator- tempText = tempText.replace(QRegExp("&([^& ])"), "\\1");+ QRegularExpression re("&([^& ])");+ tempText = tempText.replace(re, "\\1");// removing doubled &stempText = tempText.replace("&&", "&");setText(tempText);@@ -237,10 +241,10 @@ void UiPreviewWidget::dragMoveEvent(QDragMoveEvent* event) {}void UiPreviewWidget::dropEvent(QDropEvent* event) {- QString commandId = event->mimeData()->text();- bool isDraggdFromTree = (event->dropAction() == Qt::CopyAction);+ QString commandId = event->mimeData()->text();+ bool isDraggedFromTree = (event->dropAction() == Qt::CopyAction);- emit dropped(m_highlightUiId, commandId, isDraggdFromTree);+ emit dropped(m_highlightUiId, commandId, isDraggedFromTree);}//-----------------------------------------------------------------------------@@ -263,7 +267,7 @@ void UiPreviewArea::resizeEvent(QResizeEvent* event) {//-----------------------------------------------------------------------------bool CustomPanelEditorPopup::loadTemplateList() {- // library / custom panel templates�̒����`�F�b�N+ // Check the library / custom panel templates directoryTFilePath customPanelTemplateFolder = customPaneTemplateFolderPath();if (!TSystem::doesExistFileOrLevel(customPanelTemplateFolder)) {DVGui::warning(tr("Template folder %1 not found.")@@ -315,8 +319,7 @@ bool CustomPanelEditorPopup::loadTemplateList() {//-----------------------------------------------------------------------------void CustomPanelEditorPopup::createFields() {- QList<QWidget*> widgets = m_UiFieldsContainer->findChildren<QWidget*>();- foreach (QWidget* child, widgets) {+ for (QWidget* child : m_UiFieldsContainer->findChildren<QWidget*>()) {delete child;}@@ -353,9 +356,10 @@ void CustomPanelEditorPopup::createFields() {}if (entry.type == Button || entry.type == Scroller_Fore) row++;- connect(entry.field, SIGNAL(highlight(int)), this, SLOT(onHighlight(int)));- connect(entry.field, SIGNAL(commandChanged(QString, QString)), this,- SLOT(onCommandChanged(QString, QString)));+ connect(entry.field, &CustomPanelUIField::highlight, this,+ &CustomPanelEditorPopup::onHighlight);+ connect(entry.field, &CustomPanelUIField::commandChanged, this,+ &CustomPanelEditorPopup::onCommandChanged);id++;}}@@ -389,7 +393,7 @@ void CustomPanelEditorPopup::buildEntries(QWidget* customWidget) {entry.objectName = widget->objectName();if (entry.type == Button)entry.rect = QRect(relativePos(widget, customWidget), widget->size());- else { // Sroller_Back+ else { // Scroller_Backentry.orientation =(widget->width() > widget->height()) ? Qt::Horizontal : Qt::Vertical;if (entry.orientation == Qt::Horizontal)@@ -467,18 +471,18 @@ void CustomPanelEditorPopup::onTemplateSwitched() {UiPreviewWidget* oldPreview =dynamic_cast<UiPreviewWidget*>(m_previewArea->widget());if (oldPreview) {- disconnect(oldPreview, SIGNAL(clicked(int)), this,- SLOT(onPreviewClicked(int)));- disconnect(oldPreview, SIGNAL(dropped(int, QString, bool)), this,- SLOT(onPreviewDropped(int, QString, bool)));+ disconnect(oldPreview, &UiPreviewWidget::clicked, this,+ &CustomPanelEditorPopup::onPreviewClicked);+ disconnect(oldPreview, &UiPreviewWidget::dropped, this,+ &CustomPanelEditorPopup::onPreviewDropped);}delete m_previewArea->widget();}- connect(previewWidget, SIGNAL(clicked(int)), this,- SLOT(onPreviewClicked(int)));- connect(previewWidget, SIGNAL(dropped(int, QString, bool)), this,- SLOT(onPreviewDropped(int, QString, bool)));+ connect(previewWidget, &UiPreviewWidget::clicked, this,+ &CustomPanelEditorPopup::onPreviewClicked);+ connect(previewWidget, &UiPreviewWidget::dropped, this,+ &CustomPanelEditorPopup::onPreviewDropped);m_previewArea->setWidget(previewWidget);previewWidget->onViewerResize(m_previewArea->size());@@ -585,7 +589,7 @@ void CustomPanelEditorPopup::replaceObjectNames(QDomElement& element) {while (!n.isNull()) {if (n.isElement()) {QDomElement e = n.toElement();- // �������g���`�F�b�N+ // check selfif (e.tagName() == "widget" && e.hasAttribute("name")) {QString objName = e.attribute("name");QList<int> entryIds = entryIdByObjName(objName);@@ -746,20 +750,18 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()m_buttonLayout->addSpacing(10);m_buttonLayout->addWidget(cancelButton, 0);- bool ret = true;- ret = ret && connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));- ret = ret && connect(m_templateCombo, SIGNAL(currentIndexChanged(int)), this,- SLOT(onTemplateSwitched()));- ret = ret &&- connect(registerButton, SIGNAL(clicked()), this, SLOT(onRegister()));- ret = ret && connect(searchEdit, SIGNAL(textChanged(const QString&)), this,- SLOT(onSearchTextChanged(const QString&)));- assert(ret);+ connect(cancelButton, &QPushButton::clicked, this,+ &CustomPanelEditorPopup::close);+ connect(m_templateCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),+ this, &CustomPanelEditorPopup::onTemplateSwitched);+ connect(registerButton, &QPushButton::clicked, this,+ &CustomPanelEditorPopup::onRegister);+ connect(searchEdit, &QLineEdit::textChanged, this,+ &CustomPanelEditorPopup::onSearchTextChanged);// load templatebool ok = loadTemplateList();if (!ok) {- // show some warning?}}@@ -776,4 +778,4 @@ void CustomPanelEditorPopup::onSearchTextChanged(const QString& text) {//-----------------------------------------------------------------------------OpenPopupCommandHandler<CustomPanelEditorPopup> openCustomPanelEditorPopup(- MI_CustomPanelEditor);\ No newline at end of file+ MI_CustomPanelEditor);diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cppindex 7f304d0af..4cd74ba34 100644--- a/toonz/sources/toonz/preferencespopup.cpp+++ b/toonz/sources/toonz/preferencespopup.cpp@@ -104,12 +104,10 @@ SizeField::SizeField(QSize min, QSize max, QSize value, QWidget* parent)lay->addStretch(1);setLayout(lay);- bool ret = true;- ret = ret && connect(m_fieldX, SIGNAL(editingFinished()), this,- SIGNAL(editingFinished()));- ret = ret && connect(m_fieldY, SIGNAL(editingFinished()), this,- SIGNAL(editingFinished()));- assert(ret);+ connect(m_fieldX, &DVGui::IntLineEdit::editingFinished, this,+ &SizeField::editingFinished);+ connect(m_fieldY, &DVGui::IntLineEdit::editingFinished, this,+ &SizeField::editingFinished);}QSize SizeField::getValue() const {@@ -170,11 +168,8 @@ PreferencesPopup::FormatProperties::FormatProperties(PreferencesPopup* parent)gridLayout->addWidget(dpiLabel, row, 0, Qt::AlignRight);m_dpi = new DVGui::DoubleLineEdit;- m_dpi->setRange(1, (std::numeric_limits<double>::max)()); // Tried- // limits::min(),- // but input 0 was- gridLayout->addWidget(m_dpi, row++,- 1); // then replaced with something * e^-128+ m_dpi->setRange(1, (std::numeric_limits<double>::max)());+ gridLayout->addWidget(m_dpi, row++, 1);m_premultiply = new DVGui::CheckBox(LevelSettingsPopup::tr("Premultiply"));gridLayout->addWidget(m_premultiply, row++, 1);@@ -191,9 +186,8 @@ PreferencesPopup::FormatProperties::FormatProperties(PreferencesPopup* parent)new QLabel(LevelSettingsPopup::tr("Antialias Softness:"));gridLayout->addWidget(antialiasLabel, row, 0, Qt::AlignRight);- m_antialias = new DVGui::IntLineEdit(- this, 10, 0, 100); // Tried 1, but then m_doAntialias was forcedly- gridLayout->addWidget(m_antialias, row++, 1); // initialized to true+ m_antialias = new DVGui::IntLineEdit(this, 10, 0, 100);+ gridLayout->addWidget(m_antialias, row++, 1);QLabel* subsamplingLabel = new QLabel(LevelSettingsPopup::tr("Subsampling:"));gridLayout->addWidget(subsamplingLabel, row, 0, Qt::AlignRight);@@ -213,20 +207,13 @@ PreferencesPopup::FormatProperties::FormatProperties(PreferencesPopup* parent)endVLayout();// Establish connections- bool ret = true;-// enable gamma field only when the regexp field contains ".exr"- ret = connect(m_regExp, SIGNAL(editingFinished()),- SLOT(updateEnabledStatus())) &&- ret;- ret = connect(m_dpiPolicy, SIGNAL(currentIndexChanged(int)),- SLOT(updateEnabledStatus())) &&- ret;- ret =- connect(m_doAntialias, SIGNAL(clicked()), SLOT(updateEnabledStatus())) &&- ret;-- assert(ret);+ connect(m_regExp, &DVGui::LineEdit::editingFinished, this,+ &FormatProperties::updateEnabledStatus);+ connect(m_dpiPolicy, QOverload<int>::of(&QComboBox::currentIndexChanged),+ this, &FormatProperties::updateEnabledStatus);+ connect(m_doAntialias, &QAbstractButton::clicked, this,+ &FormatProperties::updateEnabledStatus);}//-----------------------------------------------------------------------------@@ -315,10 +302,11 @@ PreferencesPopup::AdditionalStyleEdit::AdditionalStyleEdit(addButtonBarWidget(okButton, applyButton, closeButton);- bool ret = true;- ret = ret && connect(okButton, SIGNAL(pressed()), this, SLOT(onOK()));- ret = ret && connect(applyButton, SIGNAL(pressed()), this, SLOT(onApply()));- ret = ret && connect(closeButton, SIGNAL(pressed()), this, SLOT(close()));+ connect(okButton, &QPushButton::pressed, this, &AdditionalStyleEdit::onOK);+ connect(applyButton, &QPushButton::pressed, this,+ &AdditionalStyleEdit::onApply);+ connect(closeButton, &QPushButton::pressed, this,+ &AdditionalStyleEdit::close);}void PreferencesPopup::AdditionalStyleEdit::showEvent(QShowEvent*) {@@ -410,7 +398,7 @@ PreferencesPopup::Display30bitChecker::Display30bitChecker(setLayout(lay);lay->setSizeConstraint(QLayout::SetFixedSize);- connect(closeBtn, SIGNAL(clicked()), this, SLOT(accept()));+ connect(closeBtn, &QPushButton::clicked, this, &Display30bitChecker::accept);}PreferencesPopup::Display30bitChecker::~Display30bitChecker() {@@ -772,8 +760,8 @@ void PreferencesPopup::onOnionColorChanged() {//------------------------------------------------------------------------------void invalidateIcons(); // implemented in sceneviewer.cpp; in which fucking- // header I can put this declaration?!+void invalidateIcons(); // TODO: Find the appropriate header for this+ // declarationvoid PreferencesPopup::onTranspCheckDataChanged() { invalidateIcons(); }@@ -829,9 +817,8 @@ void PreferencesPopup::onEditAdditionalStyleSheet() {if (!m_additionalStyleEdit) {m_additionalStyleEdit = new AdditionalStyleEdit(this);- bool ret = connect(m_additionalStyleEdit, SIGNAL(additionalSheetEdited()),- this, SLOT(onAdditionalStyleSheetEdited()));- assert(ret);+ connect(m_additionalStyleEdit, &AdditionalStyleEdit::additionalSheetEdited,+ this, &PreferencesPopup::onAdditionalStyleSheetEdited);}m_additionalStyleEdit->show();}@@ -920,9 +907,8 @@ void PreferencesPopup::onEditLevelFormat() {if (!m_formatProperties) {m_formatProperties = new FormatProperties(this);- bool ret = connect(m_formatProperties, SIGNAL(dialogClosed()),- SLOT(onLevelFormatEdited()));- assert(ret);+ connect(m_formatProperties, &FormatProperties::dialogClosed, this,+ &PreferencesPopup::onLevelFormatEdited);}const Preferences::LevelFormat& lf =@@ -978,13 +964,12 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,PreferencesItem item = m_pref->getItem(id);// create widget depends on the parameter typesQWidget* widget = nullptr;- bool ret = false;switch (item.type) {case QMetaType::Bool: // create CheckBox{CheckBox* cb = new CheckBox(getUIString(id), this);cb->setChecked(item.value.toBool());- ret = connect(cb, SIGNAL(stateChanged(int)), this, SLOT(onChange()));+ connect(cb, &CheckBox::stateChanged, this, &PreferencesPopup::onChange);widget = cb;} break;@@ -994,14 +979,14 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,for (const ComboBoxItem& item : comboItems)combo->addItem(item.first, item.second);combo->setCurrentIndex(combo->findData(item.value));- ret = connect(combo, SIGNAL(currentIndexChanged(int)), this,- SLOT(onChange()));+ connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,+ &PreferencesPopup::onChange);widget = combo;} else { // create IntLineEdit- assert(item.max.toInt() != -1);DVGui::IntLineEdit* field = new DVGui::IntLineEdit(this, item.value.toInt(), item.min.toInt(), item.max.toInt());- ret = connect(field, SIGNAL(editingFinished()), this, SLOT(onChange()));+ connect(field, &DVGui::IntLineEdit::editingFinished, this,+ &PreferencesPopup::onChange);widget = field;}break;@@ -1012,7 +997,8 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,// dpi fieldDoubleLineEdit* field = new DoubleLineEdit(this, item.value.toDouble());field->setRange(item.min.toDouble(), item.max.toDouble());- ret = connect(field, SIGNAL(valueChanged()), this, SLOT(onChange()));+ connect(field, &DoubleLineEdit::valueChanged, this,+ &PreferencesPopup::onChange);widget = field;} else {MeasuredDoubleLineEdit* field = new MeasuredDoubleLineEdit(this);@@ -1022,7 +1008,8 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,elsefield->setMeasure((id == DefLevelWidth) ? "level.lx" : "level.ly");field->setValue(item.value.toDouble());- ret = connect(field, SIGNAL(valueChanged()), this, SLOT(onChange()));+ connect(field, &MeasuredDoubleLineEdit::valueChanged, this,+ &PreferencesPopup::onChange);widget = field;}break;@@ -1031,21 +1018,24 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,if (id == interfaceFont) { // create QFontComboBoxQFontComboBox* combo = new QFontComboBox(this);combo->setCurrentText(item.value.toString());- ret = connect(combo, SIGNAL(currentIndexChanged(const QString&)), this,- SLOT(onInterfaceFontChanged(const QString&)));+ // QFontComboBox uses currentFontChanged+ connect(+ combo, &QFontComboBox::currentFontChanged, this,+ [this](const QFont& font) { onInterfaceFontChanged(font.family()); });widget = combo;} else if (!comboItems.isEmpty()) { // create QComboBoxQComboBox* combo = new QComboBox(this);for (const ComboBoxItem& item : comboItems)combo->addItem(item.first, item.second);combo->setCurrentIndex(combo->findData(item.value));- ret = connect(combo, SIGNAL(currentIndexChanged(int)), this,- SLOT(onChange()));+ connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,+ &PreferencesPopup::onChange);widget = combo;} else { // create FileFieldDVGui::FileField* field =new DVGui::FileField(this, item.value.toString());- ret = connect(field, SIGNAL(pathChanged()), this, SLOT(onChange()));+ connect(field, &FileField::pathChanged, this,+ &PreferencesPopup::onChange);widget = field;}break;@@ -1054,7 +1044,8 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,{SizeField* field = new SizeField(item.min.toSize(), item.max.toSize(),item.value.toSize(), this);- ret = connect(field, SIGNAL(editingFinished()), this, SLOT(onChange()));+ connect(field, &SizeField::editingFinished, this,+ &PreferencesPopup::onChange);widget = field;} break;@@ -1062,14 +1053,13 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,{ColorField* field =new ColorField(this, false, colorToTPixel(item.value.value<QColor>()));- ret = connect(field, SIGNAL(colorChanged(const TPixel32&, bool)), this,- SLOT(onColorFieldChanged(const TPixel32&, bool)));+ connect(field, &ColorField::colorChanged, this,+ &PreferencesPopup::onColorFieldChanged);widget = field;} break;case QMetaType::QVariantMap: // used in colorCalibrationLutPaths{- assert(id == colorCalibrationLutPaths);DVGui::FileField* field = new DVGui::FileField(this, QString("- Please specify 3DLUT file (.3dl) -"), false, true);QString lutPath = m_pref->getColorCalibrationLutPath(@@ -1078,16 +1068,19 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,field->setFileMode(QFileDialog::ExistingFile);QStringList lutFileTypes = {"3dl"};field->setFilters(lutFileTypes);- ret = connect(field, SIGNAL(pathChanged()), this, SLOT(onLutPathChanged()));+ connect(field, &FileField::pathChanged, this,+ &PreferencesPopup::onLutPathChanged);widget = field;} break;default:- std::cout << "unsupported value type" << std::endl;+ qWarning() << "unsupported value type for preference item" << id;break;}- assert(ret);- m_controlIdMap[widget] = id;++ if (widget) {+ m_controlIdMap[widget] = id;+ }return widget;}@@ -1096,8 +1089,7 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,QGridLayout* PreferencesPopup::insertGroupBoxUI(PreferencesItemId id,QGridLayout* layout) {PreferencesItem item = m_pref->getItem(id);- assert(item.type == QMetaType::Bool);- QGroupBox* box = new QGroupBox(getUIString(id), this);+ QGroupBox* box = new QGroupBox(getUIString(id), this);box->setCheckable(true);box->setChecked(item.value.toBool());@@ -1107,10 +1099,7 @@ QGridLayout* PreferencesPopup::insertGroupBoxUI(PreferencesItemId id,layout->addWidget(box, layout->rowCount(), 0, 1, 3);- bool ret = connect(box, SIGNAL(clicked(bool)), this, SLOT(onChange()));- // bool ret = connect(box, SIGNAL(clicked(bool)), this,- // SLOT(onGroupBoxChanged(bool)));- assert(ret);+ connect(box, &QGroupBox::clicked, this, &PreferencesPopup::onChange);m_controlIdMap[box] = id;return lay;}@@ -1322,7 +1311,7 @@ QString PreferencesPopup::getUIString(PreferencesItemId id) {{FillOnlysavebox, tr("Use the TLV Savebox to Limit Filling Operations")},{DefRegionWithPaint,tr("Define Filling Region Using both Lines and Areas")},- { ReferFillPrevailing, tr("Paint Under Lines in Refer Fill") },+ {ReferFillPrevailing, tr("Paint Under Lines in Refer Fill")},{multiLayerStylePickerEnabled,tr("Style Picker: Switch Current Level by Picking on Multi Layer")},{cursorBrushType, tr("Basic Cursor Type:")},@@ -1425,9 +1414,7 @@ QString PreferencesPopup::getUIString(PreferencesItemId id) {tr("Check for the Latest Version of OpenToonz on Launch")},// Touch / Tablet Settings- // TounchGestureControl // Touch Gesture is a checkable command and not- // in- // preferences.ini+ // Touch Gesture is a checkable command and not in preferences.ini{winInkEnabled, tr("Enable Windows Ink Support* (EXPERIMENTAL)")},{useQtNativeWinInk,tr("Use Qt's Native Windows Ink Support*\n(CAUTION: This options is "@@ -1554,15 +1541,23 @@ QList<ComboBoxItem> PreferencesPopup::getComboItemList({tr("File"), 8}}},{animatedGuidedDrawing,{{tr("Arrow Markers"), 0}, {tr("Animated Guide"), 1}}}};- assert(comboItemsTable.contains(id));+return comboItemsTable.value(id, QList<ComboBoxItem>());}template <typename T>inline T PreferencesPopup::getUI(PreferencesItemId id) {- assert(m_controlIdMap.keys(id).count() == 1);- T ret = dynamic_cast<T>(m_controlIdMap.key(id));- assert(ret);+ // Preference IDs can be missing if the UI was not fully initialized+ QWidget* widget = m_controlIdMap.key(id);+ if (!widget) {+ qWarning() << "Widget not found for preference item:" << id;+ return nullptr;+ }++ T ret = qobject_cast<T>(widget);+ if (!ret) {+ qWarning() << "Widget cast failed for preference item:" << id;+ }return ret;}@@ -1629,10 +1624,8 @@ PreferencesPopup::PreferencesPopup()setWindowFlags(Qt::Tool);#endif- bool ret = connect(categoryList, SIGNAL(currentRowChanged(int)),- stackedWidget, SLOT(setCurrentIndex(int)));-- assert(ret);+ connect(categoryList, &QListWidget::currentRowChanged, stackedWidget,+ &QStackedWidget::setCurrentIndex);}//-----------------------------------------------------------------------------@@ -1706,15 +1699,19 @@ QWidget* PreferencesPopup::createGeneralPage() {QCheckBox* lazyLoadRoomsCheckBox = getUI<QCheckBox*>(lazyLoadRooms);connect(lazyLoadRoomsCheckBox, &QCheckBox::stateChanged,[lazyLoadRoomsCheckBox](int state) {- QString status = Preferences::instance()->isLazyLoadRoomsEnabled()- ? tr("enabled") : tr("disabled");- QString description = Preferences::instance()->isLazyLoadRoomsEnabled()- ? tr("rooms will load on demand")- : tr("all rooms load at startup");- QString lazyLoadRoomsToolTip = tr("Lazy loading %1 - %2").arg(status).arg(description);- lazyLoadRoomsCheckBox->setToolTip(lazyLoadRoomsToolTip);+ QString status = Preferences::instance()->isLazyLoadRoomsEnabled()+ ? tr("enabled")+ : tr("disabled");+ QString description =+ Preferences::instance()->isLazyLoadRoomsEnabled()+ ? tr("rooms will load on demand")+ : tr("all rooms load at startup");+ QString lazyLoadRoomsToolTip =+ tr("Lazy loading %1 - %2").arg(status).arg(description);+ lazyLoadRoomsCheckBox->setToolTip(lazyLoadRoomsToolTip);});- lazyLoadRoomsCheckBox->stateChanged(Preferences::instance()->isLazyLoadRoomsEnabled());+ lazyLoadRoomsCheckBox->stateChanged(+ Preferences::instance()->isLazyLoadRoomsEnabled());m_onEditedFuncMap.insert(autosaveEnabled,&PreferencesPopup::onAutoSaveChanged);@@ -1727,24 +1724,21 @@ QWidget* PreferencesPopup::createGeneralPage() {m_onEditedFuncMap.insert(pathAliasPriority,&PreferencesPopup::onPathAliasPriorityChanged);- bool ret = true;-- ret = ret && connect(m_pref, SIGNAL(stopAutoSave()), this,- SLOT(onAutoSaveExternallyChanged()));- ret = ret && connect(m_pref, SIGNAL(startAutoSave()), this,- SLOT(onAutoSaveExternallyChanged()));- ret = ret && connect(m_pref, SIGNAL(autoSavePeriodChanged()), this,- SLOT(onAutoSavePeriodExternallyChanged()));-- ret = ret && connect(m_projectRootDocuments, SIGNAL(stateChanged(int)),- SLOT(onProjectRootChanged()));- ret = ret && connect(m_projectRootDesktop, SIGNAL(stateChanged(int)),- SLOT(onProjectRootChanged()));- ret = ret && connect(m_projectRootCustom, SIGNAL(stateChanged(int)),- SLOT(onProjectRootChanged()));- ret = ret && connect(m_projectRootCustom, SIGNAL(clicked(bool)), customField,- SLOT(setVisible(bool)));- assert(ret);+ connect(m_pref, &Preferences::stopAutoSave, this,+ &PreferencesPopup::onAutoSaveExternallyChanged);+ connect(m_pref, &Preferences::startAutoSave, this,+ &PreferencesPopup::onAutoSaveExternallyChanged);+ connect(m_pref, &Preferences::autoSavePeriodChanged, this,+ &PreferencesPopup::onAutoSavePeriodExternallyChanged);++ connect(m_projectRootDocuments, &QCheckBox::stateChanged, this,+ &PreferencesPopup::onProjectRootChanged);+ connect(m_projectRootDesktop, &QCheckBox::stateChanged, this,+ &PreferencesPopup::onProjectRootChanged);+ connect(m_projectRootCustom, &QCheckBox::stateChanged, this,+ &PreferencesPopup::onProjectRootChanged);+ connect(m_projectRootCustom, &QCheckBox::clicked, customField,+ &QWidget::setVisible);return widget;}@@ -1760,7 +1754,7 @@ QWidget* PreferencesPopup::createInterfacePage() {}QList<ComboBoxItem> roomItemList;- foreach (QString roomName, m_pref->getRoomMap())+ for (const QString& roomName : m_pref->getRoomMap())roomItemList.push_back(ComboBoxItem(roomName, roomName));QList<ComboBoxItem> languageItemList;@@ -1798,9 +1792,7 @@ QWidget* PreferencesPopup::createInterfacePage() {->setSizeAdjustPolicy(QComboBox::AdjustToContents);QGridLayout* colorCalibLay = insertGroupBoxUI(colorCalibrationEnabled, lay);- {- insertUI(colorCalibrationLutPaths, colorCalibLay);- }+ { insertUI(colorCalibrationLutPaths, colorCalibLay); }insertUI(displayIn30bit, lay);row = lay->rowCount();lay->addWidget(check30bitBtn, row - 1, 2, Qt::AlignRight);@@ -1816,15 +1808,12 @@ QWidget* PreferencesPopup::createInterfacePage() {}// pixels unit may deactivated externally on loading scene (see// IoCmd::loadScene())- bool ret = true;- ret = ret && connect(TApp::instance()->getCurrentScene(),- SIGNAL(pixelUnitSelected(bool)), this,- SLOT(onPixelUnitExternallySelected(bool)));- ret = ret && connect(additionalStyleSheetBtn, SIGNAL(clicked()), this,- SLOT(onEditAdditionalStyleSheet()));- ret = ret && connect(check30bitBtn, SIGNAL(clicked()), this,- SLOT(onCheck30bitDisplay()));- assert(ret);+ connect(TApp::instance()->getCurrentScene(), &TSceneHandle::pixelUnitSelected,+ this, &PreferencesPopup::onPixelUnitExternallySelected);+ connect(additionalStyleSheetBtn, &QPushButton::clicked, this,+ &PreferencesPopup::onEditAdditionalStyleSheet);+ connect(check30bitBtn, &QPushButton::clicked, this,+ &PreferencesPopup::onCheck30bitDisplay);m_onEditedFuncMap.insert(CurrentStyleSheetName,&PreferencesPopup::onStyleSheetTypeChanged);@@ -1878,9 +1867,7 @@ QWidget* PreferencesPopup::createLoadingPage() {insertUI(renamePolicy, lay, getComboItemList(renamePolicy));insertUI(convertPolicy, lay, getComboItemList(convertPolicy));QGridLayout* autoExposeLay = insertGroupBoxUI(autoExposeEnabled, lay);- {- insertUI(autoRemoveUnusedLevels, autoExposeLay);- }+ { insertUI(autoRemoveUnusedLevels, autoExposeLay); }insertUI(subsceneFolderEnabled, lay);insertUI(removeSceneNumberFromLoadedLevelName, lay);insertUI(IgnoreImageDpi, lay);@@ -1908,23 +1895,21 @@ QWidget* PreferencesPopup::createLoadingPage() {lay->setRowStretch(lay->rowCount(), 1);widget->setLayout(lay);- bool ret = true;- ret = ret &&- connect(addLevelFormat, SIGNAL(clicked()), SLOT(onAddLevelFormat()));- ret = ret && connect(removeLevelFormat, SIGNAL(clicked()),- SLOT(onRemoveLevelFormat()));- ret = ret && connect(m_editLevelFormat, SIGNAL(clicked()),- SLOT(onEditLevelFormat()));- ret = ret && connect(TApp::instance()->getCurrentScene(),- SIGNAL(importPolicyChanged(int)), this,- SLOT(onImportPolicyExternallyChanged(int)));- ret = ret && connect(TApp::instance()->getCurrentScene(),- SIGNAL(convertPolicyChanged(int)), this,- SLOT(onConvertPolicyExternallyChanged(int)));- ret = ret && connect(TApp::instance()->getCurrentScene(),- SIGNAL(renamePolicyChanged(int)), this,- SLOT(onRenamePolicyExternallyChanged(int)));- assert(ret);+ connect(addLevelFormat, &QPushButton::clicked, this,+ &PreferencesPopup::onAddLevelFormat);+ connect(removeLevelFormat, &QPushButton::clicked, this,+ &PreferencesPopup::onRemoveLevelFormat);+ connect(m_editLevelFormat, &QPushButton::clicked, this,+ &PreferencesPopup::onEditLevelFormat);+ connect(TApp::instance()->getCurrentScene(),+ &TSceneHandle::importPolicyChanged, this,+ &PreferencesPopup::onImportPolicyExternallyChanged);+ connect(TApp::instance()->getCurrentScene(),+ &TSceneHandle::convertPolicyChanged, this,+ &PreferencesPopup::onConvertPolicyExternallyChanged);+ connect(TApp::instance()->getCurrentScene(),+ &TSceneHandle::renamePolicyChanged, this,+ &PreferencesPopup::onRenamePolicyExternallyChanged);return widget;}@@ -1943,9 +1928,7 @@ QWidget* PreferencesPopup::createSavingPage() {insertUI(autosaveOtherFilesEnabled, autoSaveLay);}QGridLayout* backupLay = insertGroupBoxUI(backupEnabled, lay);- {- insertUI(backupKeepCount, backupLay);- }+ { insertUI(backupKeepCount, backupLay); }insertUI(replaceAfterSaveLevelAs, lay);insertUI(resetUndoOnSavingLevel, lay);@@ -2153,7 +2136,7 @@ QWidget* PreferencesPopup::createXsheetPage() {insertUI(deleteCommandBehavior, lay, getComboItemList(deleteCommandBehavior));insertUI(pasteCellsBehavior, lay, getComboItemList(pasteCellsBehavior));insertUI(cellInputMethod, lay, getComboItemList(cellInputMethod));-+QGridLayout* xshColHeaderLay = insertGroupBox(tr("Xsheet Column Area"), lay);{insertUI(linkColumnNameWithLevel, xshColHeaderLay);@@ -2487,12 +2470,10 @@ QWidget* PreferencesPopup::createTouchTabletPage() {if (winInkAvailable) insertFootNote(lay);widget->setLayout(lay);- bool ret = true;- ret = ret && connect(enableTouchGestures, SIGNAL(clicked(bool)), touchAction,- SLOT(setChecked(bool)));- ret = ret && connect(touchAction, SIGNAL(triggered(bool)),- enableTouchGestures, SLOT(setChecked(bool)));- assert(ret);+ connect(enableTouchGestures, &CheckBox::clicked, touchAction,+ &QAction::setChecked);+ connect(touchAction, &QAction::triggered, enableTouchGestures,+ &CheckBox::setChecked);return widget;}diff --git a/toonz/sources/toonz/xdtsio.cpp b/toonz/sources/toonz/xdtsio.cppindex 953fc2a98..8a32459f2 100644--- a/toonz/sources/toonz/xdtsio.cpp+++ b/toonz/sources/toonz/xdtsio.cpp@@ -1,3 +1,5 @@++#include "xdtsio.h"#include "tsystem.h"@@ -26,7 +28,7 @@#include <iostream>#include <QJsonObject>#include <QJsonArray>-#include <QRegExp>+#include <QRegularExpression>#include <QFile>#include <QJsonDocument>#include <QApplication>@@ -58,18 +60,20 @@ const QString OPTION_REFERENCEFRAME = "OPTION_REFERENCEFRAME";} // namespace//-----------------------------------------------------------------------------void XdtsHeader::read(const QJsonObject &json) {- QRegExp rx("\\d{1,4}");+ QRegularExpression rx("^\\d{1,4}$");// TODO: We could check if the keys are valid// before attempting to read them with QJsonObject::contains(),// but we assume that they are.m_cut = json["cut"].toString();- if (!rx.exactMatch(m_cut)) // TODO: should handle an error- std::cout << "The XdtsHeader value \"cut\" does not match the pattern."- << std::endl;+ if (!rx.match(m_cut).hasMatch()) // TODO: should handle an error+ qWarning()+ << "The XdtsHeader value 'cut' value does not match expected pattern:"+ << m_cut;m_scene = json["scene"].toString();- if (!rx.exactMatch(m_scene))- std::cout << "The XdtsHeader value \"scene\" does not match the pattern."- << std::endl;+ if (!rx.match(m_scene).hasMatch())+ qWarning()+ << "The XdtsHeader value 'scene' value does not match expected pattern:"+ << m_scene;}void XdtsHeader::write(QJsonObject &json) const {@@ -86,13 +90,14 @@ TFrameId XdtsFrameDataItem::str2Fid(const QString &str) const {if (ok) return TFrameId(frame);QString regExpStr = QString("^%1$").arg(TFilePath::fidRegExpStr());- QRegExp rx(regExpStr);- int pos = rx.indexIn(str);- if (pos < 0) return TFrameId();- if (rx.cap(2).isEmpty())- return TFrameId(rx.cap(1).toInt());+ QRegularExpression rx(regExpStr);+ QRegularExpressionMatch match = rx.match(str);+ if (!match.hasMatch()) return TFrameId();++ if (match.captured(2).isEmpty())+ return TFrameId(match.captured(1).toInt());else- return TFrameId(rx.cap(1).toInt(), rx.cap(2));+ return TFrameId(match.captured(1).toInt(), match.captured(2));}QString XdtsFrameDataItem::fid2Str(const TFrameId &fid) const {@@ -110,13 +115,13 @@ QString XdtsFrameDataItem::fid2Str(const TFrameId &fid) const {void XdtsFrameDataItem::read(const QJsonObject &json) {m_id = DataId(qRound(json["id"].toDouble()));QJsonArray valuesArray = json["values"].toArray();- for (int vIndex = 0; vIndex < valuesArray.size(); ++vIndex) {- m_values.append(valuesArray[vIndex].toString());+ for (const QJsonValue &value : valuesArray) {+ m_values.append(value.toString());}if (json.contains("options")) {QJsonArray optionsArray = json["options"].toArray();- for (int vIndex = 0; vIndex < optionsArray.size(); ++vIndex) {- m_options.append(optionsArray[vIndex].toString());+ for (const QJsonValue &option : optionsArray) {+ m_options.append(option.toString());}}}@@ -124,14 +129,14 @@ void XdtsFrameDataItem::read(const QJsonObject &json) {void XdtsFrameDataItem::write(QJsonObject &json) const {json["id"] = int(m_id);QJsonArray valuesArray;- foreach (const QString &value, m_values) {+ for (const QString &value : m_values) {valuesArray.append(value);}json["values"] = valuesArray;if (!m_options.isEmpty()) {QJsonArray optionsArray;- foreach (const QString &option, m_options) {+ for (const QString &option : m_options) {optionsArray.append(option);}json["options"] = optionsArray;@@ -171,7 +176,7 @@ void XdtsTrackFrameItem::read(const QJsonObject &json) {void XdtsTrackFrameItem::write(QJsonObject &json) const {QJsonArray dataArray;- foreach (const XdtsFrameDataItem &data, m_data) {+ for (const XdtsFrameDataItem &data : m_data) {QJsonObject dataObject;data.write(dataObject);dataArray.append(dataObject);@@ -203,7 +208,7 @@ void XdtsFieldTrackItem::read(const QJsonObject &json) {void XdtsFieldTrackItem::write(QJsonObject &json) const {QJsonArray frameArray;- foreach (const XdtsTrackFrameItem &frame, m_frames) {+ for (const XdtsTrackFrameItem &frame : m_frames) {QJsonObject frameObject;frame.write(frameObject);frameArray.append(frameObject);@@ -330,7 +335,7 @@ void XdtsTimeTableFieldItem::read(const QJsonObject &json) {void XdtsTimeTableFieldItem::write(QJsonObject &json) const {json["fieldId"] = int(m_fieldId);QJsonArray trackArray;- foreach (const XdtsFieldTrackItem &track, m_tracks) {+ for (const XdtsFieldTrackItem &track : m_tracks) {QJsonObject trackObject;track.write(trackObject);trackArray.append(trackObject);@@ -393,7 +398,7 @@ void XdtsTimeTableHeaderItem::read(const QJsonObject &json) {void XdtsTimeTableHeaderItem::write(QJsonObject &json) const {json["fieldId"] = int(m_fieldId);QJsonArray namesArray;- foreach (const QString name, m_names) {+ for (const QString &name : m_names) {namesArray.append(name);}json["names"] = namesArray;@@ -431,7 +436,7 @@ void XdtsTimeTableItem::read(const QJsonObject &json) {void XdtsTimeTableItem::write(QJsonObject &json) const {if (!m_fields.isEmpty()) {QJsonArray fieldArray;- foreach (const XdtsTimeTableFieldItem &field, m_fields) {+ for (const XdtsTimeTableFieldItem &field : m_fields) {QJsonObject fieldObject;field.write(fieldObject);fieldArray.append(fieldObject);@@ -441,7 +446,7 @@ void XdtsTimeTableItem::write(QJsonObject &json) const {json["duration"] = m_duration;json["name"] = m_name;QJsonArray headerArray;- foreach (const XdtsTimeTableHeaderItem header, m_timeTableHeaders) {+ for (const XdtsTimeTableHeaderItem &header : m_timeTableHeaders) {QJsonObject headerObject;header.write(headerObject);headerArray.append(headerObject);@@ -508,7 +513,7 @@ void XdtsData::write(QJsonObject &json) const {json["header"] = headerObject;}QJsonArray tableArray;- foreach (const XdtsTimeTableItem &table, m_timeTables) {+ for (const XdtsTimeTableItem &table : m_timeTables) {QJsonObject tableObject;table.write(tableObject);tableArray.append(tableObject);@@ -562,8 +567,7 @@ bool XdtsIo::loadXdtsScene(ToonzScene *scene, const TFilePath &scenePath) {QStringList levelNames = xdtsData.getLevelNames();// in case multiple columns have the same namelevelNames.removeDuplicates();- for (auto& name : levelNames)- name = name.trimmed();+ for (auto &name : levelNames) name = name.trimmed();scene->clear();@@ -703,12 +707,12 @@ void ExportXDTSCommand::execute() {duration = xsheet->getFrameCount();{- _tick1Id = -1;- _tick2Id = -1;- _keyFrameId = -1;- _tick2Id = -1;- _exportAllColumn = true;- _isUextVersion = false;+ _tick1Id = -1;+ _tick2Id = -1;+ _keyFrameId = -1;+ _referenceFrameId = -1;+ _exportAllColumn = true;+ _isUextVersion = false;XdtsData pre_xdtsData;pre_xdtsData.build(xsheet, QString::fromStdString(fp.getName()), duration);if (pre_xdtsData.isEmpty()) {@@ -747,7 +751,7 @@ void ExportXDTSCommand::execute() {if (!savePopup) {// create custom widget- QWidget *custonWidget = new QWidget();+ QWidget *customWidget = new QWidget();tick1Id = new QComboBox();tick2Id = new QComboBox();keyFrameId = new QComboBox();@@ -821,10 +825,10 @@ void ExportXDTSCommand::execute() {}customLay->addLayout(bottomLay);}- custonWidget->setLayout(customLay);+ customWidget->setLayout(customLay);savePopup = new GenericSaveFilePopup(- QObject::tr("Export Exchange Digital Time Sheet (XDTS)"), custonWidget);+ QObject::tr("Export Exchange Digital Time Sheet (XDTS)"), customWidget);savePopup->addFilterType("xdts");} else {refreshCellMarkComboItems(tick1Id);