Skip to content

Commit

Permalink
Rename widgetbuilder to elementbuilder
Browse files Browse the repository at this point in the history
It does a lot more than just widgets
  • Loading branch information
Salanto committed Mar 25, 2024
1 parent ec1b26f commit dcb0ea8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif()
add_executable(SpriteUILoader
src/main.cpp
src/layoutloader.h src/layoutloader.cpp
src/widgetbuilder.h src/widgetbuilder.cpp
src/elementbuilder.h src/elementbuilder.cpp
src/layoutparseerror.h src/layoutparseerror.cpp
src/spriteuiloader.h src/spriteuiloader.cpp
src/xmlinputwindow.h src/xmlinputwindow.cpp
Expand Down
44 changes: 22 additions & 22 deletions src/widgetbuilder.cpp → src/elementbuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "widgetbuilder.h"
#include "ElementBuilder.h"

#include <QDebug>
#include <QLayout>
Expand All @@ -8,14 +8,14 @@
#include "elementstyler.h"
#include "spriteuiloader.h"

WidgetBuilder::WidgetBuilder(QObject *parent)
ElementBuilder::ElementBuilder(QObject *parent)
: QObject(parent)
{
loader = new SpriteUiLoader(this);
root_widget = new QWidget(nullptr);
}

void WidgetBuilder::createRootWidget(const QDomNode &nodes)
void ElementBuilder::createRootWidget(const QDomNode &nodes)
{
QMap<QString, QString> element_properties = parseAttributes(nodes.attributes());
loader->createWidget(nodes.nodeName(), root_widget, element_properties.value("id"));
Expand All @@ -33,7 +33,7 @@ void WidgetBuilder::createRootWidget(const QDomNode &nodes)
}
}

