diff --git a/dialogs/dialogincrements.cpp b/dialogs/dialogincrements.cpp index 7ea38338c..c877ef145 100644 --- a/dialogs/dialogincrements.cpp +++ b/dialogs/dialogincrements.cpp @@ -26,6 +26,7 @@ #include "widgets/doubledelegate.h" #include "container/vincrementtablerow.h" #include +#include "exception/vexception.h" DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) : DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogIncrements), data(data), doc(doc){ @@ -41,6 +42,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget FillIncrementTable(); FillLengthLines(); + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); connect(ui->toolButtonRemove, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonRemove); @@ -365,8 +367,8 @@ void DialogIncrements::AddIncrementToFile(qint64 id, QString name, qreal base, q } void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ - QTableWidgetItem *item; - QTableWidgetItem *itemName; + QTableWidgetItem *item = 0; + QTableWidgetItem *itemName = 0; qint64 id; QDomElement domElement; switch(column) { @@ -386,8 +388,14 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ id = qvariant_cast(itemName->data(Qt::UserRole)); domElement = doc->elementById(QString().setNum(id)); if(domElement.isElement()){ - domElement.setAttribute("base", item->text().toDouble()); - emit FullUpdateTree(); + bool ok = false; + qreal value = item->text().toDouble(&ok); + if(ok){ + domElement.setAttribute("base", value); + emit FullUpdateTree(); + } else { + throw VException(tr("Can't convert toDouble value.")); + } } break; case 3: diff --git a/dialogs/dialogincrements.h b/dialogs/dialogincrements.h index ed357e92a..7f305494c 100644 --- a/dialogs/dialogincrements.h +++ b/dialogs/dialogincrements.h @@ -29,38 +29,37 @@ namespace Ui { class DialogIncrements; } -class DialogIncrements : public DialogTool -{ +class DialogIncrements : public DialogTool{ Q_OBJECT public: - explicit DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0); - ~DialogIncrements(); + DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0); + ~DialogIncrements(); public slots: - void clickedToolButtonAdd(); - void clickedToolButtonRemove(); - void cellChanged ( qint32 row, qint32 column ); - void FullUpdateFromFile(); - virtual void DialogAccepted(); + void clickedToolButtonAdd(); + void clickedToolButtonRemove(); + void cellChanged ( qint32 row, qint32 column ); + void FullUpdateFromFile(); + virtual void DialogAccepted(); signals: - void FullUpdateTree(); - void haveLiteChange(); + void FullUpdateTree(); + void haveLiteChange(); private: Q_DISABLE_COPY(DialogIncrements) Ui::DialogIncrements *ui; - VContainer *data; // need because we must change data - VDomDocument *doc; - void InitialStandartTable(); - void InitialIncrementTable(); - void InitialLinesTable(); - void InitialSplinesTable(); - void InitialArcsTable(); - void FillStandartTable(); - void FillIncrementTable(); - void FillLengthLines(); - void FillLengthSplines(); - void FillLengthArcs(); - void AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, qreal kgrowth, - QString description); + VContainer *data; // need because we must change data + VDomDocument *doc; + void InitialStandartTable(); + void InitialIncrementTable(); + void InitialLinesTable(); + void InitialSplinesTable(); + void InitialArcsTable(); + void FillStandartTable(); + void FillIncrementTable(); + void FillLengthLines(); + void FillLengthSplines(); + void FillLengthArcs(); + void AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, qreal kgrowth, + QString description); }; #endif // DIALOGINCREMENTS_H diff --git a/widgets/doubledelegate.cpp b/widgets/doubledelegate.cpp index 3b0932624..0f81b6785 100644 --- a/widgets/doubledelegate.cpp +++ b/widgets/doubledelegate.cpp @@ -53,10 +53,8 @@ { } - QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &/* option */, - const QModelIndex &/* index */) const - { + QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, + const QModelIndex &/* index */) const{ QDoubleSpinBox *editor = new QDoubleSpinBox(parent); editor->setMinimum(-1000.0); editor->setMaximum(1000.0); @@ -64,18 +62,15 @@ return editor; } - void DoubleSpinBoxDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const - { - int value = index.model()->data(index, Qt::EditRole).toInt(); + void DoubleSpinBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const{ + qreal value = index.model()->data(index, Qt::EditRole).toDouble(); QDoubleSpinBox *spinBox = static_cast(editor); spinBox->setValue(value); } void DoubleSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const - { + const QModelIndex &index) const{ QDoubleSpinBox *spinBox = static_cast(editor); spinBox->interpretText(); qreal value = spinBox->value(); @@ -84,7 +79,6 @@ } void DoubleSpinBoxDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &/* index */) const - { + const QStyleOptionViewItem &option, const QModelIndex &/* index */) const{ editor->setGeometry(option.rect); } diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index d31f9b486..2de1c97b2 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -374,7 +374,7 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); bool ok = false; QString parametr = GetParametrString(domElement, name); - qreal param = parametr.toDouble(&ok); + qreal param = parametr.replace(",", ".").toDouble(&ok); if(ok == false){ throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name); }