diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.cpp index 5cb0e9b..5b011a7 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.cpp @@ -1,24 +1,28 @@ #include "StrokeStyleListView.h" #include "ColorPicker.h" +#include constexpr int COLUMN_WIDTH = 0; constexpr int COLUMN_COLOR = 1; constexpr int COLUMN_METALLIC = 2; constexpr int COLUMN_ROUGHNESS = 3; +constexpr int COLUMN_OPERATIONS = 4; +// TODO: 将这个类改为继承QWidget,把table转为其中的一个元素,加上新增行按钮和宽度设置 StrokeStyleListView::StrokeStyleListView( std::shared_ptr stroke, QWidget* parent ) : QTableWidget(parent), stroke(stroke) { this->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); - this->setColumnCount(4); + this->setColumnCount(5); this->setRowCount(stroke->materialMap.size()); QStringList headers; - headers.append(QStringLiteral("总线宽占比")); + headers.append(QStringLiteral("离心距离占比")); headers.append(QStringLiteral("颜色")); headers.append(QStringLiteral("金属度")); headers.append(QStringLiteral("粗糙度")); + headers.append(QStringLiteral("其他操作")); this->setHorizontalHeaderLabels(headers); for (int row = 0; auto& strokePair : stroke->materialMap) { @@ -45,6 +49,14 @@ StrokeStyleListView::StrokeStyleListView( roughnessItem->setData(Qt::EditRole, strokePair.second.roughness); this->setItem(row, COLUMN_ROUGHNESS, roughnessItem); + QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", this); + removeButton->setFixedSize(20, 20); + this->setCellWidget(row, COLUMN_OPERATIONS, removeButton); + connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() { + this->stroke->materialMap.erase(this->item(row, COLUMN_WIDTH)->text().toFloat()); + this->removeRow(row); + }); + row++; } connect(this, &StrokeStyleListView::currentItemChanged, this, &StrokeStyleListView::onCurrentItemChanged); @@ -54,8 +66,9 @@ StrokeStyleListView::StrokeStyleListView( void StrokeStyleListView::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous) { + if (!current) return; int column = current->column(); - if (column != COLUMN_COLOR) + if (column != COLUMN_COLOR && column != COLUMN_OPERATIONS) { this->currentItemValue = current->text(); }