Connected signal cellChanged to slot cellChanged in table of increments.

Before conversion toDouble replace "," to ".".

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-14 14:26:42 +03:00
parent 4d6179d3e2
commit 3bda5f6208
4 changed files with 43 additions and 42 deletions

View File

@ -26,6 +26,7 @@
#include "widgets/doubledelegate.h"
#include "container/vincrementtablerow.h"
#include <QDebug>
#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<qint64>(itemName->data(Qt::UserRole));
domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("base", item->text().toDouble());
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:

View File

@ -29,11 +29,10 @@ 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(VContainer *data, VDomDocument *doc, QWidget *parent = 0);
~DialogIncrements();
public slots:
void clickedToolButtonAdd();

View File

@ -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<QDoubleSpinBox*>(editor);
spinBox->setValue(value);
}
void DoubleSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
const QModelIndex &index) const{
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(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);
}

View File

@ -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);
}