Refactoring.

This commit is contained in:
Roman Telezhynskyi 2023-01-02 14:20:00 +02:00
parent cfe341e7b9
commit c9b9a3fb66
2 changed files with 18 additions and 21 deletions

View File

@ -56,8 +56,7 @@ DialogEditLabel::DialogEditLabel(const VAbstractPattern *doc, const VContainer *
ui(new Ui::DialogEditLabel), ui(new Ui::DialogEditLabel),
m_placeholdersMenu(new QMenu(this)), m_placeholdersMenu(new QMenu(this)),
m_doc(doc), m_doc(doc),
m_data(data), m_data(data)
m_placeholders()
{ {
ui->setupUi(this); ui->setupUi(this);
@ -172,10 +171,7 @@ void DialogEditLabel::RemoveLine()
{ {
ui->listWidgetEdit->blockSignals(true); ui->listWidgetEdit->blockSignals(true);
QListWidgetItem *curLine = ui->listWidgetEdit->takeItem(ui->listWidgetEdit->currentRow()); QListWidgetItem *curLine = ui->listWidgetEdit->takeItem(ui->listWidgetEdit->currentRow());
if (curLine) delete curLine;
{
delete curLine;
}
ui->listWidgetEdit->blockSignals(false); ui->listWidgetEdit->blockSignals(false);
ShowLineDetails(); ShowLineDetails();
} }
@ -198,7 +194,7 @@ void DialogEditLabel::SaveFontStyle(bool checked)
{ {
QFont lineFont = curLine->font(); QFont lineFont = curLine->font();
QToolButton *button = qobject_cast<QToolButton *>(sender()); auto *button = qobject_cast<QToolButton *>(sender());
if (button) if (button)
{ {
if (button == ui->toolButtonBold) if (button == ui->toolButtonBold)
@ -221,7 +217,7 @@ void DialogEditLabel::SaveTextFormating(bool checked)
QListWidgetItem *curLine = ui->listWidgetEdit->currentItem(); QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
if (curLine) if (curLine)
{ {
QToolButton *button = qobject_cast<QToolButton *>(sender()); auto *button = qobject_cast<QToolButton *>(sender());
if (button) if (button)
{ {
ui->toolButtonTextLeft->blockSignals(true); ui->toolButtonTextLeft->blockSignals(true);
@ -327,7 +323,7 @@ void DialogEditLabel::ExportTemplate()
QString error; QString error;
const bool result = ltemplate.SaveDocument(fileName, error); const bool result = ltemplate.SaveDocument(fileName, error);
if (result == false) if (not result)
{ {
QMessageBox messageBox(this); QMessageBox messageBox(this);
messageBox.setIcon(QMessageBox::Warning); messageBox.setIcon(QMessageBox::Warning);
@ -381,7 +377,7 @@ void DialogEditLabel::ImportTemplate()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::InsertPlaceholder() void DialogEditLabel::InsertPlaceholder()
{ {
QAction *action = qobject_cast<QAction *>(sender()); auto *action = qobject_cast<QAction *>(sender());
if (action) if (action)
{ {
ui->lineEditLine->insert(action->data().toString()); ui->lineEditLine->insert(action->data().toString());
@ -549,7 +545,7 @@ void DialogEditLabel::InitPlaceholders()
m_placeholders.insert(pl_email, qMakePair(tr("Customer email"), m_doc->GetCustomerEmail())); m_placeholders.insert(pl_email, qMakePair(tr("Customer email"), m_doc->GetCustomerEmail()));
} }
m_placeholders.insert(pl_pExt, qMakePair(tr("Pattern extension"), QString("val"))); m_placeholders.insert(pl_pExt, qMakePair(tr("Pattern extension"), QStringLiteral("val")));
const QString patternFilePath = QFileInfo(VAbstractValApplication::VApp()->GetPatternPath()).baseName(); const QString patternFilePath = QFileInfo(VAbstractValApplication::VApp()->GetPatternPath()).baseName();
m_placeholders.insert(pl_pFileName, qMakePair(tr("Pattern file name"), patternFilePath)); m_placeholders.insert(pl_pFileName, qMakePair(tr("Pattern file name"), patternFilePath));
@ -686,7 +682,7 @@ void DialogEditLabel::InitPlaceholders()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogEditLabel::ReplacePlaceholders(QString line) const auto DialogEditLabel::ReplacePlaceholders(QString line) const -> QString
{ {
QChar per('%'); QChar per('%');
@ -719,9 +715,10 @@ QString DialogEditLabel::ReplacePlaceholders(QString line) const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<VLabelTemplateLine> DialogEditLabel::GetTemplate() const auto DialogEditLabel::GetTemplate() const -> QVector<VLabelTemplateLine>
{ {
QVector<VLabelTemplateLine> lines; QVector<VLabelTemplateLine> lines;
lines.reserve(ui->listWidgetEdit->count());
for (int i=0; i<ui->listWidgetEdit->count(); ++i) for (int i=0; i<ui->listWidgetEdit->count(); ++i)
{ {
@ -752,9 +749,9 @@ void DialogEditLabel::SetTemplate(const QVector<VLabelTemplateLine> &lines)
int row = -1; int row = -1;
for (auto &line : lines) for (const auto &line : lines)
{ {
QListWidgetItem *item = new QListWidgetItem(line.line); auto *item = new QListWidgetItem(line.line);
item->setTextAlignment(line.alignment); item->setTextAlignment(line.alignment);
item->setData(Qt::UserRole, line.fontSizeIncrement); item->setData(Qt::UserRole, line.fontSizeIncrement);
@ -831,9 +828,9 @@ void DialogEditLabel::InitPreviewLines(const QVector<VLabelTemplateLine> &lines)
int row = -1; int row = -1;
for (auto &line : lines) for (const auto &line : lines)
{ {
QListWidgetItem *item = new QListWidgetItem(ReplacePlaceholders(line.line)); auto *item = new QListWidgetItem(ReplacePlaceholders(line.line));
item->setTextAlignment(line.alignment); item->setTextAlignment(line.alignment);
item->setData(Qt::UserRole, line.fontSizeIncrement); item->setData(Qt::UserRole, line.fontSizeIncrement);

View File

@ -52,9 +52,9 @@ class DialogEditLabel : public QDialog
public: public:
explicit DialogEditLabel(const VAbstractPattern *doc, const VContainer *data, QWidget *parent = nullptr); explicit DialogEditLabel(const VAbstractPattern *doc, const VContainer *data, QWidget *parent = nullptr);
virtual ~DialogEditLabel(); ~DialogEditLabel() override;
QVector<VLabelTemplateLine> GetTemplate() const; auto GetTemplate() const -> QVector<VLabelTemplateLine>;
void SetTemplate(const QVector<VLabelTemplateLine> &lines); void SetTemplate(const QVector<VLabelTemplateLine> &lines);
void SetPiece(const VPiece &piece); void SetPiece(const VPiece &piece);
@ -81,14 +81,14 @@ private:
const VAbstractPattern *m_doc; const VAbstractPattern *m_doc;
const VContainer *m_data; const VContainer *m_data;
QMap<QString, QPair<QString, QString>> m_placeholders; QMap<QString, QPair<QString, QString>> m_placeholders{};
void SetupControls(); void SetupControls();
auto SortedActions() const -> QMap<QString, QString>; auto SortedActions() const -> QMap<QString, QString>;
void InitPlaceholdersMenu(); void InitPlaceholdersMenu();
void InitPlaceholders(); void InitPlaceholders();
QString ReplacePlaceholders(QString line) const; auto ReplacePlaceholders(QString line) const -> QString;
void InitPreviewLines(const QVector<VLabelTemplateLine> &lines); void InitPreviewLines(const QVector<VLabelTemplateLine> &lines);
}; };