Compare commits

...

3 Commits

6 changed files with 114 additions and 56 deletions

View File

@ -16,24 +16,19 @@ 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;
@ -55,8 +50,14 @@ 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;
@ -64,5 +65,11 @@ QWidget* FillElementLayerStyle::getInputWidget() const
QWidget* FillElementLayerStyle::getListDisplayWidget() const QWidget* FillElementLayerStyle::getListDisplayWidget() const
{ {
return nullptr; QWidget* w = new QWidget;
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;
//const static std::vector<std::pair<QString, std::function<LayerStyle*()>>> types; virtual QString getStyleName() const = 0;
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,20 +30,22 @@ 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::unique_ptr<Renderer::MaterialStroke>> materialStyles; std::vector<std::shared_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::unique_ptr<Renderer::MaterialFill>> materialStyles; std::vector<std::shared_ptr<Renderer::MaterialFill>> materialStyles;
}; };

View File

@ -3,8 +3,13 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QGridLayout> #include <QGridLayout>
#include <QDebug> #include <QDebug>
#include <unordered_set>
LayerStyleDialog::LayerStyleDialog(QWidget* parent, std::shared_ptr<LayerStyle> existedStyle) : QDialog(parent) LayerStyleDialog::LayerStyleDialog(
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);
@ -21,12 +26,28 @@ LayerStyleDialog::LayerStyleDialog(QWidget* parent, std::shared_ptr<LayerStyle>
} }
else else
{ {
this->layerStyle = LayerStyle::types[0].second(); std::unordered_set<QString> excludeStyleNames;
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)
{
if (!excludeStyleNames.contains(pair.first))
{
typeSelector->addItem(pair.first); typeSelector->addItem(pair.first);
if (!this->layerStyle)
{
this->layerStyle = pair.second();
} }
}
}
if (typeSelector->count() > 0)
{
dialogLayout->addWidget(typeSelector); dialogLayout->addWidget(typeSelector);
this->styleContainer = new QGridLayout(this); this->styleContainer = new QGridLayout(this);
dialogLayout->addLayout(styleContainer); dialogLayout->addLayout(styleContainer);
@ -34,7 +55,9 @@ LayerStyleDialog::LayerStyleDialog(QWidget* parent, std::shared_ptr<LayerStyle>
this->styleWidget = this->layerStyle->getInputWidget(); this->styleWidget = this->layerStyle->getInputWidget();
this->styleWidget->setParent(this); this->styleWidget->setParent(this);
this->styleContainer->addWidget(styleWidget); this->styleContainer->addWidget(styleWidget);
connect(typeSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LayerStyleDialog::onStyleTypeSelectorChanged); connect(typeSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &LayerStyleDialog::onStyleTypeSelectorChanged);
}
} }
} }

View File

@ -10,7 +10,10 @@ private:
QWidget* styleWidget; QWidget* styleWidget;
QGridLayout* styleContainer; QGridLayout* styleContainer;
public: public:
LayerStyleDialog(QWidget* parent = nullptr, std::shared_ptr<LayerStyle> existedStyle = nullptr); LayerStyleDialog(
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 new QTreeWidgetItem(this->qTreeWidgetItem); return &this->qTreeWidgetItem;
} }
QTreeWidgetItem* FolderLayerWrapper::getQTreeItem() QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()

View File

@ -3,10 +3,11 @@
#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)
{ {
@ -88,12 +89,27 @@ 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));
connect(addStyleButton, &QPushButton::clicked, [this]() { if (leafP->styles.size() >= LayerStyle::types.size())
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);
@ -153,53 +169,60 @@ 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()));
} }*/
for (auto& style : leafP->styles) std::vector<std::shared_ptr<LayerStyle>>* styles = &(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* deleteButton = new QPushButton(w); QPushButton* removeButton = new QPushButton(w);
detailButton->setText("..."); detailButton->setText("...");
detailButton->setFixedSize(QSize(20, 20)); detailButton->setFixedSize(QSize(20, 20));
deleteButton->setText("×"); removeButton->setText("×");
deleteButton->setFixedSize(QSize(20, 20)); removeButton->setFixedSize(QSize(20, 20));
connect(detailButton, &QPushButton::clicked, [this, &style]() { connect(detailButton, &QPushButton::clicked, this,
LayerStyleDialog* dialog = new LayerStyleDialog(this, style); [=]()
/*dialog->setAttribute(Qt::WA_DeleteOnClose); {
QVBoxLayout* layout = new QVBoxLayout(dialog); LayerStyleDialog* dialog = new LayerStyleDialog(nullptr, *styleIterator);
QComboBox* typeSelector = new QComboBox(dialog);
for (auto &pair : LayerStyle::types) {
typeSelector->addItem(pair.first);
}
layout->addWidget(typeSelector);
QWidget* styleWidget = style->getInputWidget();
styleWidget->setParent(dialog);
layout->addWidget(styleWidget);*/
dialog->exec(); dialog->exec();
if (dialog->layerStyle)
{
emit requireRefreshPreview();
emit requireSelfRefresh();
}
dialog->deleteLater();
}); });
QWidget* styleDisplayWidget = style->getListDisplayWidget(); connect(removeButton, &QPushButton::clicked, this,
[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(deleteButton); layout->addWidget(removeButton);
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);
} }