Terminal strip item can be added to diagram

Initial commit about graphics item of a terminal strip, Work in
progress.
This commit is contained in:
joshua
2022-08-27 21:24:25 +02:00
parent d9a0b03e23
commit ff80453f2c
13 changed files with 751 additions and 3 deletions

View File

@@ -0,0 +1,85 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "addterminalstripitemdialog.h"
#include "ui_addterminalstripitemdialog.h"
#include "../terminalstrip.h"
#include "../GraphicsItem/terminalstripitem.h"
#include "../../diagram.h"
void AddTerminalStripItemDialog::openDialog(Diagram *diagram, QWidget *parent)
{
AddTerminalStripItemDialog d(diagram->project(), parent);
if (d.exec())
{
const auto strip_{d.selectedTerminalStrip()};
if (strip_)
{
auto item_ = new TerminalStripItem(strip_);
diagram->addItem(item_);
item_->setPos(20, 20);
}
}
}
AddTerminalStripItemDialog::AddTerminalStripItemDialog(QETProject *project, QWidget *parent) :
QDialog{parent},
m_project{project},
ui{new Ui::AddTerminalStripItemDialog}
{
ui->setupUi(this);
fillComboBox();
}
AddTerminalStripItemDialog::~AddTerminalStripItemDialog()
{
delete ui;
}
/**
* @brief AddTerminalStripItemDialog::selectedTerminalStrip
* @return The selected terminal strip or nullptr if no one is selected
* or error encounted.
*/
TerminalStrip *AddTerminalStripItemDialog::selectedTerminalStrip() const
{
if (m_project)
{
QUuid uuid_{ui->m_terminal_strip_cb->currentData().toUuid()};
for (const auto &strip_ : m_project->terminalStrip())
{
if (strip_->uuid() == uuid_) {
return strip_;
}
}
}
return nullptr;
}
void AddTerminalStripItemDialog::fillComboBox()
{
if (m_project)
{
for (const auto strip_ : m_project->terminalStrip())
{
const auto text{strip_->installation() + " " + strip_->location() + " " + strip_->name()};
ui->m_terminal_strip_cb->addItem(text, strip_->uuid());
}
}
}

View File

@@ -0,0 +1,51 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADDTERMINALSTRIPITEMDIALOG_H
#define ADDTERMINALSTRIPITEMDIALOG_H
#include <QDialog>
#include <QPointer>
class Diagram;
class QETDiagramEditor;
class QETProject;
class TerminalStrip;
namespace Ui {
class AddTerminalStripItemDialog;
}
class AddTerminalStripItemDialog : public QDialog
{
Q_OBJECT
public:
static void openDialog(Diagram *diagram, QWidget *parent = nullptr);
private:
explicit AddTerminalStripItemDialog(QETProject *project, QWidget *parent = nullptr);
~AddTerminalStripItemDialog();
TerminalStrip *selectedTerminalStrip() const;
void fillComboBox();
private:
QPointer<QETProject> m_project;
Ui::AddTerminalStripItemDialog *ui;
};
#endif // ADDTERMINALSTRIPITEMDIALOG_H

View File

@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddTerminalStripItemDialog</class>
<widget class="QDialog" name="AddTerminalStripItemDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>326</width>
<height>100</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Ajouter le plan de bornes suivant :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_terminal_strip_cb"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AddTerminalStripItemDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AddTerminalStripItemDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>