changed usage of shared/unique pointers with QObjects
This commit is contained in:
parent
4604df013f
commit
0b176a1616
|
@ -11,50 +11,50 @@
|
|||
GuidedEditorElementView::GuidedEditorElementView(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
this->layout = std::make_unique<QVBoxLayout>(this);
|
||||
this->title = std::make_unique<QLabel>(this);
|
||||
this->description = std::make_unique<QString>();
|
||||
this->example = std::make_unique<QLabel>(this);
|
||||
this->layout = new QVBoxLayout(this);
|
||||
this->title = new QLabel(this);
|
||||
this->description = new QString();
|
||||
this->example = new QLabel(this);
|
||||
|
||||
this->setLayout(layout.get());
|
||||
this->layout->addWidget(title.get());
|
||||
this->layout->addWidget(example.get());
|
||||
this->setLayout(layout);
|
||||
this->layout->addWidget(title);
|
||||
this->layout->addWidget(example);
|
||||
}
|
||||
|
||||
void GuidedEditorElementView::setElement(std::shared_ptr<GuidedEditorElement> element)
|
||||
void GuidedEditorElementView::setElement(GuidedEditorElement* element)
|
||||
{
|
||||
std::cout<<"adding element " << element <<std::endl;
|
||||
if(!element) {
|
||||
this->title->setText("testtitle");
|
||||
this->description = std::make_unique<QString>("test description");
|
||||
this->description = new QString("test description");
|
||||
this->example->setText("test example");
|
||||
this->input = std::make_unique<QLineEdit>(this);
|
||||
this->layout->addWidget(input.get());
|
||||
this->input = new QLineEdit(this);
|
||||
this->layout->addWidget(input);
|
||||
this->update();
|
||||
return;
|
||||
}
|
||||
// set title
|
||||
this->title->setText(element->getTitle());
|
||||
// put description somewhere
|
||||
this->description = std::make_unique<QString>(element->getDescription());
|
||||
this->description = new QString(element->getDescription());
|
||||
// set example
|
||||
this->example->setText(element->getExample());
|
||||
// set input/static part
|
||||
switch (element->getType()) {
|
||||
case ElementType::CHOOSER:
|
||||
this->combobox = std::make_unique<QComboBox>(this);
|
||||
this->combobox = new QComboBox(this);
|
||||
//TODO: data for the combobox ?!
|
||||
this->layout->addWidget(combobox.get());
|
||||
this->layout->addWidget(combobox);
|
||||
break;
|
||||
case ElementType::INPUT:
|
||||
this->input = std::make_unique<QLineEdit>(this);
|
||||
this->layout->addWidget(input.get());
|
||||
this->input = new QLineEdit(this);
|
||||
this->layout->addWidget(input);
|
||||
|
||||
this->input->setValidator(std::make_shared<QRegExpValidator>(QRegExp(element->getSyntaxregex())).get());
|
||||
this->input->setValidator(new QRegExpValidator(QRegExp(element->getSyntaxregex())));
|
||||
break;
|
||||
case ElementType::STATIC:
|
||||
this->staticLabel = std::make_unique<QLabel>(this);
|
||||
this->layout->addWidget(staticLabel.get());
|
||||
this->staticLabel = new QLabel(this);
|
||||
this->layout->addWidget(staticLabel);
|
||||
this->staticLabel->setText(element->getValue());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class GuidedEditorElementView : public QWidget
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit GuidedEditorElementView(QWidget *parent = 0);
|
||||
void setElement(std::shared_ptr<GuidedEditorElement> element);
|
||||
void setElement(GuidedEditorElement* element);
|
||||
|
||||
signals:
|
||||
void inputChanged();
|
||||
|
@ -27,21 +27,21 @@ public slots:
|
|||
|
||||
private:
|
||||
// layout
|
||||
std::unique_ptr<QVBoxLayout> layout;
|
||||
QVBoxLayout* layout;
|
||||
// widget container
|
||||
//?
|
||||
// title label
|
||||
std::unique_ptr<QLabel> title;
|
||||
QLabel* title;
|
||||
// example/regex label
|
||||
std::unique_ptr<QLabel> example;
|
||||
QLabel* example;
|
||||
// mouseover description?
|
||||
std::unique_ptr<QString> description;
|
||||
QString* description;
|
||||
// input field based on element type
|
||||
std::unique_ptr<QLineEdit> input;
|
||||
std::unique_ptr<QComboBox> combobox;
|
||||
std::unique_ptr<QLabel> staticLabel;
|
||||
QLineEdit* input;
|
||||
QComboBox* combobox;
|
||||
QLabel* staticLabel;
|
||||
// layer information
|
||||
std::shared_ptr<GuidedEditorLayer> layer;
|
||||
GuidedEditorLayer* layer;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include "guidededitorelementview.h"
|
||||
|
||||
GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) {
|
||||
editorLayout = std::make_shared<FlowLayout>(this);
|
||||
this->setLayout(editorLayout.get());
|
||||
editorLayout = new FlowLayout(this);
|
||||
this->setLayout(editorLayout);
|
||||
// tests
|
||||
QString style = QString(
|
||||
"QWidget {"
|
||||
|
@ -22,7 +22,7 @@ GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) {
|
|||
}
|
||||
|
||||
GuidedEditorView::GuidedEditorView(
|
||||
std::shared_ptr<AbstractGuidedEditorModel> model,
|
||||
AbstractGuidedEditorModel* model,
|
||||
QWidget* parent)
|
||||
: GuidedEditorView(parent)
|
||||
{
|
||||
|
@ -31,11 +31,11 @@ GuidedEditorView::GuidedEditorView(
|
|||
|
||||
GuidedEditorView::~GuidedEditorView() {}
|
||||
|
||||
void GuidedEditorView::addElement(std::shared_ptr<GuidedEditorElement> element)
|
||||
void GuidedEditorView::addElement(GuidedEditorElement* element)
|
||||
{
|
||||
std::cout << "adding elementview from element " << element <<std::endl;
|
||||
std::shared_ptr<GuidedEditorElementView> elementView = std::make_shared<GuidedEditorElementView>(this);
|
||||
GuidedEditorElementView* elementView = new GuidedEditorElementView(this);
|
||||
elementView->setElement(element);
|
||||
this->layout()->addWidget(elementView.get());
|
||||
this->layout()->addWidget(elementView);
|
||||
//this->update();
|
||||
}
|
||||
|
|
|
@ -11,18 +11,18 @@ class GuidedEditorView : public QWidget {
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit GuidedEditorView(QWidget* parent = 0);
|
||||
GuidedEditorView(std::shared_ptr<AbstractGuidedEditorModel> model,
|
||||
GuidedEditorView(AbstractGuidedEditorModel* model,
|
||||
QWidget* parent = 0);
|
||||
~GuidedEditorView();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void addElement(std::shared_ptr<GuidedEditorElement> element);
|
||||
void addElement(GuidedEditorElement* element);
|
||||
|
||||
private:
|
||||
std::shared_ptr<FlowLayout> editorLayout;
|
||||
std::shared_ptr<AbstractGuidedEditorModel> model;
|
||||
FlowLayout* editorLayout;
|
||||
AbstractGuidedEditorModel* model;
|
||||
};
|
||||
|
||||
#endif // GUIDEDEDITOR_H
|
||||
|
|
|
@ -12,15 +12,15 @@ void MainWindow::doSomething()
|
|||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
editor = std::make_shared<GuidedEditorView>(this);
|
||||
this->setCentralWidget(editor.get());
|
||||
dockWidget = std::make_shared<QDockWidget>(this);
|
||||
this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget.get());
|
||||
editor = new GuidedEditorView(this);
|
||||
this->setCentralWidget(editor);
|
||||
dockWidget = new QDockWidget(this);
|
||||
this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
|
||||
|
||||
// dockwidget
|
||||
QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget.get());
|
||||
QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget);
|
||||
dockWidget->setLayout(dockLayout);
|
||||
QPushButton* button = new QPushButton(dockWidget.get());
|
||||
QPushButton* button = new QPushButton(dockWidget);
|
||||
button->setText("add");
|
||||
dockLayout->addWidget(button);
|
||||
this->connect(button, &QPushButton::pressed,this, &MainWindow::doSomething);
|
||||
|
|
|
@ -13,8 +13,8 @@ class MainWindow : public QMainWindow
|
|||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::shared_ptr<GuidedEditorView> editor;
|
||||
std::shared_ptr<QDockWidget> dockWidget;
|
||||
GuidedEditorView* editor;
|
||||
QDockWidget* dockWidget;
|
||||
public slots:
|
||||
void doSomething();
|
||||
|
||||
|
|
Reference in New Issue