Finish lerge refactor of systems
This commit is contained in:
parent
6d742e60db
commit
913d7df56d
36 changed files with 614 additions and 634 deletions
|
|
@ -21,18 +21,9 @@ void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
|||
{
|
||||
if(auto workItem = item.lock())
|
||||
{
|
||||
if(dynamic_cast<AuxItem*>(workItem.get()))
|
||||
{
|
||||
widgets_.push_back(new ItemWidget(item, true));
|
||||
}
|
||||
else if(dynamic_cast<MessageItem*>(workItem.get()))
|
||||
{
|
||||
widgets_.push_back(new ItemWidget(item, false, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
widgets_.push_back(new ItemWidget(item));
|
||||
}
|
||||
if(workItem->isHidden())
|
||||
return;
|
||||
widgets_.push_back(new ItemWidget(item));
|
||||
ui->relayWidgetVbox->addWidget(widgets_.back());
|
||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
||||
|
|
|
|||
|
|
@ -5,39 +5,47 @@
|
|||
#include <QDebug>
|
||||
#include <QSlider>
|
||||
|
||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, bool nameOnly, QWidget *parent) :
|
||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
item_(item),
|
||||
ui(new Ui::ItemWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if(analog)
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
ui->horizontalSpacer->changeSize(0,0);
|
||||
ui->checkBox->hide();
|
||||
}
|
||||
else if(nameOnly)
|
||||
{
|
||||
ui->checkBox->hide();
|
||||
ui->slider->hide();
|
||||
}
|
||||
else ui->slider->hide();
|
||||
if(workingItem->getValueType() == ITEM_VALUE_UINT)
|
||||
{
|
||||
ui->horizontalSpacer->changeSize(0,0);
|
||||
ui->checkBox->hide();
|
||||
}
|
||||
else if(workingItem->getValueType() == ITEM_VALUE_NO_VALUE)
|
||||
{
|
||||
ui->checkBox->hide();
|
||||
ui->slider->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->slider->hide();
|
||||
}
|
||||
|
||||
if(auto workingRelay = item_.lock())
|
||||
{
|
||||
ui->checkBox->setChecked(workingRelay->getValue());
|
||||
ui->checkBox->setChecked(workingItem->getValue());
|
||||
|
||||
ui->label->setText(workingRelay->getName());
|
||||
ui->label->setText(workingItem->getName());
|
||||
|
||||
if(analog)connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
|
||||
else connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
||||
if(workingItem->getValueType() == ITEM_VALUE_UINT)
|
||||
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
|
||||
else
|
||||
connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
||||
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
||||
connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
|
||||
connect(workingItem.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
|
||||
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
|
||||
|
||||
}
|
||||
else disable();
|
||||
else
|
||||
{
|
||||
disable();
|
||||
}
|
||||
}
|
||||
|
||||
void ItemWidget::deleteItem()
|
||||
|
|
@ -50,14 +58,18 @@ void ItemWidget::deleteItem()
|
|||
|
||||
void ItemWidget::moveToValue(int value)
|
||||
{
|
||||
if(auto workingItem = item_.lock()) workingItem->setValue(value);
|
||||
else disable();
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setValue(value);
|
||||
else
|
||||
disable();
|
||||
}
|
||||
|
||||
void ItemWidget::moveToState(bool state)
|
||||
{
|
||||
if(auto workingItem = item_.lock()) workingItem->setValue(state);
|
||||
else disable();
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setValue(state);
|
||||
else
|
||||
disable();
|
||||
}
|
||||
|
||||
void ItemWidget::disable()
|
||||
|
|
@ -70,9 +82,9 @@ void ItemWidget::disable()
|
|||
|
||||
bool ItemWidget::controles(const ItemData& relay)
|
||||
{
|
||||
if(auto workingRelay = item_.lock())
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
if(relay == *workingRelay) return true;
|
||||
if(relay == *workingItem) return true;
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -80,9 +92,9 @@ bool ItemWidget::controles(const ItemData& relay)
|
|||
|
||||
void ItemWidget::showSettingsDialog()
|
||||
{
|
||||
if(auto workingRelay = item_.lock())
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
ItemSettingsDialog dialog(workingRelay, this);
|
||||
ItemSettingsDialog dialog(workingItem, this);
|
||||
dialog.exec();
|
||||
}
|
||||
else disable();
|
||||
|
|
@ -95,7 +107,6 @@ std::weak_ptr<Item> ItemWidget::getItem()
|
|||
|
||||
void ItemWidget::stateChanged(int state)
|
||||
{
|
||||
qDebug()<<"widget got state "<<state;
|
||||
ui->slider->blockSignals(true);
|
||||
ui->slider->setValue(state);
|
||||
ui->slider->blockSignals(false);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ private slots:
|
|||
void deleteItem();
|
||||
|
||||
public:
|
||||
explicit ItemWidget(std::weak_ptr<Item> item, bool analog = false, bool nameOnly = false, QWidget *parent = nullptr);
|
||||
explicit ItemWidget(std::weak_ptr<Item> item, QWidget *parent = nullptr);
|
||||
std::weak_ptr<Item> getItem();
|
||||
bool controles(const ItemData& relay);
|
||||
~ItemWidget();
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
|
@ -46,10 +46,10 @@
|
|||
<number>255</number>
|
||||
</property>
|
||||
<property name="tracking">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "ui_mainwindow.h"
|
||||
#include "itemscrollbox.h"
|
||||
#include "itemsettingsdialog.h"
|
||||
#include "itemcreationdialog.h"
|
||||
#include "../mainobject.h"
|
||||
#include <QMessageBox>
|
||||
#include "src/mainobject.h"
|
||||
#include "src/programmode.h"
|
||||
#include "src/items/poweritem.h"
|
||||
|
||||
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
|
@ -24,15 +28,20 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
|||
for(size_t i = 0; i < globalItems.getItems()->size(); ++i)
|
||||
ui->relayList->addItem(globalItems.getItems()->at(i));
|
||||
|
||||
if(programMode != PROGRAM_MODE_PRIMARY)
|
||||
ui->label_serialRecive->setHidden(true);
|
||||
|
||||
//Sensors
|
||||
ui->sensorListView->setShowHidden(false);
|
||||
ui->sensorListView->sensorsChanged(*globalSensors.getSensors());
|
||||
connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
|
||||
|
||||
//RGB Leds
|
||||
connect(&colorChooser, SIGNAL(colorSelected(QColor)), this, SLOT(slotChangedRgb(QColor)));
|
||||
connect(&colorChooser, &QColorDialog::colorSelected, this, &MainWindow::sigSetRgb);
|
||||
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
|
||||
if(programMode != PROGRAM_MODE_PRIMARY)
|
||||
ui->button_color->hide();
|
||||
|
||||
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
||||
connect(ui->relayList, &ItemScrollBox::deleteRequest, &globalItems, &ItemStore::removeItem);
|
||||
|
|
@ -47,25 +56,30 @@ MainWindow::~MainWindow()
|
|||
|
||||
void MainWindow::showPowerItemDialog()
|
||||
{
|
||||
ItemSettingsDialog diag(std::shared_ptr<Item>(_powerItem), this);
|
||||
diag.show();
|
||||
diag.exec();
|
||||
std::shared_ptr<PowerItem> powerItem;
|
||||
for(std::shared_ptr<Item> item : *globalItems.getItems())
|
||||
{
|
||||
powerItem = std::dynamic_pointer_cast<PowerItem>(item);
|
||||
if(powerItem)
|
||||
break;
|
||||
}
|
||||
if(powerItem)
|
||||
{
|
||||
ItemSettingsDialog diag(std::shared_ptr<Item>(powerItem), this);
|
||||
diag.show();
|
||||
diag.exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, "Error", "No power item found, refresh first");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::slotChangedRgb(const QColor color)
|
||||
{
|
||||
(void)color;
|
||||
//_micro->changeRgbColor(color);
|
||||
}
|
||||
|
||||
void MainWindow::showItemCreationDialog()
|
||||
{
|
||||
ItemCreationDialog diag(this);
|
||||
diag.show();
|
||||
if(diag.exec())
|
||||
{
|
||||
createdItem(diag.item);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::changeHeaderLableText(QString string)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#include <QListWidgetItem>
|
||||
#include <QTime>
|
||||
#include <memory>
|
||||
#include "src/items/poweritem.h"
|
||||
|
||||
#include<src/items/item.h>
|
||||
|
||||
class MainObject;
|
||||
|
||||
|
|
@ -29,17 +29,15 @@ private:
|
|||
|
||||
QColorDialog colorChooser;
|
||||
|
||||
std::shared_ptr<PowerItem> _powerItem;
|
||||
|
||||
signals:
|
||||
|
||||
void sigSave();
|
||||
void createdItem(std::shared_ptr<Item> item);
|
||||
void sigSetRgb(const QColor color);
|
||||
|
||||
private slots:
|
||||
|
||||
//RGB
|
||||
void slotChangedRgb(const QColor color);
|
||||
void showPowerItemDialog();
|
||||
void showItemCreationDialog();
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="1,0">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
|
|
@ -114,44 +114,6 @@
|
|||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_color">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_power">
|
||||
<property name="text">
|
||||
<string>Config Shutdown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
@ -194,49 +156,91 @@
|
|||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_refesh">
|
||||
<property name="text">
|
||||
<string>Refesh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_broadcast">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_addItem">
|
||||
<property name="text">
|
||||
<string>Add Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_quit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LayoutDirection::RightToLeft</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_power">
|
||||
<property name="text">
|
||||
<string>Config Shutdown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_color">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_refesh">
|
||||
<property name="text">
|
||||
<string>Refesh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_broadcast">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_addItem">
|
||||
<property name="text">
|
||||
<string>Add Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_quit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LayoutDirection::RightToLeft</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue