mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Fix some warning and write more modern c++
This commit is contained in:
@@ -65,19 +65,19 @@ void ElementInfoWidget::setElement(Element *element)
|
|||||||
m_element = element;
|
m_element = element;
|
||||||
updateUi();
|
updateUi();
|
||||||
|
|
||||||
ElementInfoPartWidget *f = infoPartWidgetForKey("formula");
|
const auto formula_info_widget = infoPartWidgetForKey(QETInformation::ELMT_FORMULA);
|
||||||
ElementInfoPartWidget *l = infoPartWidgetForKey("label");
|
const auto label_info_widget = infoPartWidgetForKey(QETInformation::ELMT_LABEL);
|
||||||
|
|
||||||
if (f && l)
|
if (formula_info_widget && label_info_widget)
|
||||||
{
|
{
|
||||||
if (f->text().isEmpty())
|
if (formula_info_widget->text().isEmpty())
|
||||||
l->setEnabled(true);
|
label_info_widget->setEnabled(true);
|
||||||
else
|
else
|
||||||
l->setDisabled(true);
|
label_info_widget->setDisabled(true);
|
||||||
|
|
||||||
connect(f, &ElementInfoPartWidget::textChanged, [l](const QString text)
|
connect(formula_info_widget, &ElementInfoPartWidget::textChanged, this, [label_info_widget](const QString text)
|
||||||
{
|
{
|
||||||
l->setEnabled(text.isEmpty()? true : false);
|
label_info_widget->setEnabled(text.isEmpty()? true : false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ void ElementInfoWidget::setElement(Element *element)
|
|||||||
*/
|
*/
|
||||||
void ElementInfoWidget::apply()
|
void ElementInfoWidget::apply()
|
||||||
{
|
{
|
||||||
if (QUndoCommand *undo = associatedUndo())
|
if (auto undo = associatedUndo())
|
||||||
m_element -> diagram() -> undoStack().push(undo);
|
m_element -> diagram() -> undoStack().push(undo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +104,8 @@ void ElementInfoWidget::apply()
|
|||||||
*/
|
*/
|
||||||
QUndoCommand* ElementInfoWidget::associatedUndo() const
|
QUndoCommand* ElementInfoWidget::associatedUndo() const
|
||||||
{
|
{
|
||||||
DiagramContext new_info = currentInfo();
|
const auto new_info = currentInfo();
|
||||||
DiagramContext old_info = m_element -> elementInformations();
|
const auto old_info = m_element -> elementInformations();
|
||||||
|
|
||||||
if (old_info != new_info)
|
if (old_info != new_info)
|
||||||
return (new ChangeElementInformationCommand(m_element, old_info, new_info));
|
return (new ChangeElementInformationCommand(m_element, old_info, new_info));
|
||||||
@@ -179,11 +179,11 @@ void ElementInfoWidget::disableLiveEdit()
|
|||||||
void ElementInfoWidget::buildInterface()
|
void ElementInfoWidget::buildInterface()
|
||||||
{
|
{
|
||||||
QStringList keys;
|
QStringList keys;
|
||||||
auto type_ = m_element.data()->elementData().m_type;
|
if (m_element.data()->elementData().m_type == ElementData::Terminale) {
|
||||||
if (type_ == ElementData::Terminale)
|
|
||||||
keys = QETInformation::terminalElementInfoKeys();
|
keys = QETInformation::terminalElementInfoKeys();
|
||||||
else
|
} else {
|
||||||
keys = QETInformation::elementInfoKeys();
|
keys = QETInformation::elementInfoKeys();
|
||||||
|
}
|
||||||
|
|
||||||
for (auto str : keys)
|
for (auto str : keys)
|
||||||
{
|
{
|
||||||
@@ -203,7 +203,7 @@ void ElementInfoWidget::buildInterface()
|
|||||||
*/
|
*/
|
||||||
ElementInfoPartWidget *ElementInfoWidget::infoPartWidgetForKey(const QString &key) const
|
ElementInfoPartWidget *ElementInfoWidget::infoPartWidgetForKey(const QString &key) const
|
||||||
{
|
{
|
||||||
for (auto eipw : m_eipw_list)
|
for (const auto &eipw : qAsConst(m_eipw_list))
|
||||||
{
|
{
|
||||||
if (eipw->key() == key)
|
if (eipw->key() == key)
|
||||||
return eipw;
|
return eipw;
|
||||||
@@ -226,7 +226,7 @@ void ElementInfoWidget::updateUi()
|
|||||||
//We disable live edit to avoid wrong undo when we fill the line edit with new text
|
//We disable live edit to avoid wrong undo when we fill the line edit with new text
|
||||||
if (m_live_edit) disableLiveEdit();
|
if (m_live_edit) disableLiveEdit();
|
||||||
|
|
||||||
DiagramContext element_info = m_element->elementInformations();
|
const auto element_info{m_element->elementInformations()};
|
||||||
|
|
||||||
for (ElementInfoPartWidget *eipw : m_eipw_list) {
|
for (ElementInfoPartWidget *eipw : m_eipw_list) {
|
||||||
eipw -> setText (element_info[eipw->key()].toString());
|
eipw -> setText (element_info[eipw->key()].toString());
|
||||||
@@ -245,16 +245,16 @@ DiagramContext ElementInfoWidget::currentInfo() const
|
|||||||
{
|
{
|
||||||
DiagramContext info_;
|
DiagramContext info_;
|
||||||
|
|
||||||
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
for (const auto &eipw : qAsConst(m_eipw_list))
|
||||||
{
|
{
|
||||||
|
|
||||||
//add value only if they're something to store
|
//add value only if they're something to store
|
||||||
if (!eipw->text().isEmpty())
|
if (!eipw->text().isEmpty())
|
||||||
{
|
{
|
||||||
QString txt = eipw->text();
|
QString txt{eipw->text()};
|
||||||
//remove line feed and carriage return
|
//remove line feed and carriage return
|
||||||
txt.remove("\r");
|
txt.remove(QStringLiteral("\r"));
|
||||||
txt.remove("\n");
|
txt.remove(QStringLiteral("\n"));
|
||||||
info_.addValue(eipw->key(), txt);
|
info_.addValue(eipw->key(), txt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
*/
|
*/
|
||||||
ChangeElementInformationCommand::ChangeElementInformationCommand(
|
ChangeElementInformationCommand::ChangeElementInformationCommand(
|
||||||
Element *elmt,
|
Element *elmt,
|
||||||
DiagramContext &old_info,
|
const DiagramContext &old_info,
|
||||||
DiagramContext &new_info,
|
const DiagramContext &new_info,
|
||||||
QUndoCommand *parent) :
|
QUndoCommand *parent) :
|
||||||
QUndoCommand (parent)
|
QUndoCommand (parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class ChangeElementInformationCommand : public QUndoCommand
|
|||||||
public:
|
public:
|
||||||
ChangeElementInformationCommand(
|
ChangeElementInformationCommand(
|
||||||
Element *elmt,
|
Element *elmt,
|
||||||
DiagramContext &old_info,
|
const DiagramContext &old_info,
|
||||||
DiagramContext &new_info,
|
const DiagramContext &new_info,
|
||||||
QUndoCommand *parent = nullptr);
|
QUndoCommand *parent = nullptr);
|
||||||
|
|
||||||
ChangeElementInformationCommand(QMap<QPointer<Element>, QPair<DiagramContext, DiagramContext>> map,
|
ChangeElementInformationCommand(QMap<QPointer<Element>, QPair<DiagramContext, DiagramContext>> map,
|
||||||
|
|||||||
Reference in New Issue
Block a user