Compare commits

..

No commits in common. "15e2522591590cc378b7d7cce11ee6f8f161cf2f" and "fedb147dd30e7f643e15101d92475c3e32cebb38" have entirely different histories.

6 changed files with 55 additions and 113 deletions

View File

@ -16,19 +16,24 @@ const std::vector<std::pair<QString, std::function<std::shared_ptr<LayerStyle>()
} }
}; };
//const std::vector<std::pair<QString, std::function<LayerStyle*()>>> LayerStyle::types = {
// {
// QStringLiteral("Ãè±ß"),
// []() { return new StrokeElementLayerStyle; }
// },
// {
// QStringLiteral("Ìî³ä"),
// []() { return new FillElementLayerStyle; }
// }
//};
std::vector<Renderer::BaseStyle> StrokeElementLayerStyle::toBaseStyles() const std::vector<Renderer::BaseStyle> StrokeElementLayerStyle::toBaseStyles() const
{ {
return std::vector<Renderer::BaseStyle>(); return std::vector<Renderer::BaseStyle>();
} }
QString StrokeElementLayerStyle::getStyleName() const
{
return QStringLiteral("Ãè±ß");
}
QWidget* StrokeElementLayerStyle::getInputWidget() const QWidget* StrokeElementLayerStyle::getInputWidget() const
{ {
// TODO
QLabel* le = new QLabel; QLabel* le = new QLabel;
le->setText(QStringLiteral("Ãè±ß")); le->setText(QStringLiteral("Ãè±ß"));
return le; return le;
@ -50,14 +55,8 @@ std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
return std::vector<Renderer::BaseStyle>(); return std::vector<Renderer::BaseStyle>();
} }
QString FillElementLayerStyle::getStyleName() const
{
return QStringLiteral("Ìî³ä");
}
QWidget* FillElementLayerStyle::getInputWidget() const QWidget* FillElementLayerStyle::getInputWidget() const
{ {
// TODO
QLineEdit* name = new QLineEdit; QLineEdit* name = new QLineEdit;
name->setText(QStringLiteral("Ìî³ä")); name->setText(QStringLiteral("Ìî³ä"));
return name; return name;
@ -65,11 +64,5 @@ QWidget* FillElementLayerStyle::getInputWidget() const
QWidget* FillElementLayerStyle::getListDisplayWidget() const QWidget* FillElementLayerStyle::getListDisplayWidget() const
{ {
QWidget* w = new QWidget; return nullptr;
QLabel* name = new QLabel(w);
name->setText(QStringLiteral("Ìî³ä"));
QHBoxLayout* layout = new QHBoxLayout(w);
layout->setMargin(0);
layout->addWidget(name);
return w;
} }

View File

@ -20,7 +20,7 @@ class LayerStyle
{ {
public: public:
const static std::vector<std::pair<QString, std::function<std::shared_ptr<LayerStyle>()>>> types; const static std::vector<std::pair<QString, std::function<std::shared_ptr<LayerStyle>()>>> types;
virtual QString getStyleName() const = 0; //const static std::vector<std::pair<QString, std::function<LayerStyle*()>>> types;
virtual QWidget* getInputWidget() const = 0; virtual QWidget* getInputWidget() const = 0;
virtual QWidget* getListDisplayWidget() const = 0; virtual QWidget* getListDisplayWidget() const = 0;
virtual ~LayerStyle() {}; virtual ~LayerStyle() {};
@ -30,22 +30,20 @@ class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
{ {
public: public:
std::vector<Renderer::BaseStyle> toBaseStyles() const override; std::vector<Renderer::BaseStyle> toBaseStyles() const override;
QString getStyleName() const override;
QWidget* getInputWidget() const override; QWidget* getInputWidget() const override;
QWidget* getListDisplayWidget() const override; QWidget* getListDisplayWidget() const override;
StrokeElementLayerStyle() = default; StrokeElementLayerStyle() = default;
~StrokeElementLayerStyle() = default; ~StrokeElementLayerStyle() = default;
std::vector<std::shared_ptr<Renderer::MaterialStroke>> materialStyles; std::vector<std::unique_ptr<Renderer::MaterialStroke>> materialStyles;
}; };
class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
{ {
public: public:
std::vector<Renderer::BaseStyle> toBaseStyles() const override; std::vector<Renderer::BaseStyle> toBaseStyles() const override;
QString getStyleName() const override;
QWidget* getInputWidget() const override; QWidget* getInputWidget() const override;
QWidget* getListDisplayWidget() const override; QWidget* getListDisplayWidget() const override;
FillElementLayerStyle() = default; FillElementLayerStyle() = default;
~FillElementLayerStyle() = default; ~FillElementLayerStyle() = default;
std::vector<std::shared_ptr<Renderer::MaterialFill>> materialStyles; std::vector<std::unique_ptr<Renderer::MaterialFill>> materialStyles;
}; };

View File

@ -3,13 +3,8 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QGridLayout> #include <QGridLayout>
#include <QDebug> #include <QDebug>
#include <unordered_set>
LayerStyleDialog::LayerStyleDialog( LayerStyleDialog::LayerStyleDialog(QWidget* parent, std::shared_ptr<LayerStyle> existedStyle) : QDialog(parent)
QWidget* parent,
std::shared_ptr<LayerStyle> existedStyle,
std::vector<std::shared_ptr<LayerStyle>>* excludeStyles
) : QDialog(parent)
{ {
QVBoxLayout* dialogLayout = new QVBoxLayout(this); QVBoxLayout* dialogLayout = new QVBoxLayout(this);
dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
@ -26,38 +21,20 @@ LayerStyleDialog::LayerStyleDialog(
} }
else else
{ {
std::unordered_set<QString> excludeStyleNames; this->layerStyle = LayerStyle::types[0].second();
for(auto &style : *excludeStyles)
{
excludeStyleNames.insert(style->getStyleName());
}
QComboBox* typeSelector = new QComboBox(this); QComboBox* typeSelector = new QComboBox(this);
for (auto& pair : LayerStyle::types) {
for (auto& pair : LayerStyle::types) typeSelector->addItem(pair.first);
{
if (!excludeStyleNames.contains(pair.first))
{
typeSelector->addItem(pair.first);
if (!this->layerStyle)
{
this->layerStyle = pair.second();
}
}
} }
dialogLayout->addWidget(typeSelector);
this->styleContainer = new QGridLayout(this);
dialogLayout->addLayout(styleContainer);
if (typeSelector->count() > 0) this->styleWidget = this->layerStyle->getInputWidget();
{ this->styleWidget->setParent(this);
dialogLayout->addWidget(typeSelector); this->styleContainer->addWidget(styleWidget);
this->styleContainer = new QGridLayout(this); connect(typeSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LayerStyleDialog::onStyleTypeSelectorChanged);
dialogLayout->addLayout(styleContainer);
this->styleWidget = this->layerStyle->getInputWidget();
this->styleWidget->setParent(this);
this->styleContainer->addWidget(styleWidget);
connect(typeSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &LayerStyleDialog::onStyleTypeSelectorChanged);
}
} }
} }

View File

@ -10,10 +10,7 @@ private:
QWidget* styleWidget; QWidget* styleWidget;
QGridLayout* styleContainer; QGridLayout* styleContainer;
public: public:
LayerStyleDialog( LayerStyleDialog(QWidget* parent = nullptr, std::shared_ptr<LayerStyle> existedStyle = nullptr);
QWidget* parent = nullptr,
std::shared_ptr<LayerStyle> existedStyle = nullptr,
std::vector<std::shared_ptr<LayerStyle>>* excludeStyles = nullptr);
std::shared_ptr<LayerStyle> layerStyle; std::shared_ptr<LayerStyle> layerStyle;
private slots: private slots:
void onStyleTypeSelectorChanged(int index); void onStyleTypeSelectorChanged(int index);

View File

@ -168,7 +168,7 @@ QTreeWidgetItem* LayerWrapper::getQTreeItem()
{ {
this->qTreeWidgetItem.setText(0, this->property.name); this->qTreeWidgetItem.setText(0, this->property.name);
this->qTreeWidgetItem.setData(0, Qt::UserRole, QVariant::fromValue(this)); this->qTreeWidgetItem.setData(0, Qt::UserRole, QVariant::fromValue(this));
return &this->qTreeWidgetItem; return new QTreeWidgetItem(this->qTreeWidgetItem);
} }
QTreeWidgetItem* FolderLayerWrapper::getQTreeItem() QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()

View File

@ -3,11 +3,10 @@
#include <QLineEdit> #include <QLineEdit>
#include <QTextBlock> #include <QTextBlock>
#include <QListWidget> #include <QListWidget>
#include <QPushButton>
#include <QDialog> #include <QDialog>
#include <QComboBox> #include <QComboBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <qtmaterialraisedbutton.h>
#include <qtmaterialflatbutton.h>
void InfoDisplayWidget::setLayer(LayerWrapper *layer) void InfoDisplayWidget::setLayer(LayerWrapper *layer)
{ {
@ -89,27 +88,12 @@ void InfoDisplayWidget::generateLayerForm()
headerLabel->setText("样式列表"); headerLabel->setText("样式列表");
headerLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); headerLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
//QtMaterialRaisedButton* addStyleButton = new QtMaterialRaisedButton("+", headerWidget);
QPushButton* addStyleButton = new QPushButton("+", headerWidget); QPushButton* addStyleButton = new QPushButton("+", headerWidget);
addStyleButton->setFixedSize(QSize(20, 20)); addStyleButton->setFixedSize(QSize(20, 20));
if (leafP->styles.size() >= LayerStyle::types.size()) connect(addStyleButton, &QPushButton::clicked, [this]() {
{ QDialog* dialog = new LayerStyleDialog(this);
addStyleButton->setDisabled(true);
}
else
{
connect(addStyleButton, &QPushButton::clicked, [&, leafP]() {
LayerStyleDialog* dialog = new LayerStyleDialog(nullptr, nullptr, &(leafP->styles));
dialog->exec(); dialog->exec();
if (dialog->layerStyle) });
{
leafP->styles.push_back(dialog->layerStyle);
emit requireRefreshPreview();
emit requireSelfRefresh();
}
dialog->deleteLater();
});
}
headerLayout->addWidget(headerLabel); headerLayout->addWidget(headerLabel);
headerLayout->addWidget(addStyleButton); headerLayout->addWidget(addStyleButton);
@ -169,60 +153,53 @@ void InfoDisplayWidget::generateLayerForm()
// for (int i = 0; i < styleNames.size(); i++) // for (int i = 0; i < styleNames.size(); i++)
// createStyleItem(i); // createStyleItem(i);
/*if (leafP->styles.empty()) if (leafP->styles.empty())
{ {
leafP->styles.push_back(std::shared_ptr<LayerStyle>(new StrokeElementLayerStyle())); leafP->styles.push_back(std::shared_ptr<LayerStyle>(new StrokeElementLayerStyle()));
}*/ }
std::vector<std::shared_ptr<LayerStyle>>* styles = &(leafP->styles); for (auto& style : leafP->styles)
for (auto styleIterator = styles->begin(); styleIterator != styles->end(); styleIterator++)
{ {
QListWidgetItem* item = new QListWidgetItem; QListWidgetItem* item = new QListWidgetItem;
QWidget* w = new QWidget; QWidget* w = new QWidget;
item->setSizeHint(QSize(50, 40)); item->setSizeHint(QSize(50, 40));
QHBoxLayout* layout = new QHBoxLayout; QHBoxLayout* layout = new QHBoxLayout;
layout->setAlignment(Qt::AlignmentFlag::AlignRight); layout->setAlignment(Qt::AlignmentFlag::AlignRight);
//QtMaterialFlatButton* detailButton = new QtMaterialFlatButton(w);
//QtMaterialFlatButton* removeButton = new QtMaterialFlatButton(w);
QPushButton* detailButton = new QPushButton(w); QPushButton* detailButton = new QPushButton(w);
QPushButton* removeButton = new QPushButton(w); QPushButton* deleteButton = new QPushButton(w);
detailButton->setText("..."); detailButton->setText("...");
detailButton->setFixedSize(QSize(20, 20)); detailButton->setFixedSize(QSize(20, 20));
removeButton->setText("×"); deleteButton->setText("×");
removeButton->setFixedSize(QSize(20, 20)); deleteButton->setFixedSize(QSize(20, 20));
connect(detailButton, &QPushButton::clicked, this, connect(detailButton, &QPushButton::clicked, [this, &style]() {
[=]() LayerStyleDialog* dialog = new LayerStyleDialog(this, style);
{ /*dialog->setAttribute(Qt::WA_DeleteOnClose);
LayerStyleDialog* dialog = new LayerStyleDialog(nullptr, *styleIterator); QVBoxLayout* layout = new QVBoxLayout(dialog);
dialog->exec();
if (dialog->layerStyle) QComboBox* typeSelector = new QComboBox(dialog);
{ for (auto &pair : LayerStyle::types) {
emit requireRefreshPreview(); typeSelector->addItem(pair.first);
emit requireSelfRefresh(); }
}
dialog->deleteLater(); layout->addWidget(typeSelector);
QWidget* styleWidget = style->getInputWidget();
styleWidget->setParent(dialog);
layout->addWidget(styleWidget);*/
dialog->exec();
}); });
connect(removeButton, &QPushButton::clicked, this, QWidget* styleDisplayWidget = style->getListDisplayWidget();
[this, styleIterator, styles]()
{
styles->erase(styleIterator);
emit requireRefreshPreview();
emit requireSelfRefresh();
});
QWidget* styleDisplayWidget = (*styleIterator)->getListDisplayWidget();
styleDisplayWidget->setParent(w); styleDisplayWidget->setParent(w);
styleDisplayWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); styleDisplayWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
layout->addWidget(styleDisplayWidget); layout->addWidget(styleDisplayWidget);
layout->addWidget(detailButton); layout->addWidget(detailButton);
layout->addWidget(removeButton); layout->addWidget(deleteButton);
w->setLayout(layout); w->setLayout(layout);
styleList->addItem(item); styleList->addItem(item);
styleList->setItemWidget(item, w); styleList->setItemWidget(item, w);
//style->addListItem(styleList);
} }
layout->addRow(styleList); layout->addRow(styleList);
} }