working on implementation

This commit is contained in:
Marcel M. Otte 2016-01-04 21:58:51 +01:00
parent 14605ac0cb
commit 182becb31b
8 changed files with 62 additions and 24 deletions

View File

@ -3,6 +3,8 @@
#include <cstdlib> #include <cstdlib>
#include <QObject> #include <QObject>
#include <memory>
#include <list>
#include "guidededitorelement.h" #include "guidededitorelement.h"
class AbstractGuidedEditorModel : public QObject class AbstractGuidedEditorModel : public QObject
@ -16,6 +18,8 @@ public:
virtual GuidedEditorElement& getElement(uint index) = 0; virtual GuidedEditorElement& getElement(uint index) = 0;
virtual void setElementValue(const uint index, const QString value)= 0; virtual void setElementValue(const uint index, const QString value)= 0;
virtual const std::list<GuidedEditorElement>& getAllElements() = 0;
signals: signals:
void dataChanged(); void dataChanged();
void dataChanged(uint index); void dataChanged(uint index);

View File

@ -1,7 +1,7 @@
#include "guidededitorelement.h" #include "guidededitorelement.h"
#include <QString> #include <QString>
GuidedEditorElement::GuidedEditorElement(QObject *parent) : QObject(parent) GuidedEditorElement::GuidedEditorElement()
{ {
} }

View File

@ -14,7 +14,7 @@ class GuidedEditorElement : public QObject
public: public:
explicit GuidedEditorElement(QObject *parent = 0); explicit GuidedEditorElement();
~GuidedEditorElement(); ~GuidedEditorElement();
QString getTitle() const; QString getTitle() const;

View File

@ -1,17 +1,51 @@
#include "guidededitorelementview.h" #include "guidededitorelementview.h"
GuidedEditorElementView::GuidedEditorElementView(QWidget *parent) : QWidget(parent) #include <memory>
{ #include <QVBoxLayout>
#include <QRegExpValidator>
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->setLayout(layout.get());
this->layout->addWidget(title.get());
this->layout->addWidget(example.get());
} }
void GuidedEditorElementView::setElement() void GuidedEditorElementView::setElement(GuidedEditorElement& element)
{ {
// set title
this->title->setText(element.getTitle());
// put description somewhere
this->description = std::make_unique<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);
//TODO: data for the combobox ?!
this->layout->addWidget(combobox.get());
break;
case ElementType::INPUT:
this->input = std::make_unique<QLineEdit>(this);
this->layout->addWidget(input.get());
this->input->setValidator(std::make_shared<QRegExpValidator>(element.getSyntaxregex(), input.get()).get());
break;
case ElementType::STATIC:
this->staticLabel = std::make_unique<QLabel>(this);
this->layout->addWidget(staticLabel.get());
this->staticLabel->setText(element.getValue());
break;
}
} }
void GuidedEditorElementView::dataChanged() void GuidedEditorElementView::dataChanged()
{ {
} }

View File

@ -4,10 +4,11 @@
#include <QWidget> #include <QWidget>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QBoxLayout> #include <QVBoxLayout>
#include <memory> #include <memory>
#include <QComboBox> #include <QComboBox>
#include "guidededitorelement.h"
#include "guidededitorlayer.h" #include "guidededitorlayer.h"
@ -15,11 +16,8 @@ class GuidedEditorElementView : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GuidedEditorElementView(QWidget *parent = 0); explicit GuidedEditorElementView(QWidget *parent = 0);
//explicit GuidedEditorElementView( QWidget *parent = 0); void setElement(GuidedEditorElement& element);
void setElement();
signals: signals:
void inputChanged(); void inputChanged();
@ -29,7 +27,7 @@ public slots:
private: private:
// layout // layout
std::unique_ptr<QBoxLayout> layout; std::unique_ptr<QVBoxLayout> layout;
// widget container // widget container
//? //?
// title label // title label
@ -41,6 +39,7 @@ private:
// input field based on element type // input field based on element type
std::unique_ptr<QLineEdit> input; std::unique_ptr<QLineEdit> input;
std::unique_ptr<QComboBox> combobox; std::unique_ptr<QComboBox> combobox;
std::unique_ptr<QLabel> staticLabel;
// layer information // layer information
std::shared_ptr<GuidedEditorLayer> layer; std::shared_ptr<GuidedEditorLayer> layer;

View File

@ -16,7 +16,7 @@ public:
void setTitle(const QString &value); void setTitle(const QString &value);
QColor getColor() const; QColor getColor() const;
void setColor(const QColor &value); void setColor(const QColor &value);
private: private:
QString title; QString title;

View File

@ -1,9 +1,11 @@
#include <memory>
#include "guidededitorview.h" #include "guidededitorview.h"
#include "guidededitorelementview.h" #include "guidededitorelementview.h"
GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) { GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) {
editorLayout = new FlowLayout(this); editorLayout = std::make_shared<FlowLayout>(this);
this->setLayout(editorLayout); this->setLayout(editorLayout.get());
// tests // tests
QString style = QString( QString style = QString(
"QWidget {" "QWidget {"
@ -19,10 +21,9 @@ GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) {
GuidedEditorView::GuidedEditorView( GuidedEditorView::GuidedEditorView(
std::shared_ptr<AbstractGuidedEditorModel> model, std::shared_ptr<AbstractGuidedEditorModel> model,
QWidget* parent) QWidget* parent)
: GuidedEditorView(parent) {} : GuidedEditorView(parent)
{
this->model = model;
}
GuidedEditorView::~GuidedEditorView() {} GuidedEditorView::~GuidedEditorView() {}
void GuidedEditorView::addElement() {
this->editorLayout->addWidget(new GuidedEditorElementView());
}

View File

@ -18,10 +18,10 @@ public:
signals: signals:
public slots: public slots:
void addElement();
private: private:
FlowLayout* editorLayout; std::shared_ptr<FlowLayout> editorLayout;
std::shared_ptr<AbstractGuidedEditorModel> model;
}; };
#endif // GUIDEDEDITOR_H #endif // GUIDEDEDITOR_H