working again on npc, finally

This commit is contained in:
Marcel Otte 2015-09-06 18:57:18 +02:00
parent 8bc8b8f44e
commit 65faf27963
14 changed files with 281 additions and 78 deletions

View File

@ -0,0 +1,7 @@
#include "abstractguidededitormodel.h"
AbstractGuidedEditorModel::AbstractGuidedEditorModel(QObject *parent) : QObject(parent)
{
}

View File

@ -0,0 +1,26 @@
#ifndef ABSTRACTGUIDEDEDITORMODEL_H
#define ABSTRACTGUIDEDEDITORMODEL_H
#include <cstdlib>
#include <QObject>
#include "guidededitorelement.h"
class AbstractGuidedEditorModel : public QObject
{
Q_OBJECT
public:
explicit AbstractGuidedEditorModel(QObject *parent = 0);
virtual ~AbstractGuidedEditorModel();
virtual uint getCount()=0;
virtual GuidedEditorElement& getElement(uint index) = 0;
virtual void setElementValue(const uint index, const QString value)= 0;
signals:
void dataChanged();
void dataChanged(uint index);
public slots:
};
#endif // ABSTRACTGUIDEDEDITORMODEL_H

View File

@ -1,26 +0,0 @@
#ifndef GUIDEDEDITOR_H
#define GUIDEDEDITOR_H
#include <QWidget>
#include "flowlayout.h"
#include "guidededitorelement.h"
class GuidedEditor : public QWidget
{
Q_OBJECT
public:
explicit GuidedEditor(QWidget *parent = 0);
~GuidedEditor();
signals:
public slots:
void addElement();
private:
FlowLayout* editorLayout;
QList<EditorElement*>* list;
};
#endif // GUIDEDEDITOR_H

View File

@ -1,27 +1,75 @@
#include "guidededitorelement.h"
#include <QBoxLayout>
#include <QString>
EditorElement::EditorElement(QWidget *parent) : QWidget(parent)
{
this->layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
this->setLayout(layout);
label = new QLabel(this);
hint = new QLabel(this);
edit = new QLineEdit(this);
layout->addWidget(label);
layout->addWidget(hint);
layout->addWidget(edit);
label->setText("test");
hint->setText("another test");
edit->setText("content test");
this->setStyleSheet("QWidget {border: 2px dashed red}");
}
EditorElement::~EditorElement()
GuidedEditorElement::GuidedEditorElement(QObject *parent) : QObject(parent)
{
}
GuidedEditorElement::~GuidedEditorElement()
{
}
QString GuidedEditorElement::getTitle() const
{
return title;
}
void GuidedEditorElement::setTitle(const QString &value)
{
title = value;
}
QString GuidedEditorElement::getDescription() const
{
return description;
}
void GuidedEditorElement::setDescription(const QString &value)
{
description = value;
}
QString GuidedEditorElement::getExample() const
{
return example;
}
void GuidedEditorElement::setExample(const QString &value)
{
example = value;
}
QString GuidedEditorElement::getSyntaxregex() const
{
return syntaxregex;
}
void GuidedEditorElement::setSyntaxregex(const QString &value)
{
syntaxregex = value;
}
ElementType GuidedEditorElement::getType() const
{
return type;
}
void GuidedEditorElement::setType(const ElementType &value)
{
type = value;
}
QString GuidedEditorElement::getValue() const
{
return value;
}
void GuidedEditorElement::setValue(const QString &value)
{
this->value = value;
}

View File

@ -1,28 +1,48 @@
#ifndef EDITORELEMENT_H
#define EDITORELEMENT_H
#include <QBoxLayout>
#include <QObject>
#include <QWidget>
#include <QtGui>
#include <QLineEdit>
#include <QLabel>
#include <QString>
class EditorElement : public QWidget
enum class ElementType {
INPUT, CHOOSER, STATIC
};
class GuidedEditorElement : public QObject
{
Q_OBJECT
public:
explicit EditorElement(QWidget *parent = 0);
~EditorElement();
explicit GuidedEditorElement(QObject *parent = 0);
~GuidedEditorElement();
QString getTitle() const;
void setTitle(const QString &value);
QString getDescription() const;
void setDescription(const QString &value);
QString getExample() const;
void setExample(const QString &value);
QString getSyntaxregex() const;
void setSyntaxregex(const QString &value);
ElementType getType() const;
void setType(const ElementType &value);
QString getValue() const;
void setValue(const QString &value);
private:
QBoxLayout*layout;
QLabel * label;
QLabel * hint;
QLineEdit* edit;
QString title;
QString description;
QString example;
QString syntaxregex;
ElementType type;
QString value;
signals:
public slots:
};
#endif // EDITORELEMENT_H

View File

@ -0,0 +1,7 @@
#include "guidededitorelementview.h"
GuidedEditorElementView::GuidedEditorElementView(GuidedEditorElement *element, QWidget *parent) : QWidget(parent)
{
}

