Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYFormDialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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  QLineEdit* pObject = nullptr;
36  QObjectList objectsList = children();
37 
38  // Search default button
39  for (int i = 0; i < objectsList.size(); i++)
40  {
41  pDefaultButton = dynamic_cast<QPushButton*>(objectsList[i]);
42  if (pDefaultButton != nullptr && pDefaultButton->isDefault())
43  {
44  break;
45  }
46  }
47 
48  // If there is a default button then validate
49  if (pDefaultButton != nullptr)
50  {
51  isValidated = validateChildren(this);
52  pDefaultButton->setEnabled(isValidated);
53  }
54  else
55  {
56  isValidated = false;
57  }
58  return isValidated;
59 }
60 
61 bool TYFormDialog::validateChildren(QObject* object)
62 {
63  bool ret = true;
64 
65  QLineEdit* pQLineEdit = nullptr;
66  pQLineEdit = dynamic_cast<QLineEdit*>(object);
67  // If it is a QLineEdit, then validate it
68  if (pQLineEdit != nullptr)
69  {
70  ret = ret && (pQLineEdit->hasAcceptableInput() || !pQLineEdit->isEnabled());
71  }
72  else
73  // Else validate its children
74  {
75  QObject* pObject = nullptr;
76  QObjectList objectsList = object->children();
77  for (int i = 0; i < objectsList.size(); i++)
78  {
79  ret = ret && validateChildren(objectsList[i]);
80  }
81  }
82  return ret;
83 }
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))