mirror of
https://github.com/IndeemaSoftware/QSimpleScada.git
synced 2026-10-16 21:01:05 +08:00
Refactoring and fitting for dynamic load of qml widgets
This commit is contained in:
+11
-13
@@ -14,7 +14,7 @@ QScadaBoard::QScadaBoard(QWidget *parent) :
|
||||
mEditable{false},
|
||||
mShowGrid{true},
|
||||
mGrid{10},
|
||||
mPixmap{nullptr}
|
||||
mGridPixmap{nullptr}
|
||||
{
|
||||
setPalette(QPalette(Qt::transparent));
|
||||
setAutoFillBackground(true);
|
||||
@@ -82,7 +82,6 @@ void QScadaBoard::createNewObject(int id)
|
||||
{
|
||||
QScadaObjectInfo *lInfo = new QScadaObjectInfo();
|
||||
lInfo->setId(id);
|
||||
lInfo->setShowMarkers(true);
|
||||
lInfo->setShowBackground(true);
|
||||
lInfo->setShowBackgroundImage(false);
|
||||
lInfo->setIsDynamic(true);
|
||||
@@ -95,7 +94,6 @@ void QScadaBoard::createQMLObject(int id, QString path)
|
||||
{
|
||||
QScadaObjectInfo *lInfo = new QScadaObjectInfo();
|
||||
lInfo->setId(id);
|
||||
lInfo->setShowMarkers(true);
|
||||
lInfo->setShowBackground(true);
|
||||
lInfo->setShowBackgroundImage(false);
|
||||
lInfo->setIsDynamic(true);
|
||||
@@ -128,19 +126,19 @@ void QScadaBoard::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void QScadaBoard::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
if (mPixmap == nullptr) {
|
||||
if (mGridPixmap == nullptr) {
|
||||
resetGridPixmap();
|
||||
}
|
||||
|
||||
if ((mPixmap->width() != this->width())
|
||||
|| (mPixmap->height() != this->height())) {
|
||||
delete mPixmap;
|
||||
if ((mGridPixmap->width() != this->width())
|
||||
|| (mGridPixmap->height() != this->height())) {
|
||||
delete mGridPixmap;
|
||||
resetGridPixmap();
|
||||
}
|
||||
|
||||
if (mUpdateGridPixmap) {
|
||||
QPainter lPainter(mPixmap);
|
||||
mPixmap->fill(Qt::white);
|
||||
QPainter lPainter(mGridPixmap);
|
||||
mGridPixmap->fill(Qt::white);
|
||||
QPen lLinepen(Qt::darkGray);
|
||||
lLinepen.setCapStyle(Qt::RoundCap);
|
||||
lLinepen.setWidth(1);
|
||||
@@ -150,8 +148,8 @@ void QScadaBoard::paintEvent(QPaintEvent *e)
|
||||
int lX = this->width();
|
||||
int lY = this->height();
|
||||
|
||||
mPixmap->scaledToWidth(lX);
|
||||
mPixmap->scaledToHeight(lY);
|
||||
mGridPixmap->scaledToWidth(lX);
|
||||
mGridPixmap->scaledToHeight(lY);
|
||||
|
||||
for (int i=0; i<=lX; i++) {
|
||||
for (int j=1; j<=lY; j++) {
|
||||
@@ -163,7 +161,7 @@ void QScadaBoard::paintEvent(QPaintEvent *e)
|
||||
}
|
||||
|
||||
QPainter lPainter(this);
|
||||
lPainter.drawPixmap(0, 0, mPixmap->width(), mPixmap->height(), *mPixmap);
|
||||
lPainter.drawPixmap(0, 0, mGridPixmap->width(), mGridPixmap->height(), *mGridPixmap);
|
||||
|
||||
QWidget::paintEvent(e);
|
||||
}
|
||||
@@ -210,7 +208,7 @@ QList<QScadaObject*> QScadaBoard::getSeletedObjects()
|
||||
|
||||
void QScadaBoard::resetGridPixmap()
|
||||
{
|
||||
mPixmap = new QPixmap(this->width(), this->height());
|
||||
mGridPixmap = new QPixmap(this->width(), this->height());
|
||||
mUpdateGridPixmap = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ private:
|
||||
bool mEditable; //default value false
|
||||
bool mShowGrid; //default value true
|
||||
int mGrid; //default value 10
|
||||
QPixmap *mPixmap;
|
||||
QPixmap *mGridPixmap;
|
||||
bool mUpdateGridPixmap;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ QScadaBoardController::~QScadaBoardController()
|
||||
|
||||
void QScadaBoardController::clearBoard(QScadaBoard* board)
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
|
||||
for (QScadaObject *object : *board->objects()) {
|
||||
board->deleteObject(object);
|
||||
}
|
||||
@@ -45,7 +43,6 @@ void QScadaBoardController::clearBoard(QScadaBoard* board)
|
||||
|
||||
void QScadaBoardController::clearAllBoards()
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
for (QScadaBoard *board:mBoardManager->getBoardList()) {
|
||||
clearBoard(board);
|
||||
}
|
||||
@@ -53,7 +50,6 @@ void QScadaBoardController::clearAllBoards()
|
||||
|
||||
void QScadaBoardController::initConnectedDevices(const QList<QScadaBoardInfo *> list)
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
for (QScadaBoardInfo *boardInfo : list) {
|
||||
if (boardInfo != nullptr) {
|
||||
mBoard->setEditable(false);
|
||||
@@ -68,7 +64,6 @@ void QScadaBoardController::initConnectedDevices(const QList<QScadaBoardInfo *>
|
||||
|
||||
void QScadaBoardController::initBoardForDeviceIp(QString ip)
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
if (mBoard != nullptr
|
||||
&& mBoard->isVisible()) {
|
||||
mBoard->hide();
|
||||
@@ -152,8 +147,6 @@ void QScadaBoardController::updateObjectInfoDialog(QScadaObject *object)
|
||||
|
||||
void QScadaBoardController::deleteObject(QScadaObjectInfo *info)
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
|
||||
if (info != nullptr) {
|
||||
mBoard->deleteObjectWithId(info->id());
|
||||
}
|
||||
@@ -161,8 +154,6 @@ void QScadaBoardController::deleteObject(QScadaObjectInfo *info)
|
||||
|
||||
void QScadaBoardController::updateSavedObject(QScadaObjectInfo *info)
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
|
||||
if (info != nullptr) {
|
||||
mBoard->updateObjectWithId(info->id());
|
||||
}
|
||||
@@ -175,8 +166,6 @@ void QScadaBoardController::objectDoubleClickedHandler(QScadaObject *o)
|
||||
|
||||
void QScadaBoardController::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
|
||||
if (mBoard != nullptr) {
|
||||
mBoard->setGeometry(QRect(0, 0, this->geometry().width(), this->geometry().height()));
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class QScadaBoardManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QScadaBoardManager(QObject *parent = 0);
|
||||
explicit QScadaBoardManager(QObject *parent = nullptr);
|
||||
|
||||
QScadaBoard* getBoardForDeviceWithIp(QString);
|
||||
|
||||
|
||||
@@ -117,8 +117,6 @@ void QConnectedDeviceInfo::initFromXml(const QByteArray &xmlData) {
|
||||
lObjectInfo->setShowBackground((bool)lXmlStreamReader.readElementText().toInt());//new
|
||||
} else if (lXmlStreamReader.name() == tag_show_background_image) {
|
||||
lObjectInfo->setShowBackgroundImage((bool)lXmlStreamReader.readElementText().toInt());//new
|
||||
} else if (lXmlStreamReader.name() == tag_show_marker) {
|
||||
lObjectInfo->setShowMarkers((bool)lXmlStreamReader.readElementText().toInt());//new
|
||||
} else if (lXmlStreamReader.name() == tag_background_image) {
|
||||
lObjectInfo->setBackGroundImage(lXmlStreamReader.readElementText());//new
|
||||
} else if (lXmlStreamReader.name() == tag_is_dynamic) {
|
||||
@@ -223,7 +221,6 @@ QString QConnectedDeviceInfo::XMLFromDeviceInfo(QList<QScadaDeviceInfo> deviceLi
|
||||
rDevices += i.formTagValue(tag_is_dynamic, QString::number(object->info()->isDynamic()), true, 4);
|
||||
rDevices += i.formTagValue(tag_show_background, QString::number(object->info()->showBackground()), true, 4);
|
||||
rDevices += i.formTagValue(tag_show_background_image, QString::number(object->info()->showBackgroundImage()), true, 4);
|
||||
rDevices += i.formTagValue(tag_show_marker, QString::number(object->info()->showMarkers()), true, 4);
|
||||
rDevices += i.formTagValue(tag_background_image, object->info()->backGroundImage(), true, 4);
|
||||
rDevices += i.formTagValue(tag_geometry_x, QString::number(object->info()->geometry().x()), true, 4);
|
||||
rDevices += i.formTagValue(tag_geometry_y, QString::number(object->info()->geometry().y()), true, 4);
|
||||
|
||||
@@ -9,7 +9,6 @@ QScadaObjectInfo::QScadaObjectInfo(QObject *parent) :
|
||||
mOrderLevel{0},
|
||||
mShowBackgroundImage{false},
|
||||
mShowBackground{true},
|
||||
mShowMarkers{true},
|
||||
mFrom{0},
|
||||
mTo{100},
|
||||
mUIResourcePath{""}
|
||||
@@ -26,7 +25,6 @@ QScadaObjectInfo::QScadaObjectInfo(QScadaObjectInfo *o):
|
||||
mBackGroundImage{o->backGroundImage()},
|
||||
mShowBackgroundImage{o->showBackgroundImage()},
|
||||
mShowBackground{o->showBackground()},
|
||||
mShowMarkers{o->showMarkers()},
|
||||
mFrom{0},
|
||||
mTo{100},
|
||||
mUIResourcePath{""}
|
||||
@@ -87,16 +85,6 @@ void QScadaObjectInfo::setShowBackground(bool showBackground)
|
||||
mShowBackground = showBackground;
|
||||
}
|
||||
|
||||
bool QScadaObjectInfo::showMarkers() const
|
||||
{
|
||||
return mShowMarkers;
|
||||
}
|
||||
|
||||
void QScadaObjectInfo::setShowMarkers(bool showMarkers)
|
||||
{
|
||||
mShowMarkers = showMarkers;
|
||||
}
|
||||
|
||||
QString QScadaObjectInfo::backGroundImage() const
|
||||
{
|
||||
return mBackGroundImage;
|
||||
|
||||
@@ -41,9 +41,6 @@ public:
|
||||
bool showBackground() const;
|
||||
void setShowBackground(bool showBackground);
|
||||
|
||||
bool showMarkers() const;
|
||||
void setShowMarkers(bool showMarkers);
|
||||
|
||||
QString backGroundImage() const;
|
||||
void setBackGroundImage(const QString &backGroundImage);
|
||||
|
||||
@@ -85,7 +82,6 @@ private:
|
||||
QString mBackGroundImage;
|
||||
bool mShowBackgroundImage;
|
||||
bool mShowBackground;
|
||||
bool mShowMarkers;
|
||||
|
||||
qreal mFrom;
|
||||
qreal mTo;
|
||||
|
||||
@@ -32,7 +32,6 @@ void QScadaObjectInfoDialog::updateWithObjectInfo(QScadaObjectInfo *info)
|
||||
ui->checkBoxDynamic->setChecked(info->isDynamic());
|
||||
ui->spinBoxId->setValue(info->id());
|
||||
ui->checkBoxShowBackground->setChecked(info->showBackground());
|
||||
ui->checkBoxShowMarkers->setChecked(info->showMarkers());
|
||||
ui->checkBoxShowBackGroundImage->setChecked(mLatestObject->showBackgroundImage());
|
||||
|
||||
mMarkerImage = mLatestObject->backGroundImage();
|
||||
@@ -75,7 +74,6 @@ void QScadaObjectInfoDialog::on_pushButton_2_pressed()
|
||||
|
||||
mLatestObject->setGeometry(QRect(lX, lY, lWidth, lHeight));
|
||||
mLatestObject->setShowBackground(ui->checkBoxShowBackground->isChecked());
|
||||
mLatestObject->setShowMarkers(ui->checkBoxShowMarkers->isChecked());
|
||||
mLatestObject->setShowBackgroundImage(ui->checkBoxShowBackGroundImage->isChecked());
|
||||
//axies
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>360</width>
|
||||
<height>727</height>
|
||||
<width>368</width>
|
||||
<height>658</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
@@ -81,13 +81,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxShowMarkers">
|
||||
<property name="text">
|
||||
<string>Show Markers</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxDynamic">
|
||||
<property name="text">
|
||||
|
||||
+8
-3
@@ -13,6 +13,8 @@ struct QMLInfo {
|
||||
QString groupPath = "";
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QMLInfo)
|
||||
|
||||
struct QMLWidgetsConfig {
|
||||
QMLInfo info;
|
||||
bool isValid = false;
|
||||
@@ -21,8 +23,8 @@ struct QMLWidgetsConfig {
|
||||
return mQMLWidgets;
|
||||
}
|
||||
|
||||
QMLWidgetsConfig(){}
|
||||
QMLWidgetsConfig(QString path){
|
||||
QMLWidgetsConfig() {}
|
||||
QMLWidgetsConfig(QString path) {
|
||||
if (!path.isEmpty()) {
|
||||
QDir directory(path);
|
||||
|
||||
@@ -33,6 +35,7 @@ struct QMLWidgetsConfig {
|
||||
if (lQMLList.count() > 0) {
|
||||
mQMLWidgets = lQMLList;
|
||||
info.groupPath = path;
|
||||
isValid = true;
|
||||
|
||||
QString lTmpTitle = path.split('/').last();
|
||||
//let secure from having / at end or not having
|
||||
@@ -49,6 +52,8 @@ private:
|
||||
QStringList mQMLWidgets;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QMLWidgetsConfig)
|
||||
|
||||
class QMLConfig
|
||||
{
|
||||
private:
|
||||
@@ -70,7 +75,7 @@ class QMLConfig
|
||||
}
|
||||
|
||||
void appendQMLPath(QString path) {
|
||||
QMLWidgetsConfig lConf = QMLWidgetsConfig(path);
|
||||
QMLWidgetsConfig lConf(path);
|
||||
|
||||
if (lConf.isValid) {
|
||||
//check if QML group is unique.
|
||||
|
||||
Reference in New Issue
Block a user