void WidgetBuilder::createChildElement(const QDomNodeList &nodes, QString parent_id)
void ElementBuilder::createChildElement(const QDomNodeList &nodes, QString parent_id)
{
QString parent_type = element_classes.value(parent_id);
for (int index = 0; index < nodes.size(); ++index) {
Expand Down Expand Up @@ -94,7 +94,7 @@ void WidgetBuilder::createChildElement(const QDomNodeList &nodes, QString parent
}
}

QMap<QString, QString> WidgetBuilder::parseAttributes(QDomNamedNodeMap attribute_nodes)
QMap<QString, QString> ElementBuilder::parseAttributes(QDomNamedNodeMap attribute_nodes)
{
QMap<QString, QString> attributes;
for (int attribute = 0; attribute < attribute_nodes.size(); ++attribute) {
Expand All @@ -104,28 +104,28 @@ QMap<QString, QString> WidgetBuilder::parseAttributes(QDomNamedNodeMap attribute
return attributes;
}

void WidgetBuilder::appendWidgetToWidget(QString parent_widget,
QString widget_type,
QString child_widget)
void ElementBuilder::appendWidgetToWidget(QString parent_widget,
QString widget_type,
QString child_widget)
{
qDebug() << "Creating widget with name" << child_widget;
QWidget *parent = objectPointer<QWidget *>(parent_widget);
loader->createWidget(widget_type, parent, child_widget);
}

void WidgetBuilder::appendWidgetToLayout(QString parent_layout,
QString widget_type,
QString child_widget)
void ElementBuilder::appendWidgetToLayout(QString parent_layout,
QString widget_type,
QString child_widget)
{
qDebug() << "Creating widget with name" << child_widget;
QLayout *parent = objectPointer<QLayout *>(parent_layout);
QWidget *widget = loader->createWidget(widget_type, nullptr, child_widget);
parent->addWidget(widget);
}

void WidgetBuilder::appendLayoutToWidget(QString parent_widget,
QString layout_type,
QString child_layout)
void ElementBuilder::appendLayoutToWidget(QString parent_widget,
QString layout_type,
QString child_layout)
{
qDebug() << root_widget;
qDebug() << "Creating layout with name" << child_layout;
Expand All @@ -134,9 +134,9 @@ void WidgetBuilder::appendLayoutToWidget(QString parent_widget,
parent->setLayout(layout);
}

void WidgetBuilder::appendLayoutToLayout(QString parent_layout,
QString layout_type,
QString child_layout)
void ElementBuilder::appendLayoutToLayout(QString parent_layout,
QString layout_type,
QString child_layout)
{
qDebug() << "Creating layout with name" << child_layout;
QBoxLayout *parent = objectPointer<QBoxLayout *>(parent_layout);
Expand All @@ -148,17 +148,17 @@ void WidgetBuilder::appendLayoutToLayout(QString parent_layout,
parent->addLayout(layout);
}

void WidgetBuilder::appendEffectToWidget(QString parent_widget,
QString effect_type,
QString child_effect)
void ElementBuilder::appendEffectToWidget(QString parent_widget,
QString effect_type,
QString child_effect)
{
qDebug() << "Creating effect with name" << child_effect;
QWidget *parent = objectPointer<QWidget *>(parent_widget);
QGraphicsEffect *effect = loader->createEffect(effect_type, parent, child_effect);
parent->setGraphicsEffect(effect);
}

QWidget *WidgetBuilder::ui()
QWidget *ElementBuilder::ui()
{
// This step will be unecessary in production code as we would reparent to a QMainWindow.
qDebug() << "Main widget name" << root_widget_name;
Expand All @@ -171,7 +171,7 @@ QWidget *WidgetBuilder::ui()
}

template<typename T>
T WidgetBuilder::objectPointer(QString object_name)
T ElementBuilder::objectPointer(QString object_name)
{
return root_widget->findChild<T>(object_name);
}
12 changes: 6 additions & 6 deletions src/widgetbuilder.h → src/elementbuilder.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#ifndef WIDGETBUILDER_H
#define WIDGETBUILDER_H
#ifndef ELEMENTBUILDER_H
#define ELEMENTBUILDER_H

#include <QDomNode>
#include <QMap>
#include <QObject>

class SpriteUiLoader;

class WidgetBuilder : public QObject
class ElementBuilder : public QObject
{
Q_OBJECT
public:
explicit WidgetBuilder(QObject *parent);
~WidgetBuilder(){};
explicit ElementBuilder(QObject *parent);
~ElementBuilder(){};

void createRootWidget(const QDomNode &nodes);
void createChildElement(const QDomNodeList &nodes, QString parent_id);
Expand Down Expand Up @@ -40,4 +40,4 @@ class WidgetBuilder : public QObject
QMap<QString, QMap<QString, QString>> widget_configuration;
};

#endif // WIDGETBUILDER_H
#endif // ELEMENTBUILDER_H
6 changes: 3 additions & 3 deletions src/layoutloader.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "layoutloader.h"
#include "widgetbuilder.h"
#include "elementbuilder.h"

#include <QDebug>

LayoutLoader::LayoutLoader(QObject *parent)
: QObject{parent}
{
builder = new WidgetBuilder(this);
builder = new ElementBuilder(this);
}

void LayoutLoader::loadDocument(const QByteArray file)
Expand Down Expand Up @@ -53,7 +53,7 @@ void LayoutLoader::reset()
{
document.clear();
builder->deleteLater();
builder = new WidgetBuilder(this);
builder = new ElementBuilder(this);
}

LayoutLoader::VersionInformation LayoutLoader::parseVersion(QDomNode node)
Expand Down
4 changes: 2 additions & 2 deletions src/layoutloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "layoutparseerror.h"

class WidgetBuilder;
class ElementBuilder;

class LayoutLoader : public QObject
{
Expand Down Expand Up @@ -40,7 +40,7 @@ public Q_SLOTS:
VersionInformation parseVersion(QDomNode node);
void reset();

WidgetBuilder *builder;
ElementBuilder *builder;
QDomDocument document;
const int COMPATIBLE_VERSION = 1;
const QString COMPATIBLE_STYLE = "SPRITECHAT";
Expand Down

0 comments on commit dcb0ea8

Please sign in to comment.