优化了一些bad smells

dev-LayerStyle
ArgonarioD 2023-03-18 03:49:15 +08:00
parent 789d282393
commit 73719905db
2 changed files with 20 additions and 20 deletions

View File

@ -15,12 +15,12 @@ StrokeStyleWidget::StrokeStyleWidget(
QWidget* parent QWidget* parent
) : QWidget(parent), stroke(stroke) ) : QWidget(parent), stroke(stroke)
{ {
QVBoxLayout* viewLayout = new QVBoxLayout(this); auto* viewLayout = new QVBoxLayout(this);
this->setLayout(viewLayout); this->setLayout(viewLayout);
initStrokeSettings(); initStrokeSettings();
QWidget* strokeProperties = new QWidget(this); auto* strokeProperties = new QWidget(this);
QHBoxLayout* strokePropertiesLayout = new QHBoxLayout(strokeProperties); auto* strokePropertiesLayout = new QHBoxLayout(strokeProperties);
strokePropertiesLayout->setMargin(0); strokePropertiesLayout->setMargin(0);
strokeProperties->setLayout(strokePropertiesLayout); strokeProperties->setLayout(strokePropertiesLayout);
@ -72,7 +72,7 @@ void StrokeStyleWidget::initStrokeSettings()
this->widthField = new QtMaterialTextField(this); this->widthField = new QtMaterialTextField(this);
widthField->setLabel(QStringLiteral("±¾²àÃè±ß¿í¶È")); widthField->setLabel(QStringLiteral("±¾²àÃè±ß¿í¶È"));
widthField->setText(QString::number(stroke->halfWidth)); widthField->setText(QString::number(stroke->halfWidth));
QDoubleValidator* widthValidator = new QDoubleValidator(0.1, std::numeric_limits<float>::max(), 3, widthField); auto* widthValidator = new QDoubleValidator(0.1, std::numeric_limits<float>::max(), 3, widthField);
widthValidator->setNotation(QDoubleValidator::StandardNotation); widthValidator->setNotation(QDoubleValidator::StandardNotation);
widthField->setValidator(widthValidator); widthField->setValidator(widthValidator);
connect(widthField, &QtMaterialTextField::textChanged, [this](const QString& changed) { connect(widthField, &QtMaterialTextField::textChanged, [this](const QString& changed) {
@ -139,30 +139,30 @@ void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient
void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& material) void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& material)
{ {
QTableWidgetItem* widthItem = new QTableWidgetItem; auto* widthItem = new QTableWidgetItem;
widthItem->setData(Qt::EditRole, width); widthItem->setData(Qt::EditRole, width);
strokeTable->setItem(row, COLUMN_WIDTH, widthItem); strokeTable->setItem(row, COLUMN_WIDTH, widthItem);
QColor* colorPtr = &(material.color); QColor* colorPtr = &(material.color);
QTableWidgetItem* colorItem = new QTableWidgetItem; auto* colorItem = new QTableWidgetItem;
colorItem->setData(Qt::DisplayRole, *colorPtr); colorItem->setData(Qt::DisplayRole, *colorPtr);
strokeTable->setItem(row, COLUMN_COLOR, colorItem); strokeTable->setItem(row, COLUMN_COLOR, colorItem);
ColorPicker* colorPicker = new ColorPicker(*colorPtr, strokeTable); auto* colorPicker = new ColorPicker(*colorPtr, strokeTable);
strokeTable->setCellWidget(row, COLUMN_COLOR, colorPicker); strokeTable->setCellWidget(row, COLUMN_COLOR, colorPicker);
connect(colorPicker, &ColorPicker::colorChanged, [this, colorPtr](QColor color) { connect(colorPicker, &ColorPicker::colorChanged, [this, colorPtr](QColor color) {
*colorPtr = color; *colorPtr = color;
this->strokeTable->update(); this->strokeTable->update();
}); });
QTableWidgetItem* metallicItem = new QTableWidgetItem; auto* metallicItem = new QTableWidgetItem;
metallicItem->setData(Qt::EditRole, material.metallicF()); metallicItem->setData(Qt::EditRole, material.metallicF());
strokeTable->setItem(row, COLUMN_METALLIC, metallicItem); strokeTable->setItem(row, COLUMN_METALLIC, metallicItem);
QTableWidgetItem* roughnessItem = new QTableWidgetItem; auto* roughnessItem = new QTableWidgetItem;
roughnessItem->setData(Qt::EditRole, material.roughnessF()); roughnessItem->setData(Qt::EditRole, material.roughnessF());
strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem); strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", strokeTable); auto* removeButton = new QtMaterialRaisedButton("-", strokeTable);
removeButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1")); removeButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1"));
removeButton->setFixedSize(20, 20); removeButton->setFixedSize(20, 20);
strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton); strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton);

View File

@ -41,21 +41,21 @@ std::vector<Renderer::BaseStyle> StrokeElementLayerStyle::toBaseStyles() const
QWidget* StrokeElementLayerStyle::getInputWidget() QWidget* StrokeElementLayerStyle::getInputWidget()
{ {
QWidget* w = new QWidget; auto* w = new QWidget;
QListView* materialList = new QListView; auto* materialList = new QListView;
QVBoxLayout* layout = new QVBoxLayout(w); auto* layout = new QVBoxLayout(w);
layout->setMargin(0); layout->setMargin(0);
StrokeStyleWidget* leftStrokeView = new StrokeStyleWidget(this->strokePair.first, w); auto* leftStrokeView = new StrokeStyleWidget(this->strokePair.first, w);
layout->addWidget(leftStrokeView); layout->addWidget(leftStrokeView);
QtMaterialCheckBox* checkEachSideIndependent = new QtMaterialCheckBox(w); auto* checkEachSideIndependent = new QtMaterialCheckBox(w);
checkEachSideIndependent->setText(QStringLiteral("ÓÒ²à¶ÀÁ¢Ãè±ß")); checkEachSideIndependent->setText(QStringLiteral("ÓÒ²à¶ÀÁ¢Ãè±ß"));
checkEachSideIndependent->setChecked(enableEachSideIndependent); checkEachSideIndependent->setChecked(enableEachSideIndependent);
layout->addWidget(checkEachSideIndependent); layout->addWidget(checkEachSideIndependent);
StrokeStyleWidget* rightStrokeView = new StrokeStyleWidget(this->strokePair.second, w); auto* rightStrokeView = new StrokeStyleWidget(this->strokePair.second, w);
layout->addWidget(rightStrokeView); layout->addWidget(rightStrokeView);
rightStrokeView->setDisabled(!this->enableEachSideIndependent); rightStrokeView->setDisabled(!this->enableEachSideIndependent);
@ -262,17 +262,17 @@ std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
QWidget* FillElementLayerStyle::getInputWidget() QWidget* FillElementLayerStyle::getInputWidget()
{ {
// TODO // TODO
QLineEdit* name = new QLineEdit; auto* name = new QLineEdit;
name->setText(QStringLiteral("Ìî³ä")); name->setText(QStringLiteral("Ìî³ä"));
return name; return name;
} }
QWidget* FillElementLayerStyle::getListDisplayWidget() const QWidget* FillElementLayerStyle::getListDisplayWidget() const
{ {
QWidget* w = new QWidget; auto* w = new QWidget;
QLabel* name = new QLabel(w); auto* name = new QLabel(w);
name->setText(QStringLiteral("Ìî³ä")); name->setText(QStringLiteral("Ìî³ä"));
QHBoxLayout* layout = new QHBoxLayout(w); auto* layout = new QHBoxLayout(w);
layout->setMargin(0); layout->setMargin(0);
layout->addWidget(name); layout->addWidget(name);
return w; return w;