latest changes

This commit is contained in:
Marcel Otte 2016-01-10 21:39:26 +01:00
parent 91e7b195bf
commit 4604df013f
6 changed files with 44 additions and 9 deletions

View File

@ -6,6 +6,8 @@
#include <QRegExp> #include <QRegExp>
#include <QLabel> #include <QLabel>
#include <iostream>
GuidedEditorElementView::GuidedEditorElementView(QWidget* parent) GuidedEditorElementView::GuidedEditorElementView(QWidget* parent)
: QWidget(parent) : QWidget(parent)
{ {
@ -19,16 +21,26 @@ GuidedEditorElementView::GuidedEditorElementView(QWidget* parent)
this->layout->addWidget(example.get()); this->layout->addWidget(example.get());
} }
void GuidedEditorElementView::setElement(GuidedEditorElement& element) void GuidedEditorElementView::setElement(std::shared_ptr<GuidedEditorElement> element)
{ {
std::cout<<"adding element " << element <<std::endl;
if(!element) {
this->title->setText("testtitle");
this->description = std::make_unique<QString>("test description");
this->example->setText("test example");
this->input = std::make_unique<QLineEdit>(this);
this->layout->addWidget(input.get());
this->update();
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 = std::make_unique<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 = std::make_unique<QComboBox>(this);
//TODO: data for the combobox ?! //TODO: data for the combobox ?!
@ -38,12 +50,12 @@ void GuidedEditorElementView::setElement(GuidedEditorElement& element)
this->input = std::make_unique<QLineEdit>(this); this->input = std::make_unique<QLineEdit>(this);
this->layout->addWidget(input.get()); this->layout->addWidget(input.get());
this->input->setValidator(std::make_shared<QRegExpValidator>(QRegExp(element.getSyntaxregex())).get()); this->input->setValidator(std::make_shared<QRegExpValidator>(QRegExp(element->getSyntaxregex())).get());
break; break;
case ElementType::STATIC: case ElementType::STATIC:
this->staticLabel = std::make_unique<QLabel>(this); this->staticLabel = std::make_unique<QLabel>(this);
this->layout->addWidget(staticLabel.get()); this->layout->addWidget(staticLabel.get());
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(GuidedEditorElement& element); void setElement(std::shared_ptr<GuidedEditorElement> element);
signals: signals:
void inputChanged(); void inputChanged();

View File

@ -1,5 +1,7 @@
#include <memory> #include <memory>
#include <iostream>
#include "guidededitorview.h" #include "guidededitorview.h"
#include "guidededitorelementview.h" #include "guidededitorelementview.h"
@ -16,6 +18,7 @@ GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) {
"QLineEdit {border: 2px dashed black;background: dark-gray;" "QLineEdit {border: 2px dashed black;background: dark-gray;"
"border-radius: 5px;}"); "border-radius: 5px;}");
this->setStyleSheet(style); this->setStyleSheet(style);
this->addElement(nullptr);
} }
GuidedEditorView::GuidedEditorView( GuidedEditorView::GuidedEditorView(
@ -27,3 +30,12 @@ GuidedEditorView::GuidedEditorView(
} }
GuidedEditorView::~GuidedEditorView() {} GuidedEditorView::~GuidedEditorView() {}
void GuidedEditorView::addElement(std::shared_ptr<GuidedEditorElement> element)
{
std::cout << "adding elementview from element " << element <<std::endl;
std::shared_ptr<GuidedEditorElementView> elementView = std::make_shared<GuidedEditorElementView>(this);
elementView->setElement(element);
this->layout()->addWidget(elementView.get());
//this->update();
}

View File

@ -18,6 +18,7 @@ public:
signals: signals:
public slots: public slots:
void addElement(std::shared_ptr<GuidedEditorElement> element);
private: private:
std::shared_ptr<FlowLayout> editorLayout; std::shared_ptr<FlowLayout> editorLayout;

View File

@ -1,5 +1,13 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QPushButton> #include <QPushButton>
#include <iostream>
void MainWindow::doSomething()
{
std::cout<<"sending nullptr"<<std::endl;
this->editor->addElement(nullptr);
std::cout<<"sent nullptr"<<std::endl;
}
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@ -15,7 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
QPushButton* button = new QPushButton(dockWidget.get()); QPushButton* button = new QPushButton(dockWidget.get());
button->setText("add"); button->setText("add");
dockLayout->addWidget(button); dockLayout->addWidget(button);
//this->connect(button, &QPushButton::pressed,editor, &GuidedEditorView::addElement); this->connect(button, &QPushButton::pressed,this, &MainWindow::doSomething);
} }

View File

@ -15,6 +15,8 @@ class MainWindow : public QMainWindow
private: private:
std::shared_ptr<GuidedEditorView> editor; std::shared_ptr<GuidedEditorView> editor;
std::shared_ptr<QDockWidget> dockWidget; std::shared_ptr<QDockWidget> dockWidget;
public slots:
void doSomething();
public: public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);