Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYFormDialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
23 #include <QLineEdit>
24 
26 
27 #include "TYFormDialog.h"
28 
29 TYFormDialog::TYFormDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) {}
30 
32 {
33  bool isValidated = true;
34  QPushButton* pDefaultButton = nullptr;
35  QObjectList objectsList = children();
36 
37  // Search default button
38  for (int i = 0; i < objectsList.size(); i++)
39  {
40  pDefaultButton = dynamic_cast<QPushButton*>(objectsList[i]);
41  if (pDefaultButton != nullptr && pDefaultButton->isDefault())
42  {
43  break;
44  }
45  }
46 
47  // If there is a default button then validate
48  if (pDefaultButton != nullptr)
49  {
50  isValidated = validateChildren(this);
51  pDefaultButton->setEnabled(isValidated);
52  }
53  else
54  {
55  isValidated = false;
56  }
57  return isValidated;
58 }
59 
60 bool TYFormDialog::validateChildren(QObject* object)
61 {
62  bool ret = true;
63 
64  QLineEdit* pQLineEdit = nullptr;
65  pQLineEdit = dynamic_cast<QLineEdit*>(object);
66  // If it is a QLineEdit, then validate it
67  if (pQLineEdit != nullptr)
68  {
69  bool valid = (pQLineEdit->hasAcceptableInput() || !pQLineEdit->isEnabled());
70  if (!valid)
71  {
72  pQLineEdit->setStyleSheet("QLineEdit { border: 2px solid red; color: red;}");
73  }
74  ret = ret && valid;
75  }
76  else
77  // Else validate its children
78  {
79  QObjectList objectsList = object->children();
80  for (int i = 0; i < objectsList.size(); i++)
81  {
82  ret = ret & validateChildren(objectsList[i]);
83  }
84  }
85  return ret;
86 }
Parent class of Tympan Qt dialogs of type form (geader file)
outil IHM pour une entrée utilisateur (fichier header)
bool validateChildren(QObject *object)
TYFormDialog(QWidget *parent=nullptr, Qt::WindowFlags f=QFlag(0))