完成style的基本构架
parent
52734adda8
commit
846f334d54
|
@ -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
|
||||
{
|
||||
return std::vector<Renderer::BaseStyle>();
|
||||
}
|
||||
|
||||
QString StrokeElementLayerStyle::getStyleName() const
|
||||
{
|
||||
return QStringLiteral("Ãè±ß");
|
||||
}
|
||||
|
||||
QWidget* StrokeElementLayerStyle::getInputWidget() const
|
||||
{
|
||||
// TODO
|
||||
QLabel* le = new QLabel;
|
||||
le->setText(QStringLiteral("Ãè±ß"));
|
||||
return le;
|
||||
|
@ -55,8 +50,14 @@ std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
|
|||
return std::vector<Renderer::BaseStyle>();
|
||||
}
|
||||
|
||||
QString FillElementLayerStyle::getStyleName() const
|
||||
{
|
||||
return QStringLiteral("Ìî³ä");
|
||||
}
|
||||
|
||||
QWidget* FillElementLayerStyle::getInputWidget() const
|
||||
{
|
||||
// TODO
|
||||
QLineEdit* name = new QLineEdit;
|
||||
name->setText(QStringLiteral("Ìî³ä"));
|
||||
return name;
|
||||
|
@ -64,5 +65,11 @@ QWidget* FillElementLayerStyle::getInputWidget() 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;
|
||||
}
|
|
@ -20,7 +20,7 @@ class LayerStyle
|
|||
{
|
||||
public:
|
||||
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* getListDisplayWidget() const = 0;
|
||||
virtual ~LayerStyle() {};
|
||||
|
@ -30,20 +30,22 @@ class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
|
|||
{
|
||||
public:
|
||||
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
|
||||
QString getStyleName() const override;
|
||||
QWidget* getInputWidget() const override;
|
||||
QWidget* getListDisplayWidget() const override;
|
||||
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
|
||||
{
|
||||
public:
|
||||
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
|
||||
QString getStyleName() const override;
|
||||
QWidget* getInputWidget() const override;
|
||||
QWidget* getListDisplayWidget() const override;
|
||||
FillElementLayerStyle() = default;
|
||||
~FillElementLayerStyle() = default;
|
||||
std::vector<std::unique_ptr<Renderer::MaterialFill>> materialStyles;
|
||||
std::vector<std::shared_ptr<Renderer::MaterialFill>> materialStyles;
|
||||
};
|
|
@ -3,8 +3,13 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#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);
|
||||
dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
|
@ -21,12 +26,28 @@ LayerStyleDialog::LayerStyleDialog(QWidget* parent, std::shared_ptr<LayerStyle>
|
|||
}
|
||||
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);
|
||||
for (auto& pair : LayerStyle::types) {
|
||||
|
||||
for (auto& pair : LayerStyle::types)
|
||||
{
|
||||
if (!excludeStyleNames.contains(pair.first))
|
||||
{
|
||||
typeSelector->addItem(pair.first);
|
||||
if (!this->layerStyle)
|
||||
{
|
||||
this->layerStyle = pair.second();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeSelector->count() > 0)
|
||||
{
|
||||
dialogLayout->addWidget(typeSelector);
|
||||
this->styleContainer = new QGridLayout(this);
|
||||
dialogLayout->addLayout(styleContainer);
|
||||
|
@ -34,7 +55,9 @@ LayerStyleDialog::LayerStyleDialog(QWidget* parent, std::shared_ptr<LayerStyle>
|
|||
this->styleWidget = this->layerStyle->getInputWidget();
|
||||
this->styleWidget->setParent(this);
|
||||
this->styleContainer->addWidget(styleWidget);
|
||||
connect(typeSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LayerStyleDialog::onStyleTypeSelectorChanged);
|
||||
connect(typeSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &LayerStyleDialog::onStyleTypeSelectorChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,10 @@ private:
|
|||
QWidget* styleWidget;
|
||||
QGridLayout* styleContainer;
|
||||
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;
|
||||
private slots:
|
||||
void onStyleTypeSelectorChanged(int index);
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#include <QLineEdit>
|
||||
#include <QTextBlock>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QDialog>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <qtmaterialraisedbutton.h>
|
||||
#include <qtmaterialflatbutton.h>
|
||||
|
||||
void InfoDisplayWidget::setLayer(LayerWrapper *layer)
|
||||
{
|
||||
|
@ -88,12 +89,27 @@ void InfoDisplayWidget::generateLayerForm()
|
|||
headerLabel->setText("样式列表");
|
||||
headerLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||
|
||||
//QtMaterialRaisedButton* addStyleButton = new QtMaterialRaisedButton("+", headerWidget);
|
||||
QPushButton* addStyleButton = new QPushButton("+", headerWidget);
|
||||
addStyleButton->setFixedSize(QSize(20, 20));
|
||||
connect(addStyleButton, &QPushButton::clicked, [this]() {
|
||||
QDialog* dialog = new LayerStyleDialog(this);
|
||||
if (leafP->styles.size() >= LayerStyle::types.size())
|
||||
{
|
||||
addStyleButton->setDisabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(addStyleButton, &QPushButton::clicked, [&, leafP]() {
|
||||
LayerStyleDialog* dialog = new LayerStyleDialog(nullptr, nullptr, &(leafP->styles));
|
||||
dialog->exec();
|
||||
if (dialog->layerStyle)
|
||||
{
|
||||
leafP->styles.push_back(dialog->layerStyle);
|
||||
emit requireRefreshPreview();
|
||||
emit requireSelfRefresh();
|
||||
}
|
||||
dialog->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
headerLayout->addWidget(headerLabel);
|
||||
headerLayout->addWidget(addStyleButton);
|
||||
|
@ -153,53 +169,60 @@ void InfoDisplayWidget::generateLayerForm()
|
|||
// for (int i = 0; i < styleNames.size(); i++)
|
||||
// createStyleItem(i);
|
||||
|
||||
if (leafP->styles.empty())
|
||||
/*if (leafP->styles.empty())
|
||||
{
|
||||
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;
|
||||
QWidget* w = new QWidget;
|
||||
item->setSizeHint(QSize(50, 40));
|
||||
QHBoxLayout* layout = new QHBoxLayout;
|
||||
layout->setAlignment(Qt::AlignmentFlag::AlignRight);
|
||||
//QtMaterialFlatButton* detailButton = new QtMaterialFlatButton(w);
|
||||
//QtMaterialFlatButton* removeButton = new QtMaterialFlatButton(w);
|
||||
QPushButton* detailButton = new QPushButton(w);
|
||||
QPushButton* deleteButton = new QPushButton(w);
|
||||
QPushButton* removeButton = new QPushButton(w);
|
||||
detailButton->setText("...");
|
||||
detailButton->setFixedSize(QSize(20, 20));
|
||||
deleteButton->setText("×");
|
||||
deleteButton->setFixedSize(QSize(20, 20));
|
||||
removeButton->setText("×");
|
||||
removeButton->setFixedSize(QSize(20, 20));
|
||||
|
||||
connect(detailButton, &QPushButton::clicked, [this, &style]() {
|
||||
LayerStyleDialog* dialog = new LayerStyleDialog(this, style);
|
||||
/*dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
QVBoxLayout* layout = new QVBoxLayout(dialog);
|
||||
|
||||
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);*/
|
||||
connect(detailButton, &QPushButton::clicked, this,
|
||||
[=]()
|
||||
{
|
||||
LayerStyleDialog* dialog = new LayerStyleDialog(nullptr, *styleIterator);
|
||||
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->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||
|
||||
layout->addWidget(styleDisplayWidget);
|
||||
layout->addWidget(detailButton);
|
||||
layout->addWidget(deleteButton);
|
||||
layout->addWidget(removeButton);
|
||||
w->setLayout(layout);
|
||||
|
||||
styleList->addItem(item);
|
||||
styleList->setItemWidget(item, w);
|
||||
//style->addListItem(styleList);
|
||||
}
|
||||
layout->addRow(styleList);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue