Skip to content

Commit

Permalink
QListWidget, QLineEdit, QTextEdit and QSpinBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Salanto committed Mar 24, 2024
1 parent dc62a09 commit 987377c
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 4 deletions.
114 changes: 110 additions & 4 deletions src/elementstyler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <QComboBox>
#include <QGraphicsDropShadowEffect>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QSpinBox>
#include <QTextEdit>
#include <QWidget>

ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui)
Expand Down Expand Up @@ -35,6 +38,7 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui)
qcombobox_styler["items"] = &ElementStyler::addItems<QComboBox>;
qcombobox_styler["editable"] = &ElementStyler::setEditable<QComboBox>;
qcombobox_styler["placeholder"] = &ElementStyler::setPlaceholderText<QComboBox>;
qcombobox_styler["frame"] = &ElementStyler::setFrame<QComboBox>;
styler["QComboBox"] = qcombobox_styler;

QMap<QString, ElementStylist> qwidget_styler;
Expand All @@ -45,12 +49,42 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui)
styler["QWidget"] = qwidget_styler;

QMap<QString, ElementStylist> qlistwidget_styler;
qwidget_styler["size"] = &ElementStyler::setFixedSize<QListWidget>;
qwidget_styler["position"] = &ElementStyler::move<QListWidget>;
qwidget_styler["visible"] = &ElementStyler::setVisible<QListWidget>;
qwidget_styler["enabled"] = &ElementStyler::setEnabled<QListWidget>;
qlistwidget_styler["size"] = &ElementStyler::setFixedSize<QListWidget>;
qlistwidget_styler["position"] = &ElementStyler::move<QListWidget>;
qlistwidget_styler["visible"] = &ElementStyler::setVisible<QListWidget>;
qlistwidget_styler["enabled"] = &ElementStyler::setEnabled<QListWidget>;
styler["QListWidget"] = qlistwidget_styler;

QMap<QString, ElementStylist> qlineedit_styler;
qlineedit_styler["size"] = &ElementStyler::setFixedSize<QLineEdit>;
qlineedit_styler["position"] = &ElementStyler::move<QLineEdit>;
qlineedit_styler["visible"] = &ElementStyler::setVisible<QLineEdit>;
qlineedit_styler["enabled"] = &ElementStyler::setEnabled<QLineEdit>;
qlineedit_styler["placeholder"] = &ElementStyler::setPlaceholderText<QLineEdit>;
qlineedit_styler["frame"] = &ElementStyler::setFrame<QLineEdit>;
styler["QLineEdit"] = qlineedit_styler;

QMap<QString, ElementStylist> qtextedit_styler;
qtextedit_styler["size"] = &ElementStyler::setFixedSize<QTextEdit>;
qtextedit_styler["position"] = &ElementStyler::move<QTextEdit>;
qtextedit_styler["visible"] = &ElementStyler::setVisible<QTextEdit>;
qtextedit_styler["enabled"] = &ElementStyler::setEnabled<QTextEdit>;
qtextedit_styler["placeholder"] = &ElementStyler::setPlaceholderText<QTextEdit>;
styler["QTextEdit"] = qtextedit_styler;

QMap<QString, ElementStylist> qspinbox_styler;
qspinbox_styler["size"] = &ElementStyler::setFixedSize<QSpinBox>;
qspinbox_styler["position"] = &ElementStyler::move<QSpinBox>;
qspinbox_styler["visible"] = &ElementStyler::setVisible<QSpinBox>;
qspinbox_styler["enabled"] = &ElementStyler::setEnabled<QSpinBox>;
qspinbox_styler["frame"] = &ElementStyler::setFrame<QSpinBox>;
qspinbox_styler["minimum"] = &ElementStyler::setMinimum<QSpinBox>;
qspinbox_styler["maximum"] = &ElementStyler::setMaximum<QSpinBox>;
qspinbox_styler["range"] = &ElementStyler::setRange<QSpinBox>;
qspinbox_styler["prefix"] = &ElementStyler::setPrefix<QSpinBox>;
qspinbox_styler["suffix"] = &ElementStyler::setSuffix<QSpinBox>;
styler["QSpinBox"] = qspinbox_styler;

QMap<QString, ElementStylist> qlabel_styler;
qlabel_styler["text"] = &ElementStyler::setText<QLabel>;
qlabel_styler["image"] = &ElementStyler::setPixmap<QLabel>;
Expand Down Expand Up @@ -328,3 +362,75 @@ void ElementStyler::setPlaceholderText(QString element_id, QString placeholder)
}
pointer->setPlaceholderText(placeholder);
}

template<typename T>
void ElementStyler::setFrame(QString element_id, QString frame_enabled)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set frame rendering enabled";
return;
}
pointer->setFrame(QVariant::fromValue<QString>(frame_enabled).toBool());
}

template<typename T>
void ElementStyler::setMinimum(QString element_id, QString minimum_value)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set minimum value";
return;
}
pointer->setMinimum(QVariant::fromValue<QString>(minimum_value).toInt());
}

template<typename T>
void ElementStyler::setMaximum(QString element_id, QString maximum_value)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set maximum value";
return;
}
pointer->setMaximum(QVariant::fromValue<QString>(maximum_value).toInt());
}

template<typename T>
void ElementStyler::setRange(QString element_id, QString range_list)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set value range";
return;
}

QStringList ranges = range_list.split(",");
if (ranges.size() != 2) {
qDebug() << "Provided range string" << range_list << "is not valid.";
return;
}
pointer->setRange(ranges[0].toInt(), ranges[1].toInt());
}

template<typename T>
void ElementStyler::setSuffix(QString element_id, QString suffix)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set suffix";
return;
}
pointer->setSuffix(suffix);
}

template<typename T>
void ElementStyler::setPrefix(QString element_id, QString suffix)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set prefix";
return;
}
pointer->setPrefix(suffix);
}
18 changes: 18 additions & 0 deletions src/elementstyler.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,26 @@ class ElementStyler : public QObject
template<typename T>
void setEditable(QString element_id, QString editable);

template<typename T>
void setFrame(QString element_id, QString frame_enabled);

template<typename T>
void addItems(QString element_id, QString items);

template<typename T>
void setMinimum(QString element_id, QString minimum_value);

template<typename T>
void setMaximum(QString element_id, QString maximum_value);

template<typename T>
void setRange(QString element_id, QString range_list);

template<typename T>
void setSuffix(QString element_id, QString suffix);

template<typename T>
void setPrefix(QString element_id, QString suffix);
};

#endif // ELEMENTSTYLER_H

0 comments on commit 987377c

Please sign in to comment.