27
guidededitorelementview.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef GUIDEDEDITORELEMENTVIEW_H
#define GUIDEDEDITORELEMENTVIEW_H
#include "guidededitorelement.h"
#include <QWidget>
class GuidedEditorElementView : public QWidget
{
Q_OBJECT
public:
explicit GuidedEditorElementView(GuidedEditorElement* element, QWidget *parent = 0);
signals:
public slots:
private:
// widget container
// title label
// example/regex label
// mouseover description?
// input field based on element type
// layer information
};
#endif // GUIDEDEDITORELEMENTVIEW_H

27
guidededitorlayer.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "guidededitorlayer.h"
GuidedEditorLayer::GuidedEditorLayer(QObject *parent) : QObject(parent)
{
}
QString GuidedEditorLayer::getTitle() const
{
return title;
}
void GuidedEditorLayer::setTitle(const QString &value)
{
title = value;
}
QColor GuidedEditorLayer::getColor() const
{
return color;
}
void GuidedEditorLayer::setColor(const QColor &value)
{
color = value;
}

31
guidededitorlayer.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef GUIDEDEDITORLAYER_H
#define GUIDEDEDITORLAYER_H
#include <QObject>
#include <QString>
#include <QColor>
class GuidedEditorLayer : public QObject
{
Q_OBJECT
public:
explicit GuidedEditorLayer(QObject *parent = 0);
GuidedEditorLayer(QString title, QObject *parent = 0);
QString getTitle() const;
void setTitle(const QString &value);
QColor getColor() const;
void setColor(const QColor &value);
private:
QString title;
QColor color;
signals:
public slots:
};
#endif // GUIDEDEDITORLAYER_H

View File

@ -1,12 +1,9 @@
#include "guidededitor.h"
#include "guidededitorview.h"
GuidedEditor::GuidedEditor(QWidget *parent) : QWidget(parent)
{
GuidedEditorView::GuidedEditorView(QWidget * parent): QWidget(parent) {
editorLayout = new FlowLayout(this);
this->setLayout(editorLayout);
//tests
this->editorLayout->addWidget(new EditorElement(this));
this->editorLayout->addWidget(new EditorElement(this));
QString style = QString(
"QWidget {"
"border-radius: 5px;"
@ -17,14 +14,16 @@ GuidedEditor::GuidedEditor(QWidget *parent) : QWidget(parent)
"border-radius: 5px;}"
);
this->setStyleSheet(style);
}
GuidedEditorView::GuidedEditorView(std::shared_ptr<AbstractGuidedEditorModel> model,QWidget *parent) :GuidedEditorView(parent)
{
}
void GuidedEditor::addElement() {
this->editorLayout->addWidget(new EditorElement(this));
}
GuidedEditor::~GuidedEditor()
GuidedEditorView::~GuidedEditorView()
{
}

29
guidededitorview.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef GUIDEDEDITOR_H
#define GUIDEDEDITOR_H
#include <memory>
#include <QWidget>
#include "flowlayout.h"
#include "guidededitorelement.h"
#include "abstractguidededitormodel.h"
class GuidedEditorView : public QWidget
{
Q_OBJECT
public:
explicit GuidedEditorView(QWidget *parent = 0);
explicit GuidedEditorView(std::shared_ptr<AbstractGuidedEditorModel> model, QWidget *parent);
~GuidedEditorView();
signals:
public slots:
private:
FlowLayout* editorLayout;
};
#endif // GUIDEDEDITOR_H

View File

@ -4,7 +4,7 @@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
editor = new GuidedEditor(this);
editor = new GuidedEditorView(this);
this->setCentralWidget(editor);
dockWidget = new QDockWidget(this);
this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
@ -15,7 +15,7 @@ MainWindow::MainWindow(QWidget *parent)
QPushButton* button = new QPushButton(dockWidget);
button->setText("add");
dockLayout->addWidget(button);
this->connect(button, &QPushButton::pressed,editor, &GuidedEditor::addElement);
// this->connect(button, &QPushButton::pressed,editor, &GuidedEditorView::addElement);
}

View File

@ -4,7 +4,7 @@
#include <QMainWindow>
#include <QList>
#include "flowlayout.h"
#include "guidededitor.h"
#include "guidededitorview.h"
#include <QGridLayout>
#include <QDockWidget>
@ -12,7 +12,7 @@ class MainWindow : public QMainWindow
{
Q_OBJECT
private:
GuidedEditor* editor;
GuidedEditorView* editor;
QDockWidget* dockWidget;
public:

View File

@ -8,6 +8,8 @@ QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QMAKE_CXXFLAGS += -std=c++14
TARGET = networkpacketcomposer
TEMPLATE = app
@ -16,12 +18,18 @@ SOURCES += main.cpp\
mainwindow.cpp \
flowlayout.cpp \
guidededitorelement.cpp \
guidededitor.cpp
abstractguidededitormodel.cpp \
guidededitorview.cpp \
guidededitorlayer.cpp \
guidededitorelementview.cpp
HEADERS += mainwindow.h \
flowlayout.h \
guidededitorelement.h \
guidededitor.h
abstractguidededitormodel.h \
guidededitorview.h \
guidededitorlayer.h \
guidededitorelementview.h
INCLUDEPATH += $$PWD/../QtGuidedEditor
DEPENDPATH += $$PWD/../QtGuidedEditor