Wrap code for better readability

This commit is contained in:
Simon De Backer
2020-08-28 18:32:24 +02:00
parent d8cbcf3b54
commit f4550ab3b4
3 changed files with 51 additions and 28 deletions

View File

@@ -50,7 +50,9 @@ SelectAutonumW::SelectAutonumW(int type, QWidget *parent) :
setContext(NumerotationContext()); setContext(NumerotationContext());
} }
SelectAutonumW::SelectAutonumW(const NumerotationContext &context, int type, QWidget *parent) : SelectAutonumW::SelectAutonumW(const NumerotationContext &context,
int type,
QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::SelectAutonumW), ui(new Ui::SelectAutonumW),
m_edited_type(type) m_edited_type(type)
@@ -85,7 +87,8 @@ SelectAutonumW::~SelectAutonumW()
selected in the diagram_chooser QcomboBox selected in the diagram_chooser QcomboBox
@param context @param context
*/ */
void SelectAutonumW::setContext(const NumerotationContext &context) { void SelectAutonumW::setContext(const NumerotationContext &context)
{
m_context = context; m_context = context;
qDeleteAll(num_part_list_); qDeleteAll(num_part_list_);
@@ -114,7 +117,8 @@ void SelectAutonumW::setContext(const NumerotationContext &context) {
@brief SelectAutonumW::toNumContext @brief SelectAutonumW::toNumContext
@return the content to num_part_list to NumerotationContext @return the content to num_part_list to NumerotationContext
*/ */
NumerotationContext SelectAutonumW::toNumContext() const { NumerotationContext SelectAutonumW::toNumContext() const
{
NumerotationContext nc; NumerotationContext nc;
foreach (NumPartEditorW *npew, num_part_list_) foreach (NumPartEditorW *npew, num_part_list_)
nc << npew -> toNumContext(); nc << npew -> toNumContext();
@@ -139,7 +143,8 @@ void SelectAutonumW::on_add_button_clicked()
@brief SelectAutonumW::on_remove_button_clicked @brief SelectAutonumW::on_remove_button_clicked
* Action on remove button, remove the last NumPartEditor * Action on remove button, remove the last NumPartEditor
*/ */
void SelectAutonumW::on_remove_button_clicked() { void SelectAutonumW::on_remove_button_clicked()
{
//remove if @num_part_list contains more than one item //remove if @num_part_list contains more than one item
if (num_part_list_.size() > 1) { if (num_part_list_.size() > 1) {
NumPartEditorW *part = num_part_list_.takeLast(); NumPartEditorW *part = num_part_list_.takeLast();
@@ -246,17 +251,20 @@ void SelectAutonumW::on_buttonBox_clicked(QAbstractButton *button) {
@brief SelectAutonumW::applyEnable @brief SelectAutonumW::applyEnable
enable/disable the apply button enable/disable the apply button
*/ */
void SelectAutonumW::applyEnable(bool b) { void SelectAutonumW::applyEnable(bool b)
{
if (b){ if (b){
bool valid= true; bool valid= true;
foreach (NumPartEditorW *npe, num_part_list_) foreach (NumPartEditorW *npe, num_part_list_)
if (!npe -> isValid()) if (!npe -> isValid())
valid= false; valid= false;
ui -> buttonBox -> button(QDialogButtonBox::Apply) -> setEnabled(valid); ui->buttonBox->button(QDialogButtonBox::Apply)
->setEnabled(valid);
} }
else { else {
ui -> buttonBox -> button(QDialogButtonBox::Apply) -> setEnabled(b); ui->buttonBox->button(QDialogButtonBox::Apply)
->setEnabled(b);
} }
if (m_edited_type == 0) if (m_edited_type == 0)
contextToFormula(); contextToFormula();
@@ -279,7 +287,8 @@ void SelectAutonumW::contextToFormula()
if (m_faw) if (m_faw)
{ {
m_faw->clearContext(); m_faw->clearContext();
m_faw->setContext(autonum::numerotationContextToFormula(toNumContext())); m_faw->setContext(autonum::numerotationContextToFormula(
toNumContext()));
} }
} }

View File

@@ -31,6 +31,9 @@ namespace Ui {
class SelectAutonumW; class SelectAutonumW;
} }
/**
@brief The SelectAutonumW class
*/
class SelectAutonumW : public QWidget class SelectAutonumW : public QWidget
{ {
Q_OBJECT Q_OBJECT
@@ -38,7 +41,9 @@ class SelectAutonumW : public QWidget
//METHODS //METHODS
public: public:
explicit SelectAutonumW(int type, QWidget *parent = nullptr); explicit SelectAutonumW(int type, QWidget *parent = nullptr);
explicit SelectAutonumW(const NumerotationContext &context, int type, QWidget *parent = nullptr); explicit SelectAutonumW(const NumerotationContext &context,
int type,
QWidget *parent = nullptr);
~SelectAutonumW() override; ~SelectAutonumW() override;
void setContext (const NumerotationContext &context); void setContext (const NumerotationContext &context);
@@ -70,7 +75,7 @@ class SelectAutonumW : public QWidget
NumerotationContext m_context; NumerotationContext m_context;
FormulaAutonumberingW *m_feaw; FormulaAutonumberingW *m_feaw;
FormulaAutonumberingW *m_fcaw; FormulaAutonumberingW *m_fcaw;
int m_edited_type = -1; //0 == element : 1 == conductor : 2 == folio int m_edited_type = -1; ///<0 == element : 1 == conductor : 2 == folio
}; };
#endif // SELECTAUTONUMW_H #endif // SELECTAUTONUMW_H

View File

@@ -175,14 +175,15 @@ bool QET::orthogonalProjection(const QPointF &point,
// determine le point d'intersection des deux droites = le projete orthogonal // determine le point d'intersection des deux droites = le projete orthogonal
QPointF intersection_point; QPointF intersection_point;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QLineF::IntersectType it = line.intersect(perpendicular_line,
&intersection_point); // ### Qt 6: remove
#else
#pragma message("@TODO remove code for QT 5.14 or later") #pragma message("@TODO remove code for QT 5.14 or later")
QLineF::IntersectType it = line.intersects(perpendicular_line, QLineF::IntersectType it = line.
&intersection_point); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
intersect // ### Qt 6: remove
#else
intersects
#endif #endif
(perpendicular_line, &intersection_point);
// ne devrait pas arriver (mais bon...) // ne devrait pas arriver (mais bon...)
if (it == QLineF::NoIntersection) return(false); if (it == QLineF::NoIntersection) return(false);
@@ -399,7 +400,8 @@ QString QET::license() {
Windows Windows
*/ */
QList<QChar> QET::forbiddenCharacters() { QList<QChar> QET::forbiddenCharacters() {
return(QList<QChar>() << '\\' << '/' << ':' << '*' << '?' << '"' << '<' << '>' << '|'); return(QList<QChar>() << '\\' << '/' << ':' << '*' << '?' << '"'
<< '<' << '>' << '|');
} }
/** /**
@@ -467,13 +469,17 @@ QString QET::joinWithSpaces(const QStringList &string_list) {
@return La liste des sous-chaines, sans echappement. @return La liste des sous-chaines, sans echappement.
*/ */
QStringList QET::splitWithSpaces(const QString &string) { QStringList QET::splitWithSpaces(const QString &string) {
// les chaines sont separees par des espaces non echappes = avec un nombre nul ou pair de backslashes devant // les chaines sont separees par des espaces non echappes
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove // = avec un nombre nul ou pair de backslashes devant
QStringList escaped_strings = string.split(QRegExp("[^\\]?(?:\\\\)* "), QString::SkipEmptyParts);
#else
#pragma message("@TODO remove code for QT 5.14 or later") #pragma message("@TODO remove code for QT 5.14 or later")
QStringList escaped_strings = string.split(QRegExp("[^\\]?(?:\\\\)* "), Qt::SkipEmptyParts); QStringList escaped_strings = string.split(QRegExp("[^\\]?(?:\\\\)* "),
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QString
#else
Qt
#endif #endif
::SkipEmptyParts);
QStringList returned_list; QStringList returned_list;
foreach(QString escaped_string, escaped_strings) { foreach(QString escaped_string, escaped_strings) {
@@ -591,8 +597,9 @@ bool QET::writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString *
{ {
if (error_message) if (error_message)
{ {
*error_message = QString(QObject::tr("Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.", *error_message = QString(QObject::tr(
"error message when attempting to write an XML file")).arg(filepath).arg(file.error()); "Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.",
"error message when attempting to write an XML file")).arg(filepath).arg(file.error());
} }
return(false); return(false);
} }
@@ -604,8 +611,9 @@ bool QET::writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString *
if (!file.commit()) if (!file.commit())
{ {
if (error_message) { if (error_message) {
*error_message = QString(QObject::tr("Une erreur est survenue lors de l'écriture du fichier %1, erreur %2 rencontrée.", *error_message = QString(QObject::tr(
"error message when attempting to write an XML file")).arg(filepath).arg(file.error()); "Une erreur est survenue lors de l'écriture du fichier %1, erreur %2 rencontrée.",
"error message when attempting to write an XML file")).arg(filepath).arg(file.error());
} }
return false; return false;
@@ -713,8 +721,9 @@ bool QET::writeToFile(QDomDocument &xml_doc, QFile *file, QString *error_message
{ {
QFileInfo info_(*file); QFileInfo info_(*file);
*error_message = QString( *error_message = QString(
QObject::tr("Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.", QObject::tr(
"error message when attempting to write an XML file") "Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.",
"error message when attempting to write an XML file")
).arg(info_.absoluteFilePath()).arg(file->error()); ).arg(info_.absoluteFilePath()).arg(file->error());
} }
return false; return false;