changed usage of shared/unique pointers with QObjects

This commit is contained in:
Marcel Otte 2016-01-24 12:59:46 +01:00
parent 4604df013f
commit 0b176a1616
6 changed files with 46 additions and 46 deletions

View File

@ -11,50 +11,50 @@
GuidedEditorElementView::GuidedEditorElementView(QWidget* parent) GuidedEditorElementView::GuidedEditorElementView(QWidget* parent)
: QWidget(parent) : QWidget(parent)
{ {
this->layout = std::make_unique<QVBoxLayout>(this); this->layout = new QVBoxLayout(this);
this->title = std::make_unique<QLabel>(this); this->title = new QLabel(this);
this->description = std::make_unique<QString>(); this->description = new QString();
this->example = std::make_unique<QLabel>(this); this->example = new QLabel(this);
this->setLayout(layout.get()); this->setLayout(layout);
this->layout->addWidget(title.get()); this->layout->addWidget(title);
this->layout->addWidget(example.get()); this->layout->addWidget(example);
} }
void GuidedEditorElementView::setElement(std::shared_ptr<GuidedEditorElement> element) void GuidedEditorElementView::setElement(GuidedEditorElement* element)
{ {
std::cout<<"adding element " << element <<std::endl; std::cout<<"adding element " << element <<std::endl;
if(!element) { if(!element) {
this->title->setText("testtitle"); this->title->setText("testtitle");
this->description = std::make_unique<QString>("test description"); this->description = new QString("test description");
this->example->setText("test example"); this->example->setText("test example");
this->input = std::make_unique<QLineEdit>(this); this->input = new QLineEdit(this);
this->layout->addWidget(input.get()); this->layout->addWidget(input);
this->update(); this->update();
return; return;
} }
// set title // set title
this->title->setText(element->getTitle()); this->title->setText(element->getTitle());
// put description somewhere // put description somewhere
this->description = std::make_unique<QString>(element->getDescription()); this->description = new QString(element->getDescription());
// set example // set example
this->example->setText(element->getExample()); this->example->setText(element->getExample());
// set input/static part // set input/static part
switch (element->getType()) { switch (element->getType()) {
case ElementType::CHOOSER: case ElementType::CHOOSER:
this->combobox = std::make_unique<QComboBox>(this); this->combobox = new QComboBox(this);
//TODO: data for the combobox ?! //TODO: data for the combobox ?!
this->layout->addWidget(combobox.get()); this->layout->addWidget(combobox);
break; break;
case ElementType::INPUT: case ElementType::INPUT:
this->input = std::make_unique<QLineEdit>(this); this->input = new QLineEdit(this);
this->layout->addWidget(input.get()); this->layout->addWidget(input);
this->input->setValidator(std::make_shared<QRegExpValidator>(QRegExp(element->getSyntaxregex())).get()); this->input->setValidator(new QRegExpValidator(QRegExp(element->getSyntaxregex())));
break; break;
case ElementType::STATIC: case ElementType::STATIC:
this->staticLabel = std::make_unique<QLabel>(this); this->staticLabel = new QLabel(this);
this->layout->addWidget(staticLabel.get()); this->layout->addWidget(staticLabel);
this->staticLabel->setText(element->getValue()); this->staticLabel->setText(element->getValue());
break; break;
} }

View File

@ -17,7 +17,7 @@ class GuidedEditorElementView : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit GuidedEditorElementView(QWidget *parent = 0); explicit GuidedEditorElementView(QWidget *parent = 0);
void setElement(std::shared_ptr<GuidedEditorElement> element); void setElement(GuidedEditorElement* element);
signals: signals:
void inputChanged(); void inputChanged();
@ -27,21 +27,21 @@ public slots:
private: private:
// layout // layout
std::unique_ptr<QVBoxLayout> layout; QVBoxLayout* layout;
// widget container // widget container
//? //?
// title label // title label
std::unique_ptr<QLabel> title; QLabel* title;
// example/regex label // example/regex label
std::unique_ptr<QLabel> example; QLabel* example;
// mouseover description? // mouseover description?
std::unique_ptr<QString> description; QString* description;
// input field based on element type // input field based on element type
std::unique_ptr<QLineEdit> input; QLineEdit* input;
std::unique_ptr<QComboBox> combobox; QComboBox* combobox;
std::unique_ptr<QLabel> staticLabel; QLabel* staticLabel;
// layer information // layer information
std::shared_ptr<GuidedEditorLayer> layer; GuidedEditorLayer* layer;
}; };

View File

@ -6,8 +6,8 @@
#include "guidededitorelementview.h" #include "guidededitorelementview.h"
GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) { GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) {
editorLayout = std::make_shared<FlowLayout>(this); editorLayout = new FlowLayout(this);
this->setLayout(editorLayout.get()); this->setLayout(editorLayout);
// tests // tests
QString style = QString( QString style = QString(
"QWidget {" "QWidget {"
@ -22,7 +22,7 @@ GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) {
} }
GuidedEditorView::GuidedEditorView( GuidedEditorView::GuidedEditorView(
std::shared_ptr<AbstractGuidedEditorModel> model, AbstractGuidedEditorModel* model,
QWidget* parent) QWidget* parent)
: GuidedEditorView(parent) : GuidedEditorView(parent)
{ {
@ -31,11 +31,11 @@ GuidedEditorView::GuidedEditorView(
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::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); elementView->setElement(element);
this->layout()->addWidget(elementView.get()); this->layout()->addWidget(elementView);
//this->update(); //this->update();
} }

View File

@ -11,18 +11,18 @@ class GuidedEditorView : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit GuidedEditorView(QWidget* parent = 0); explicit GuidedEditorView(QWidget* parent = 0);
GuidedEditorView(std::shared_ptr<AbstractGuidedEditorModel> model, GuidedEditorView(AbstractGuidedEditorModel* model,
QWidget* parent = 0); QWidget* parent = 0);
~GuidedEditorView(); ~GuidedEditorView();
signals: signals:
public slots: public slots:
void addElement(std::shared_ptr<GuidedEditorElement> element); void addElement(GuidedEditorElement* element);
private: private:
std::shared_ptr<FlowLayout> editorLayout; FlowLayout* editorLayout;
std::shared_ptr<AbstractGuidedEditorModel> model; AbstractGuidedEditorModel* model;
}; };
#endif // GUIDEDEDITOR_H #endif // GUIDEDEDITOR_H

View File

@ -12,15 +12,15 @@ void MainWindow::doSomething()
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
editor = std::make_shared<GuidedEditorView>(this); editor = new GuidedEditorView(this);
this->setCentralWidget(editor.get()); this->setCentralWidget(editor);
dockWidget = std::make_shared<QDockWidget>(this); dockWidget = new QDockWidget(this);
this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget.get()); this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
// dockwidget // dockwidget
QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget.get()); QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget);
dockWidget->setLayout(dockLayout); dockWidget->setLayout(dockLayout);
QPushButton* button = new QPushButton(dockWidget.get()); QPushButton* button = new QPushButton(dockWidget);
button->setText("add"); button->setText("add");
dockLayout->addWidget(button); dockLayout->addWidget(button);
this->connect(button, &QPushButton::pressed,this, &MainWindow::doSomething); this->connect(button, &QPushButton::pressed,this, &MainWindow::doSomething);

View File

@ -13,8 +13,8 @@ class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
private: private:
std::shared_ptr<GuidedEditorView> editor; GuidedEditorView* editor;
std::shared_ptr<QDockWidget> dockWidget; QDockWidget* dockWidget;
public slots: public slots:
void doSomething(); void doSomething();