diff --git a/Valentina.pro b/Valentina.pro index df9d5cfd1..082d92577 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -19,7 +19,12 @@ SOURCES += main.cpp\ widgets/vgraphicssimpletextitem.cpp \ xml/vdomdocument.cpp \ container/vpointf.cpp \ - container/vcontainer.cpp + container/vcontainer.cpp \ + tools/vtoolpoint.cpp \ + container/calculator.cpp \ + dialogs/dialogincrements.cpp \ + container/vstandarttablecell.cpp \ + container/vincrementtablerow.cpp HEADERS += mainwindow.h \ widgets/vmaingraphicsscene.h \ @@ -29,10 +34,16 @@ HEADERS += mainwindow.h \ widgets/vgraphicssimpletextitem.h \ xml/vdomdocument.h \ container/vpointf.h \ - container/vcontainer.h + container/vcontainer.h \ + tools/vtoolpoint.h \ + container/calculator.h \ + dialogs/dialogincrements.h \ + container/vstandarttablecell.h \ + container/vincrementtablerow.h FORMS += mainwindow.ui \ - dialogs/dialogsinglepoint.ui + dialogs/dialogsinglepoint.ui \ + dialogs/dialogincrements.ui RESOURCES += \ icon.qrc \ diff --git a/container/calculator.cpp b/container/calculator.cpp new file mode 100644 index 000000000..b455951a2 --- /dev/null +++ b/container/calculator.cpp @@ -0,0 +1,323 @@ +#include "calculator.h" +#include + +#include + +#define DELIMITER 1 +#define VARIABLE 2 +#define NUMBER 3 +#define COMMAND 4 +#define STRING 5 +#define QUOTE 6 +#define FINISHED 10 +#define EOL 9 + +Calculator::Calculator(VContainer *data){ + index = 0; + this->data = data; + +} + +qreal Calculator::eval(QString prog){ + debugFormula.clear(); + this->prog = prog; + qDebug()<<"Формула: "<0; --t) +// *r = (*r) * ex; + break; + } +} + +/* Изменение знака */ +void Calculator::unary(QChar o, qreal *r){ + if(o=='-') + *r = -(*r); +} + +/* Поиск значения переменной */ +qreal Calculator::find_var(QString s){ + bool ok = false; + qreal value = data->FindVar(s, &ok); + if(!ok){ + serror(4); /* не переменная */ + return 0; + } + return value; +} + +/* выдать сообщение об ошибке */ +void Calculator::serror(qint32 error){ + QString e[]= { + "Синтаксическая ошибка", + "Непарные круглые скобки", + "Это не выражение", + "Предполагается символ равенства", + "Не переменная", + "Таблица меток переполнена", + "Дублирование меток", + "Неопределенная метка", + "Необходим оператор THEN", + "Необходим оператор TO", + "Уровень вложенности цикла FOR слишком велик", + "NEXT не соответствует FOR", + "Уровень вложенности GOSUB слишком велик", + "RETURN не соответствует GOSUB" + }; + qDebug()</*%^=()",c) || c=='\n' || c=='\r' || c=='\0') + return true; + return false; +} + +/* Возвращает 1, если "с" пробел или табуляция */ +bool Calculator::iswhite(QChar c){ + if(c==' ' || c=='\t') + return true; + else + return false; +} + +void Calculator::get_token(){ + QString *temp; + + token_type=0; tok=0; + token.clear(); + temp=&token; + + if(prog[index]=='\0') { /* Конец файла */ + token="\0"; + tok=FINISHED; + token_type=DELIMITER; + return; + } + + while(iswhite(prog[index])) ++index; /* пропуск пробелов */ + + if(prog[index]=='\r') { /* crtl */ + ++index; ++index; + tok= EOL; token='\r'; + token.append('\n');token.append("\0"); + token_type = DELIMITER; + return; + } + + if(StrChr("+-*^/%=;(),><", prog[index])) { /* разделитель */ + *temp=prog[index]; + index++; /* переход на следующую позицию */ + temp->append("\0"); + token_type=DELIMITER; + debugFormula.append(token); + return; + } + if(prog[index]=='"') { /* строка в кавычках */ + index++; + while(prog[index] != '"' && prog[index] != '\r'){ + temp->append(prog[index]); + index++; + } + if(prog[index]=='\r') + serror(1); + index++;temp->append("\0"); + token_type=QUOTE; + return; + } + if(prog[index].isDigit()) { /* число */ + while(!isdelim(prog[index])){ + temp->append(prog[index]); + index++; + } + temp->append('\0'); + token_type = NUMBER; + return; + } + + if(prog[index].isPrint()) { /* переменная или команда */ + while(!isdelim(prog[index])){ + temp->append(prog[index]); + index++; + } + token_type=STRING; + } + temp->append("\0"); + + /* Просматривается, если строка есть команда или переменная */ + if(token_type==STRING) { + tok=look_up(token); /* преобразование во внутренний + формат */ + if(!tok) + token_type = VARIABLE; + else token_type = COMMAND; /* это команда */ + } + return; +} + +bool Calculator::StrChr(QString string, QChar c){ + return string.contains(c, Qt::CaseInsensitive); +} + +/* Возвращает лексему обратно во входной поток */ +void Calculator::putback(){ + QString t; + t = token; + index = index - t.size(); +} diff --git a/container/calculator.h b/container/calculator.h new file mode 100644 index 000000000..d7e90f191 --- /dev/null +++ b/container/calculator.h @@ -0,0 +1,148 @@ +#ifndef CALCULATOR_H +#define CALCULATOR_H + +#include +#include +#include +#include +#include +#include "vcontainer.h" + +/** + * @brief The Calculator клас калькулятора формул лекал. Виконує розрахунок формул з підставлянням + * значеннь зміних. + */ +class Calculator +{ +public: + /** + * @brief Calculator конструктор класу. Використовується при розрахунку лекала. + * @param data покажчик на контейнер змінних + */ + Calculator(VContainer *data); + /** + * @brief eval виконує розрахунок формули. + * @param prog рядко в якому зберігається формула. + * @return значення формули. + */ + qreal eval(QString prog); +private: + /** + * @brief token теперішня лексема. + */ + QString token; + /** + * @brief tok внутрішне представлення лексеми. + */ + qint32 tok; + /** + * @brief token_type тип лексеми. + */ + qint32 token_type; + /** + * @brief prog рядок в якому зберігається формула. + */ + QString prog; /* Содержит анализируемое выражение */ + /** + * @brief index номер символу в рядку формули. + */ + qint32 index; /* Индекс символа в строке*/ + /** + * @brief data контейнер усіх змінних. + */ + VContainer *data; + /** + * @brief debugFormula рядок розшифрованої формули. + */ + QString debugFormula; + /** + * @brief get_exp виконує розрахунок формули. + * @return значення формули. + */ + qreal get_exp(); + /** + * @brief get_token повертає наступну лексему. + */ + void get_token();/* Получить лексему */ + /** + * @brief StrChr перевіряє чи символ належить рядку. + * @param string рядок + * @param c символ. + * @return true - належить рядку, false - не належить рядку. + */ + bool StrChr(QString string, QChar c); + /** + * @brief putback повертає зчитану лексему назад у потік. + */ + void putback(); + /** + * @brief level2 метод додавання і віднімання двух термів. + * @param result результат операції. + */ + void level2(qreal *result); + /** + * @brief level3 метод множення, ділення, знаходження процентів. + * @param result результат операції. + */ + void level3(qreal *result); + /** + * @brief level4 метод знаходження степені двох чисел. + * @param result результат операції. + */ + void level4(qreal *result); + /** + * @brief level5 метод знаходження унарного плюса чи мінуса. + * @param result результат операції. + */ + void level5(qreal *result); + /** + * @brief level6 метод обробки виразу в круглих лапках. + * @param result результат операції. + */ + void level6(qreal *result); + /** + * @brief primitive метод визначення значення зміної по її імені. + * @param result результат операції. + */ + void primitive(qreal *result); + /** + * @brief arith виконання специфікованої арифметики. Результат записується в перший елемент. + * @param o знак операції. + * @param r перший елемент. + * @param h другий елемент. + */ + void arith(QChar o, qreal *r, qreal *h); + /** + * @brief unary метод зміни знаку. + * @param o символ знаку. + * @param r елемент. + */ + void unary(QChar o, qreal *r); + /** + * @brief find_var метод знаходить змінну за іменем. + * @param s ім'я змінної. + * @return значення зміної. + */ + qreal find_var(QString s); + void serror(qint32 error); + /** + * @brief look_up пошук відповідного внутрішнього формату для теперішньої лексеми в таблиці лексем. текущей лексемы в таблице лексем + * @param s ім'я лексеми. + * @return внутрішній номер лексеми. + */ + char look_up(QString s); + /** + * @brief isdelim повертає "істино", якщо с розділювач. + * @param c символ. + * @return розділювач, або ні. + */ + bool isdelim(QChar c); + /** + * @brief iswhite перевіряє чи с пробіл чи табуляція. + * @param c символ. + * @return так або ні. + */ + bool iswhite(QChar c); +}; + +#endif // CALCULATOR_H diff --git a/container/vcontainer.cpp b/container/vcontainer.cpp index 1dec202a6..dff946305 100644 --- a/container/vcontainer.cpp +++ b/container/vcontainer.cpp @@ -1,8 +1,12 @@ #include "vcontainer.h" #include +#include "../options.h" + VContainer::VContainer(){ _id = 0; + SetSize(500); + SetGrowth(1760); } VPointF VContainer::GetPoint(qint64 id) const{ @@ -15,12 +19,40 @@ VPointF VContainer::GetPoint(qint64 id) const{ return VPointF(); } +VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const{ + if(standartTable.contains(name)){ + return standartTable.value(name); + } else { + qCritical()<<"Не можу знайти змінну за імям = "< _id){ @@ -37,7 +73,152 @@ void VContainer::UpdatePoint(qint64 id, const VPointF& point){ } } +void VContainer::UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell){ + standartTable[name] = cell; +} + +void VContainer::UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell){ + incrementTable[name] = cell; +} + +qreal VContainer::GetValueStandartTableCell(const QString& name) const{ + VStandartTableCell cell = GetStandartTableCell(name); + qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2; + qreal k_growth = ( ( qreal ) (growth()/10) - 176.0 ) / 6; + qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth(); + return value; +} + +qreal VContainer::GetValueIncrementTableRow(const QString& name) const{ + VIncrementTableRow cell = GetIncrementTableRow(name); + qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2; + qreal k_growth = ( ( qreal ) (growth()/10) - 176.0 ) / 6; + qreal value = cell.getBase() + k_size*cell.getKsize() + k_growth*cell.getKgrowth(); + return value; +} + void VContainer::Clear(){ _id = 0; points.clear(); + standartTable.clear(); + incrementTable.clear(); +} + +void VContainer::ClearIncrementTable(){ + incrementTable.clear(); +} + +void VContainer::SetSize(qint32 size){ + base["Сг"] = size; +} + +void VContainer::SetGrowth(qint32 growth){ + base["Р"] = growth; +} + +qint32 VContainer::size() const{ + return base.value("Сг"); +} + +qint32 VContainer::growth() const{ + return base.value("Р"); +} + +bool VContainer::IncrementTableContains(const QString& name){ + return incrementTable.contains(name); +} + +qreal VContainer::FindVar(const QString &name, bool *ok)const{ + if(base.contains(name)){ + *ok = true; + return base.value(name)/PrintDPI*25.4; + } + + if(standartTable.contains(name)){ + *ok = true; + return GetValueStandartTableCell(name)/PrintDPI*25.4; + } + if(incrementTable.contains(name)){ + *ok = true; + return GetValueIncrementTableRow(name)/PrintDPI*25.4; + } + *ok = false; + return 0; +} + +void VContainer::FillStandartTable(QTableWidget *table) const{ + qint32 currentRow = -1; + QMapIterator i(standartTable); + while (i.hasNext()) { + i.next(); + VStandartTableCell cell = i.value(); + currentRow++; + table->setRowCount ( standartTable.size() ); + + QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + table->setItem(currentRow, 0, item); + + item = new QTableWidgetItem(QString().setNum(GetValueStandartTableCell(i.key()))); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 1, item); + + item = new QTableWidgetItem(QString().setNum(cell.GetBase())); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 2, item); + + item = new QTableWidgetItem(QString().setNum(cell.GetKsize())); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 3, item); + + item = new QTableWidgetItem(QString().setNum(cell.GetKgrowth())); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 4, item); + + item = new QTableWidgetItem(cell.GetDescription()); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 5, item); + } +} + +void VContainer::FillIncrementTable(QTableWidget *table) const{ + qint32 currentRow = -1; + QMapIterator i(incrementTable); + while (i.hasNext()) { + i.next(); + VIncrementTableRow cell = i.value(); + currentRow++; + table->setRowCount ( incrementTable.size() ); + + QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, cell.getId()); + table->setItem(currentRow, 0, item); + + item = new QTableWidgetItem(QString().setNum(GetValueIncrementTableRow(i.key()))); + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + table->setItem(currentRow, 1, item); + + item = new QTableWidgetItem(QString().setNum(cell.getBase())); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 2, item); + + item = new QTableWidgetItem(QString().setNum(cell.getKsize())); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 3, item); + + item = new QTableWidgetItem(QString().setNum(cell.getKgrowth())); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 4, item); + + item = new QTableWidgetItem(cell.getDescription()); + item->setTextAlignment(Qt::AlignHCenter); + table->setItem(currentRow, 5, item); + } } diff --git a/container/vcontainer.h b/container/vcontainer.h index 1abab3561..ad4941836 100644 --- a/container/vcontainer.h +++ b/container/vcontainer.h @@ -2,22 +2,46 @@ #define VCONTAINER_H #include +#include #include "vpointf.h" +#include "vstandarttablecell.h" +#include "vincrementtablerow.h" class VContainer { public: - VContainer(); - VPointF GetPoint(qint64 id) const; - qint64 getId(); - qint64 AddPoint(const VPointF& point); - void UpdatePoint(qint64 id, const VPointF& point); - void Clear(); + VContainer(); + VPointF GetPoint(qint64 id) const; + VStandartTableCell GetStandartTableCell(const QString& name) const; + VIncrementTableRow GetIncrementTableRow(const QString& name) const; + qint64 getId(); + qint64 AddPoint(const VPointF& point); + void AddStandartTableCell(const QString& name, const VStandartTableCell& cell); + void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell); + void UpdatePoint(qint64 id, const VPointF& point); + void UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell); + void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell); + qreal GetValueStandartTableCell(const QString& name) const; + qreal GetValueIncrementTableRow(const QString& name) const; + void Clear(); + void ClearIncrementTable(); + void SetSize(qint32 size); + void SetGrowth(qint32 growth); + qint32 size() const; + qint32 growth() const; + qreal FindVar(const QString& name, bool *ok)const; + void FillStandartTable(QTableWidget *table) const; + void FillIncrementTable(QTableWidget *table) const; + bool IncrementTableContains(const QString& name); + qint64 getNextId(); + void RemoveIncrementTableRow(const QString& name); private: - qint64 _id; + qint64 _id; + QMap base; QMap points; - qint64 getNextId(); + QMap standartTable; + QMap incrementTable; }; #endif // VCONTAINER_H diff --git a/container/vincrementtablerow.cpp b/container/vincrementtablerow.cpp new file mode 100644 index 000000000..5c2fce21d --- /dev/null +++ b/container/vincrementtablerow.cpp @@ -0,0 +1,58 @@ +#include "vincrementtablerow.h" + +VIncrementTableRow::VIncrementTableRow(){ + this->id = 0; + this->base = 0; + this->ksize = 0; + this->kgrowth = 0; + this->description = QString(); +} + +VIncrementTableRow::VIncrementTableRow(qint64 id, qint32 base, qreal ksize, qreal kgrowth, + QString description){ + this->id = id; + this->base = base; + this->ksize = ksize; + this->kgrowth = kgrowth; + this->description = description; +} + +QString VIncrementTableRow::getDescription() const{ + return description; +} + +void VIncrementTableRow::setDescription(const QString &value){ + description = value; +} + +qreal VIncrementTableRow::getKgrowth() const{ + return kgrowth; +} + +void VIncrementTableRow::setKgrowth(const qreal &value){ + kgrowth = value; +} + +qreal VIncrementTableRow::getKsize() const{ + return ksize; +} + +void VIncrementTableRow::setKsize(const qreal &value){ + ksize = value; +} + +qint32 VIncrementTableRow::getBase() const{ + return base; +} + +void VIncrementTableRow::setBase(const qint32 &value){ + base = value; +} + +qint64 VIncrementTableRow::getId() const{ + return id; +} + +void VIncrementTableRow::setId(const qint64 &value){ + id = value; +} diff --git a/container/vincrementtablerow.h b/container/vincrementtablerow.h new file mode 100644 index 000000000..82d57300e --- /dev/null +++ b/container/vincrementtablerow.h @@ -0,0 +1,35 @@ +#ifndef VINCREMENTTABLEROW_H +#define VINCREMENTTABLEROW_H + +#include + +class VIncrementTableRow +{ +public: + VIncrementTableRow(); + VIncrementTableRow(qint64 id, qint32 base, qreal ksize, qreal kgrowth, + QString description = QString()); + qint64 getId() const; + void setId(const qint64 &value); + + qint32 getBase() const; + void setBase(const qint32 &value); + + qreal getKsize() const; + void setKsize(const qreal &value); + + qreal getKgrowth() const; + void setKgrowth(const qreal &value); + + QString getDescription() const; + void setDescription(const QString &value); + +private: + qint64 id; + qint32 base; + qreal ksize; + qreal kgrowth; + QString description; +}; + +#endif // VINCREMENTTABLEROW_H diff --git a/container/vstandarttablecell.cpp b/container/vstandarttablecell.cpp new file mode 100644 index 000000000..1b28ec002 --- /dev/null +++ b/container/vstandarttablecell.cpp @@ -0,0 +1,31 @@ +#include "vstandarttablecell.h" + +VStandartTableCell::VStandartTableCell(){ + base = 0; + ksize = 0; + kgrowth = 0; + description = QString(); +} + +VStandartTableCell::VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description){ + this->base = base; + this->ksize = ksize; + this->kgrowth = kgrowth; + this->description = description; +} + +qint32 VStandartTableCell::GetBase() const{ + return base; +} + +qreal VStandartTableCell::GetKsize() const{ + return ksize; +} + +qreal VStandartTableCell::GetKgrowth() const{ + return kgrowth; +} + +QString VStandartTableCell::GetDescription() const{ + return description; +} diff --git a/container/vstandarttablecell.h b/container/vstandarttablecell.h new file mode 100644 index 000000000..6243bfa0a --- /dev/null +++ b/container/vstandarttablecell.h @@ -0,0 +1,22 @@ +#ifndef VSTANDARTTABLECELL_H +#define VSTANDARTTABLECELL_H + +#include + +class VStandartTableCell +{ +public: + VStandartTableCell(); + VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description = QString()); + qint32 GetBase() const; + qreal GetKsize() const; + qreal GetKgrowth() const; + QString GetDescription() const; +private: + qint32 base; + qreal ksize; + qreal kgrowth; + QString description; +}; + +#endif // VSTANDARTTABLECELL_H diff --git a/dialogs/dialogincrements.cpp b/dialogs/dialogincrements.cpp new file mode 100644 index 000000000..c8f8a6e30 --- /dev/null +++ b/dialogs/dialogincrements.cpp @@ -0,0 +1,267 @@ +#include "dialogincrements.h" +#include "ui_dialogincrements.h" +#include +#include + +#include "../container/vincrementtablerow.h" + +DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) : + QDialog(parent), ui(new Ui::DialogIncrements){ + ui->setupUi(this); + this->data = data; + this->doc = doc; + ui->tableWidgetStandart->resizeColumnsToContents(); + ui->tableWidgetStandart->resizeRowsToContents(); + ui->tableWidgetStandart->verticalHeader()->setDefaultSectionSize(20); + ui->tableWidgetStandart->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення")); + ui->tableWidgetStandart->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач.")); + ui->tableWidgetStandart->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач.")); + ui->tableWidgetStandart->setHorizontalHeaderItem(3, new QTableWidgetItem("В розмірі")); + ui->tableWidgetStandart->setHorizontalHeaderItem(4, new QTableWidgetItem("В рості")); + ui->tableWidgetStandart->setHorizontalHeaderItem(5, new QTableWidgetItem("Опис")); + ui->tableWidgetIncrement->resizeColumnsToContents(); + ui->tableWidgetIncrement->resizeRowsToContents(); + ui->tableWidgetIncrement->verticalHeader()->setDefaultSectionSize(20); + ui->tableWidgetIncrement->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач.")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач.")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(3, new QTableWidgetItem("В розмірі")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(4, new QTableWidgetItem("В рості")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(5, new QTableWidgetItem("Опис")); + FillStandartTable(); + FillIncrementTable(); + + connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); + connect(ui->toolButtonRemove, &QPushButton::clicked, this, + &DialogIncrements::clickedToolButtonRemove); + + connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); + connect(this, &DialogIncrements::haveLiteChange, this->doc, &VDomDocument::haveLiteChange); + connect(this->doc, &VDomDocument::FullUpdateFromFile, this, + &DialogIncrements::FullUpdateFromFile); + + QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogIncrements::clickedButtonOk); +} + +void DialogIncrements::FillStandartTable(){ + data->FillStandartTable(ui->tableWidgetStandart); +} + +void DialogIncrements::FillIncrementTable(){ + data->FillIncrementTable(ui->tableWidgetIncrement); + if(ui->tableWidgetIncrement->rowCount()>0){ + ui->toolButtonRemove->setEnabled(true); + } +} + +void DialogIncrements::FullUpdateFromFile(){ + disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::cellChanged); + ui->tableWidgetStandart->clear(); + ui->tableWidgetStandart->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення")); + ui->tableWidgetStandart->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач.")); + ui->tableWidgetStandart->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач.")); + ui->tableWidgetStandart->setHorizontalHeaderItem(3, new QTableWidgetItem("В розмірі")); + ui->tableWidgetStandart->setHorizontalHeaderItem(4, new QTableWidgetItem("В рості")); + ui->tableWidgetStandart->setHorizontalHeaderItem(5, new QTableWidgetItem("Опис")); + ui->tableWidgetIncrement->clear(); + ui->tableWidgetIncrement->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(1, new QTableWidgetItem("Розрах. знач.")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(2, new QTableWidgetItem("Базове знач.")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(3, new QTableWidgetItem("В розмірі")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(4, new QTableWidgetItem("В рості")); + ui->tableWidgetIncrement->setHorizontalHeaderItem(5, new QTableWidgetItem("Опис")); + FillStandartTable(); + FillIncrementTable(); + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::cellChanged); +} + +void DialogIncrements::clickedToolButtonAdd(){ + disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::cellChanged); + ui->tableWidgetIncrement->setFocus(Qt::OtherFocusReason); + qint32 currentRow = ui->tableWidgetIncrement->rowCount(); + ui->tableWidgetIncrement->insertRow( currentRow ); + + qint32 num = 1; + QString name; + do{ + name = QString("Позначення %1").arg(num); + num++; + }while(data->IncrementTableContains(name)); + + qint64 id = data->getNextId(); + qint32 base = 0; + qreal ksize = 0; + qreal kgrowth = 0; + QString description = QString("Опис"); + VIncrementTableRow incrementRow = VIncrementTableRow(id, base, ksize, kgrowth, description); + data->AddIncrementTableRow(name, incrementRow); + + AddIncrementToFile(id, name, base, ksize, kgrowth, description); + + QTableWidgetItem *item = new QTableWidgetItem(name); + item->setTextAlignment(Qt::AlignHCenter); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, id); + ui->tableWidgetIncrement->setItem(currentRow, 0, item); + ui->tableWidgetIncrement->setCurrentCell(currentRow, 0, QItemSelectionModel::ClearAndSelect); + + item = new QTableWidgetItem("0"); + item->setTextAlignment(Qt::AlignHCenter); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + ui->tableWidgetIncrement->setItem(currentRow, 1, item); + + item = new QTableWidgetItem("0"); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 2, item); + + item = new QTableWidgetItem("0"); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 3, item); + + item = new QTableWidgetItem("0"); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 4, item); + + item = new QTableWidgetItem("Опис"); + item->setTextAlignment(Qt::AlignHCenter); + ui->tableWidgetIncrement->setItem(currentRow, 5, item); + + ui->toolButtonRemove->setEnabled(true); + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::cellChanged); +} + +void DialogIncrements::clickedToolButtonRemove(){ + disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::cellChanged); + QTableWidgetItem *item = ui->tableWidgetIncrement->currentItem(); + qint32 row = item->row(); + QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0); + data->RemoveIncrementTableRow(itemName->text()); + qint64 id = qvariant_cast(item->data(Qt::UserRole)); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + QDomNodeList list = doc->elementsByTagName("increments"); + list.at(0).removeChild(domElement); + } + ui->tableWidgetIncrement->removeRow(row); + if(ui->tableWidgetIncrement->rowCount() == 0){ + ui->toolButtonRemove->setEnabled(false); + } + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, + &DialogIncrements::cellChanged); +} + +void DialogIncrements::AddIncrementToFile(quint64 id, QString name, qint32 base, qreal ksize, + qreal kgrowth, QString description){ + QDomNodeList list = doc->elementsByTagName("increments"); + QDomElement element = doc->createElement("increment"); + + QDomAttr drawAttr = doc->createAttribute("id"); + drawAttr.setValue(QString().setNum(id)); + element.setAttributeNode(drawAttr); + + drawAttr = doc->createAttribute("name"); + drawAttr.setValue(name); + element.setAttributeNode(drawAttr); + + drawAttr = doc->createAttribute("base"); + drawAttr.setValue(QString().setNum(base)); + element.setAttributeNode(drawAttr); + + drawAttr = doc->createAttribute("ksize"); + drawAttr.setValue(QString().setNum(ksize)); + element.setAttributeNode(drawAttr); + + drawAttr = doc->createAttribute("kgrowth"); + drawAttr.setValue(QString().setNum(kgrowth)); + element.setAttributeNode(drawAttr); + + drawAttr = doc->createAttribute("description"); + drawAttr.setValue(description); + element.setAttributeNode(drawAttr); + + list.at(0).appendChild(element); +} + +void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ + QTableWidgetItem *item; + QTableWidgetItem *itemName; + qint64 id; + QDomElement domElement; + switch(column) { + case 0: + item = ui->tableWidgetIncrement->item(row, 0); + id = qvariant_cast(item->data(Qt::UserRole)); + domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", item->text()); + data->ClearIncrementTable(); + emit FullUpdateTree(); + } + break; + case 2: + itemName = ui->tableWidgetIncrement->item(row, 0); + item = ui->tableWidgetIncrement->item(row, 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(); + } + break; + case 3: + itemName = ui->tableWidgetIncrement->item(row, 0); + item = ui->tableWidgetIncrement->item(row, column); + id = qvariant_cast(itemName->data(Qt::UserRole)); + domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("ksize", item->text().toDouble()); + emit FullUpdateTree(); + } + break; + case 4: + itemName = ui->tableWidgetIncrement->item(row, 0); + item = ui->tableWidgetIncrement->item(row, column); + id = qvariant_cast(itemName->data(Qt::UserRole)); + domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("kgrowth", item->text().toDouble()); + emit FullUpdateTree(); + } + break; + case 5: + itemName = ui->tableWidgetIncrement->item(row, 0); + item = ui->tableWidgetIncrement->item(row, column); + id = qvariant_cast(itemName->data(Qt::UserRole)); + domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("description", item->text()); + VIncrementTableRow incr = data->GetIncrementTableRow(itemName->text()); + incr.setDescription(item->text()); + data->UpdateIncrementTableRow(itemName->text(), incr); + emit haveLiteChange(); + } + break; + } +} + +void DialogIncrements::closeEvent ( QCloseEvent * event ){ + emit closedActionTable(); + event->accept(); +} + +void DialogIncrements::clickedButtonOk(){ + emit closedActionTable(); +} + +DialogIncrements::~DialogIncrements(){ + delete ui; +} diff --git a/dialogs/dialogincrements.h b/dialogs/dialogincrements.h new file mode 100644 index 000000000..80d96880c --- /dev/null +++ b/dialogs/dialogincrements.h @@ -0,0 +1,43 @@ +#ifndef DIALOGINCREMENTS_H +#define DIALOGINCREMENTS_H + +#include +#include + +#include "../container/vcontainer.h" +#include "../xml/vdomdocument.h" + +namespace Ui { +class DialogIncrements; +} + +class DialogIncrements : public QDialog +{ + Q_OBJECT + +public: + explicit DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0); + ~DialogIncrements(); +public slots: + void clickedToolButtonAdd(); + void clickedToolButtonRemove(); + void cellChanged ( qint32 row, qint32 column ); + void FullUpdateFromFile(); + void clickedButtonOk(); +signals: + void FullUpdateTree(); + void haveLiteChange(); + void closedActionTable(); +protected: + void closeEvent ( QCloseEvent * event ); +private: + Ui::DialogIncrements *ui; + VContainer *data; + VDomDocument *doc; + void FillStandartTable(); + void FillIncrementTable(); + void AddIncrementToFile(quint64 id, QString name, qint32 base, qreal ksize, qreal kgrowth, + QString description); +}; + +#endif // DIALOGINCREMENTS_H diff --git a/dialogs/dialogincrements.ui b/dialogs/dialogincrements.ui new file mode 100644 index 000000000..0d0a95600 --- /dev/null +++ b/dialogs/dialogincrements.ui @@ -0,0 +1,366 @@ + + + DialogIncrements + + + + 0 + 0 + 681 + 422 + + + + Dialog + + + + + + QTabWidget::North + + + 4 + + + + Табличні розміри + + + + + + true + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + false + + + 95 + + + 25 + + + false + + + true + + + false + + + 45 + + + 8 + + + + Позначення + + + + + Розраховане знач. + + + + + Базове знач. + + + + + В розмірах + + + + + В ростах + + + + + Опис + + + + + + + + + Прибавки + + + + + + true + + + QAbstractItemView::SingleSelection + + + true + + + false + + + 95 + + + 17 + + + false + + + true + + + false + + + 45 + + + + Позначення + + + + + Розраховане знач. + + + + + Базове знач. + + + + + В розмірах + + + + + В ростах + + + + + Опис + + + + + + + + ... + + + + + + + + + + + + false + + + ... + + + + + + + + + + + + + Лінії + + + + + + QAbstractItemView::NoEditTriggers + + + false + + + 137 + + + false + + + false + + + + Лінія + + + + + Довжина лінії + + + + + + + + + Сплайни + + + + + + QAbstractItemView::NoEditTriggers + + + false + + + 137 + + + false + + + false + + + + Сплайн + + + + + Довжина сплайну + + + + + + + + + Дуги + + + + + + QAbstractItemView::NoEditTriggers + + + false + + + 137 + + + false + + + false + + + + Дуга + + + + + Довжина дуги + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + false + + + + + + + + + buttonBox + accepted() + DialogIncrements + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogIncrements + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/icon.qrc b/icon.qrc index 7f8b073da..8c4421cf2 100644 --- a/icon.qrc +++ b/icon.qrc @@ -7,5 +7,6 @@ icon/32x32/arrow_cursor.png icon/32x32/new_draw.png icon/32x32/option_draw.png + icon/32x32/table.png diff --git a/icon/32x32/table.png b/icon/32x32/table.png new file mode 100644 index 000000000..b2f7987f6 Binary files /dev/null and b/icon/32x32/table.png differ diff --git a/mainwindow.cpp b/mainwindow.cpp index 9b3a184ca..1fd4d1d39 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -38,8 +38,10 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionSave, &QAction::triggered, this, &MainWindow::triggeredActionSave); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::triggeredActionOpen); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::triggeredActionNew); + connect(ui->actionTable, &QAction::triggered, this, &MainWindow::triggeredActionTable); data = new VContainer; + CreateManTableIGroup (); doc = new VDomDocument(data); doc->CreateEmptyFile(); @@ -87,12 +89,7 @@ void MainWindow::triggeredActionNewDraw(){ if ( index != -1 ) { // -1 for not found comboBoxDraws->setCurrentIndex(index); } - ui->actionSaveAs->setEnabled(true); - ui->actionDraw->setEnabled(true); - ui->actionDetails->setEnabled(true); - ui->toolButtonSinglePoint->setEnabled(true); - ui->actionOptionDraw->setEnabled(true); - ui->actionSave->setEnabled(true); + SetEnableWidgets(true); } void MainWindow::triggeredOptionDraw(){ @@ -179,11 +176,14 @@ void MainWindow::ToolBarOption(){ QStringList list; list << "104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" << "182" << "188"; - QComboBox* comboBoxGrow = new QComboBox; + QComboBox *comboBoxGrow = new QComboBox; comboBoxGrow->clear(); comboBoxGrow->addItems(list); comboBoxGrow->setCurrentIndex(12); ui->toolBarOption->addWidget(comboBoxGrow); + connect(comboBoxGrow, + static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedGrowth); QLabel * labelSize = new QLabel; labelSize->setText(" Розмір: "); @@ -191,11 +191,14 @@ void MainWindow::ToolBarOption(){ list.clear(); list << "28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50" << "52" << "54" << "56"; - QComboBox* comboBoxSize = new QComboBox; + QComboBox *comboBoxSize = new QComboBox; comboBoxSize->clear(); comboBoxSize->addItems(list); comboBoxSize->setCurrentIndex(11); ui->toolBarOption->addWidget(comboBoxSize); + connect(comboBoxSize, + static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedSize); ui->toolBarOption->addSeparator(); @@ -218,6 +221,9 @@ void MainWindow::ToolBarDraws(){ ui->toolBarDraws->addAction(ui->actionOptionDraw); ui->actionOptionDraw->setEnabled(false); + + ui->toolBarDraws->addAction(ui->actionTable); + ui->actionTable->setEnabled(false); } void MainWindow::currentDrawChanged( int index ){ @@ -356,10 +362,12 @@ void MainWindow::triggeredActionOpen(){ disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); doc->Parse(Document::FullParse, scene, comboBoxDraws); + CreateManTableIGroup (); connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); ui->actionSave->setEnabled(true); ui->actionSaveAs->setEnabled(true); + ui->actionTable->setEnabled(true); QString nameDraw = doc->GetNameActivDraw(); qint32 index = comboBoxDraws->findText(nameDraw); if ( index != -1 ) { // -1 for not found @@ -375,6 +383,7 @@ void MainWindow::triggeredActionNew(){ setWindowTitle("Valentina"); data->Clear(); doc->clear(); + CreateManTableIGroup (); CanselTool(); comboBoxDraws->clear(); fileName.clear(); @@ -389,6 +398,110 @@ void MainWindow::haveChange(){ } } +void MainWindow::CreateManTableIGroup () const{ + data->AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3)); + data->AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3)); + data->AddStandartTableCell("Vtos", VStandartTableCell(1450, 2, 51)); + data->AddStandartTableCell("Vtosh", VStandartTableCell(1506, 2, 54)); + data->AddStandartTableCell("Vpt", VStandartTableCell(1438, 3, 52)); + data->AddStandartTableCell("Vst", VStandartTableCell(1257, -1, 49)); + data->AddStandartTableCell("Vlt", VStandartTableCell(1102, 0, 43)); + data->AddStandartTableCell("Vk", VStandartTableCell(503, 0, 22)); + data->AddStandartTableCell("Vsht", VStandartTableCell(1522, 2, 54)); + data->AddStandartTableCell("Vzy", VStandartTableCell(1328, 0, 49)); + data->AddStandartTableCell("Vlop", VStandartTableCell(1320, 0, 49)); + data->AddStandartTableCell("Vps", VStandartTableCell(811, -1, 36)); + data->AddStandartTableCell("Osh", VStandartTableCell(404,8, 2)); + data->AddStandartTableCell("OgI", VStandartTableCell(1034, 36, 4)); + data->AddStandartTableCell("OgII", VStandartTableCell(1044, 38, 2)); + data->AddStandartTableCell("OgIII", VStandartTableCell(1000, 40, 0)); + data->AddStandartTableCell("Ot", VStandartTableCell(780, 40, 0)); + data->AddStandartTableCell("Ob", VStandartTableCell(984, 30, 10)); + data->AddStandartTableCell("ObI", VStandartTableCell(964, 24, 12)); + data->AddStandartTableCell("Obed", VStandartTableCell(566, 18, 6)); + data->AddStandartTableCell("Ok", VStandartTableCell(386, 8, 8)); + data->AddStandartTableCell("Oi", VStandartTableCell(380, 8, 6)); + data->AddStandartTableCell("Osch", VStandartTableCell(234, 4, 4)); + data->AddStandartTableCell("Os", VStandartTableCell(350, 2, 8)); + data->AddStandartTableCell("Dsb", VStandartTableCell(1120, 0, 44)); + data->AddStandartTableCell("Dsp", VStandartTableCell(1110, 0, 43)); + data->AddStandartTableCell("Dn", VStandartTableCell(826, -3, 37)); + data->AddStandartTableCell("Dps", VStandartTableCell(316, 4, 7)); + data->AddStandartTableCell("Dpob", VStandartTableCell(783, 14, 15)); + data->AddStandartTableCell("Ds", VStandartTableCell(260, 1, 6)); + data->AddStandartTableCell("Op", VStandartTableCell(316, 12, 0)); + data->AddStandartTableCell("Ozap", VStandartTableCell(180, 4, 0)); + data->AddStandartTableCell("Pkis", VStandartTableCell(250, 4, 0)); + data->AddStandartTableCell("SHp", VStandartTableCell(160, 1, 4)); + data->AddStandartTableCell("Dlych", VStandartTableCell(500, 2, 15)); + data->AddStandartTableCell("Dzap", VStandartTableCell(768, 2, 24)); + data->AddStandartTableCell("DIIIp", VStandartTableCell(970, 2, 29)); + data->AddStandartTableCell("Vprp", VStandartTableCell(214, 3, 3)); + data->AddStandartTableCell("Vg", VStandartTableCell(262, 8, 3)); + data->AddStandartTableCell("Dtp", VStandartTableCell(460, 7, 9)); + data->AddStandartTableCell("Dp", VStandartTableCell(355, 5, 5)); + data->AddStandartTableCell("Vprz", VStandartTableCell(208, 3, 5)); + data->AddStandartTableCell("Dts", VStandartTableCell(438, 2, 10)); + data->AddStandartTableCell("DtsI", VStandartTableCell(469, 2, 10)); + data->AddStandartTableCell("Dvcht", VStandartTableCell(929, 9, 19)); + data->AddStandartTableCell("SHg", VStandartTableCell(370, 14, 4)); + data->AddStandartTableCell("Cg", VStandartTableCell(224, 6, 0)); + data->AddStandartTableCell("SHs", VStandartTableCell(416, 10, 2)); + data->AddStandartTableCell("dpzr", VStandartTableCell(121, 6, 0)); + data->AddStandartTableCell("Ogol", VStandartTableCell(576, 4, 4)); + data->AddStandartTableCell("Ssh1", VStandartTableCell(205, 5, 0)); + data->AddStandartTableCell("St", VStandartTableCell(410, 20, 0)); + data->AddStandartTableCell("Drzap", VStandartTableCell(594, 3, 19)); + data->AddStandartTableCell("DbII", VStandartTableCell(1020, 0, 44)); + data->AddStandartTableCell("Sb", VStandartTableCell(504, 15, 4)); +} + +void MainWindow::ChangedSize(const QString & text){ + qint32 size = text.toInt(); + data->SetSize(size*10); + doc->FullUpdateTree(); +} + +void MainWindow::ChangedGrowth(const QString &text){ + qint32 growth = text.toInt(); + data->SetGrowth(growth*10); + doc->FullUpdateTree(); +} + +void MainWindow::SetEnableWidgets(bool enable){ + ui->actionSaveAs->setEnabled(enable); + ui->actionDraw->setEnabled(enable); + ui->actionDetails->setEnabled(enable); + ui->toolButtonSinglePoint->setEnabled(enable); + ui->actionOptionDraw->setEnabled(enable); + ui->actionSave->setEnabled(enable); + ui->actionTable->setEnabled(enable); +} + +void MainWindow::triggeredActionTable(bool checked){ + if(checked){ + dialogTable = new DialogIncrements(data, doc, 0); + connect(dialogTable, &DialogIncrements::closedActionTable, this, + &MainWindow::closedActionTable); + dialogTable->show(); + } else { + ui->actionTable->setChecked(true); + dialogTable->activateWindow(); + } +} + +void MainWindow::closedActionTable(){ + ui->actionTable->setChecked(false); + delete dialogTable; +} + +void MainWindow::closeEvent ( QCloseEvent * event ){ + if(ui->actionTable->isChecked()==true){ + delete dialogTable; + } + event->accept(); +} + MainWindow::~MainWindow(){ CanselTool(); delete ui; diff --git a/mainwindow.h b/mainwindow.h index b348c5ad7..54eaff847 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,6 +8,7 @@ #include "widgets/vmaingraphicsscene.h" #include "dialogs/dialogsinglepoint.h" +#include "dialogs/dialogincrements.h" #include "tools/vtoolsimplepoint.h" #include "xml/vdomdocument.h" #include "container/vcontainer.h" @@ -46,9 +47,14 @@ public slots: void triggeredActionOpen(); void triggeredActionNew(); void haveChange(); + void ChangedSize(const QString &text); + void ChangedGrowth(const QString & text); + void triggeredActionTable(bool checked); + void closedActionTable(); protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); + virtual void closeEvent ( QCloseEvent * event ); private: Ui::MainWindow *ui; Tools::Enum tool; @@ -57,6 +63,7 @@ private: QLabel *helpLabel; bool isInitialized; DialogSinglePoint *dialogSinglePoint; + DialogIncrements *dialogTable; VDomDocument *doc; VContainer *data; QComboBox *comboBoxDraws; @@ -66,6 +73,8 @@ private: void ToolBarDraws(); void CanselTool(); void ArrowTool(); + void CreateManTableIGroup () const; + void SetEnableWidgets(bool enable); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index ce219cf96..e9fc06b2d 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -447,6 +447,18 @@ Змінити ім'я креслення + + + true + + + + :/icon/32x32/table.png:/icon/32x32/table.png + + + Таблиці змінних + + diff --git a/tools/vtoolpoint.cpp b/tools/vtoolpoint.cpp new file mode 100644 index 000000000..ea7402129 --- /dev/null +++ b/tools/vtoolpoint.cpp @@ -0,0 +1,195 @@ +#include "vtoolpoint.h" +#include +#include +#include +#include +#include + +#include "../options.h" +#include "../container/vpointf.h" + +VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, + QGraphicsItem *parent):QGraphicsEllipseItem(parent){ + this->doc = doc; + this->data = data; + radius = 1.5*PrintDPI/25.4; + this->id = id; + nameActivDraw = doc->GetNameActivDraw(); + //create circle + VPointF point = data->GetPoint(id); + QRectF rec = QRectF(point.x(), point.y(), radius*2, radius*2); + rec.translate(point.x()-rec.center().x(), point.y()-rec.center().y()); + this->setRect(rec); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setBrush(QBrush(Qt::NoBrush)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + + //Тексто мітка точки + namePoint = new VGraphicsSimpleTextItem(point.name(), this); + rec = this->rect(); + namePoint->setPos(QPointF(rec.center().x()+point.mx(), rec.center().y()+point.my())); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VToolPoint::NameChangePosition); + + //Лінія, що з'єднує точку і мітку + QRectF nameRec = namePoint->sceneBoundingRect(); + QPointF p1, p2; + LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2); + QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center())); + line = new QGraphicsLineItem(QLineF(p1, pRec), this); + line->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){ + line->setVisible(false); + } else { + line->setVisible(true); + } + + connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VToolPoint::ChangedActivDraw); + connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VToolPoint::ChangedNameDraw); + connect(this, &VToolPoint::haveLiteChange, this->doc, &VDomDocument::haveLiteChange); + connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VToolPoint::FullUpdateFromFile); +} + +void VToolPoint::NameChangePosition(const QPointF pos){ + VPointF point = data->GetPoint(id); + QRectF rec = this->rect(); + point.setMx(pos.x() - rec.center().x()); + point.setMy(pos.y() - rec.center().y()); + RefreshLine(); + LiteUpdateFromGui(point.name(), point.mx(), point.my()); + data->UpdatePoint(id, point); +} + +/* + * Взято з сайту http://hardfire.ru/cross_line_circle + */ +qint32 VToolPoint::LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, + QPointF &p2) const{ + const qreal eps = 1e-8; + //коефіцієнти для рівняння відрізку + qreal a = line.p2().y() - line.p1().y(); + qreal b = line.p1().x() - line.p2().x(); + // В даному випадку не використовується. + //qreal c = - a * line.p1().x() - b * line.p1().y(); + // проекция центра окружности на прямую + QPointF p = ClosestPoint (line, center); + // сколько всего решений? + qint32 flag = 0; + qreal d = QLineF (center, p).length(); + if (qAbs (d - radius) <= eps){ + flag = 1; + } else { + if (radius > d){ + flag = 2; + } else { + return 0; + } + } + // находим расстояние от проекции до точек пересечения + qreal k = sqrt (radius * radius - d * d); + qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); + // добавляем к проекции векторы направленные к точкам пеерсечения + p1 = add_vector (p, QPointF (0, 0), QPointF (- b, a), k / t); + p2 = add_vector (p, QPointF (0, 0), QPointF (b, - a), k / t); + return flag; +} + +/* + * Добавление вектора к точке + * Взято з сайту http://hardfire.ru/add_vector + */ +QPointF VToolPoint::add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const{ + return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k); +} + +QPointF VToolPoint::ClosestPoint(QLineF line, QPointF p) const{ + QLineF lineP2pointFrom = QLineF(line.p2(), p); + qreal angle = 180-line.angleTo(lineP2pointFrom)-90; + QLineF pointFromlineP2 = QLineF(p, line.p2()); + pointFromlineP2.setAngle(pointFromlineP2.angle()+angle); + QPointF point; + QLineF::IntersectType type = pointFromlineP2.intersect(line,&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } else{ + if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ){ + Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); + return point; + } + } + return point; +} + +QPointF VToolPoint::LineIntersectRect(QRectF rec, QLineF line) const{ + qreal x1, y1, x2, y2; + rec.getCoords(&x1, &y1, &x2, &y2); + QPointF point; + QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x1,y2)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x2,y1)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + type = line.intersect(QLineF(QPointF(x1,y2), QPointF(x2,y2)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + type = line.intersect(QLineF(QPointF(x2,y1), QPointF(x2,y2)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); + return point; +} + +void VToolPoint::RefreshLine(){ + QRectF nameRec = namePoint->sceneBoundingRect(); + QPointF p1, p2; + QRectF rec = this->rect(); + LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2); + QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center())); + line->setLine(QLineF(p1, pRec)); + if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){ + line->setVisible(false); + } else { + line->setVisible(true); + } +} + +void VToolPoint::LiteUpdateFromGui(const QString& name, qreal mx, qreal my){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", name); + domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4)); + domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4)); + emit haveLiteChange(); + } +} + +void VToolPoint::ChangedNameDraw(const QString oldName, const QString newName){ + if(nameActivDraw == oldName){ + nameActivDraw = newName; + } +} + +void VToolPoint::ChangedActivDraw(const QString newName){ + if(nameActivDraw == newName){ + this->setPen(QPen(Qt::black, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + namePoint->setFlag(QGraphicsItem::ItemIsMovable, true); + namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true); + namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + namePoint->setBrush(QBrush(Qt::black)); + line->setPen(QPen(Qt::black, widthHairLine)); + } else { + this->setPen(QPen(Qt::gray, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, false); + namePoint->setFlag(QGraphicsItem::ItemIsMovable, false); + namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false); + namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); + namePoint->setBrush(QBrush(Qt::gray)); + line->setPen(QPen(Qt::gray, widthHairLine)); + } +} diff --git a/tools/vtoolpoint.h b/tools/vtoolpoint.h new file mode 100644 index 000000000..18df133f5 --- /dev/null +++ b/tools/vtoolpoint.h @@ -0,0 +1,50 @@ +#ifndef VTOOLPOINT_H +#define VTOOLPOINT_H + +#include +#include + +#include "../widgets/vgraphicssimpletextitem.h" +#include "../container/vcontainer.h" +#include "../xml/vdomdocument.h" + +namespace Tool{ + enum Enum + { + FromGui, + FromFile + }; +} + +class VToolPoint: public QObject, public QGraphicsEllipseItem +{ + Q_OBJECT +public: + VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); +public slots: + void NameChangePosition(const QPointF pos); + virtual void ChangedActivDraw(const QString newName); + virtual void FullUpdateFromFile()=0; + void ChangedNameDraw(const QString oldName, const QString newName); +signals: + void haveLiteChange(); +protected: + qreal radius; + VDomDocument *doc; + VContainer *data; + VGraphicsSimpleTextItem *namePoint; + QGraphicsLineItem *line; + qint64 id; + QString nameActivDraw; + virtual void AddToFile()=0; + void RefreshLine(); +private: + qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, + QPointF &p2) const; + QPointF LineIntersectRect(QRectF rec, QLineF line) const; + QPointF ClosestPoint(QLineF line, QPointF p) const; + QPointF add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const; + void LiteUpdateFromGui(const QString& name, qreal mx, qreal my); +}; + +#endif // VTOOLPOINT_H diff --git a/tools/vtoolsimplepoint.cpp b/tools/vtoolsimplepoint.cpp index 14eb78adb..eaef1faf9 100644 --- a/tools/vtoolsimplepoint.cpp +++ b/tools/vtoolsimplepoint.cpp @@ -12,173 +12,25 @@ #include "../dialogs/dialogsinglepoint.h" VToolSimplePoint::VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, - QGraphicsItem * parent ):QGraphicsEllipseItem(parent){ - InitializeSimplePoint(doc, data, id); - if(typeCreation == Tool::FromGui){ - AddSimplePointToFile(); - } -} - -void VToolSimplePoint::InitializeSimplePoint(VDomDocument *doc, VContainer *data, qint64 id){ + QGraphicsItem * parent ):VToolPoint(doc, data, id, parent){ ignoreContextMenuEvent = false;//don't ignore context menu events; - this->doc = doc; - this->data = data; - radius = 1.5*PrintDPI/25.4; - this->id = id; - nameActivDraw = doc->GetNameActivDraw(); - //create circle - VPointF point = data->GetPoint(id); - QRectF rec = QRectF(point.x(), point.y(), radius*2, radius*2); - rec.translate(point.x()-rec.center().x(), point.y()-rec.center().y()); - this->setRect(rec); - this->setPen(QPen(Qt::black, widthHairLine)); - this->setBrush(QBrush(Qt::NoBrush)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - - //Тексто мітка точки - namePoint = new VGraphicsSimpleTextItem(point.name(), this); - rec = this->rect(); - namePoint->setPos(QPointF(rec.center().x()+point.mx(), rec.center().y()+point.my())); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VToolSimplePoint::NameChangePosition); - - //Лінія, що з'єднує точку і мітку - QRectF nameRec = namePoint->sceneBoundingRect(); - QPointF p1, p2; - LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2); - QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center())); - line = new QGraphicsLineItem(QLineF(p1, pRec), this); - line->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){ - line->setVisible(false); - } else { - line->setVisible(true); - } - - connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VToolSimplePoint::ChangedActivDraw); - connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VToolSimplePoint::ChangedNameDraw); connect(this, &VToolSimplePoint::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); - connect(this, &VToolSimplePoint::haveLiteChange, this->doc, &VDomDocument::haveLiteChange); - connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VToolSimplePoint::FullUpdateFromFile); -} - -void VToolSimplePoint::NameChangePosition(const QPointF pos){ - VPointF point = data->GetPoint(id); - QRectF rec = this->rect(); - point.setMx(pos.x() - rec.center().x()); - point.setMy(pos.y() - rec.center().y()); - RefreshLine(); - LiteUpdateFromGui(point.name(), point.mx(), point.my()); - data->UpdatePoint(id, point); -} - -/* - * Взято з сайту http://hardfire.ru/cross_line_circle - */ -qint32 VToolSimplePoint::LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2) const{ - const qreal eps = 1e-8; - //коефіцієнти для рівняння відрізку - qreal a = line.p2().y() - line.p1().y(); - qreal b = line.p1().x() - line.p2().x(); - // В даному випадку не використовується. - //qreal c = - a * line.p1().x() - b * line.p1().y(); - // проекция центра окружности на прямую - QPointF p = ClosestPoint (line, center); - // сколько всего решений? - qint32 flag = 0; - qreal d = QLineF (center, p).length(); - if (qAbs (d - radius) <= eps){ - flag = 1; - } else { - if (radius > d){ - flag = 2; - } else { - return 0; - } + if(typeCreation == Tool::FromGui){ + AddToFile(); } - // находим расстояние от проекции до точек пересечения - qreal k = sqrt (radius * radius - d * d); - qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); - // добавляем к проекции векторы направленные к точкам пеерсечения - p1 = add_vector (p, QPointF (0, 0), QPointF (- b, a), k / t); - p2 = add_vector (p, QPointF (0, 0), QPointF (b, - a), k / t); - return flag; -} - -/* - * Добавление вектора к точке - * Взято з сайту http://hardfire.ru/add_vector - */ -QPointF VToolSimplePoint::add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const{ - return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k); -} - -QPointF VToolSimplePoint::ClosestPoint(QLineF line, QPointF p) const{ - QLineF lineP2pointFrom = QLineF(line.p2(), p); - qreal angle = 180-line.angleTo(lineP2pointFrom)-90; - QLineF pointFromlineP2 = QLineF(p, line.p2()); - pointFromlineP2.setAngle(pointFromlineP2.angle()+angle); - QPointF point; - QLineF::IntersectType type = pointFromlineP2.intersect(line,&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } else{ - if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ){ - Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); - return point; - } - } - return point; -} - -QPointF VToolSimplePoint::LineIntersectRect(QRectF rec, QLineF line) const{ - qreal x1, y1, x2, y2; - rec.getCoords(&x1, &y1, &x2, &y2); - QPointF point; - QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x1,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x2,y1)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - type = line.intersect(QLineF(QPointF(x1,y2), QPointF(x2,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - type = line.intersect(QLineF(QPointF(x2,y1), QPointF(x2,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); - return point; } void VToolSimplePoint::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - namePoint->setFlag(QGraphicsItem::ItemIsMovable, true); - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true); - namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - namePoint->setBrush(QBrush(Qt::black)); - line->setPen(QPen(Qt::black, widthHairLine)); + VToolPoint::ChangedActivDraw(newName); ignoreContextMenuEvent = false; } else { - this->setPen(QPen(Qt::gray, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, false); - namePoint->setFlag(QGraphicsItem::ItemIsMovable, false); - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false); - namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); - namePoint->setBrush(QBrush(Qt::gray)); - line->setPen(QPen(Qt::gray, widthHairLine)); + VToolPoint::ChangedActivDraw(newName); ignoreContextMenuEvent = true; } } -void VToolSimplePoint::AddSimplePointToFile() const{ +void VToolSimplePoint::AddToFile(){ VPointF point = data->GetPoint(id); QDomElement domElement = doc->createElement("point"); @@ -219,16 +71,6 @@ void VToolSimplePoint::AddSimplePointToFile() const{ } } -void VToolSimplePoint::LiteUpdateFromGui(const QString& name, qreal mx, qreal my){ - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", name); - domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4)); - domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4)); - emit haveLiteChange(); - } -} - void VToolSimplePoint::FullUpdateFromGui(const QString &name, qreal x, qreal y){ QDomElement domElement = doc->elementById(QString().setNum(id)); if(domElement.isElement()){ @@ -239,12 +81,6 @@ void VToolSimplePoint::FullUpdateFromGui(const QString &name, qreal x, qreal y){ } } -void VToolSimplePoint::ChangedNameDraw(const QString oldName, const QString newName){ - if(nameActivDraw == oldName){ - nameActivDraw = newName; - } -} - void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){ if(!ignoreContextMenuEvent){ QMenu menu; @@ -285,17 +121,3 @@ void VToolSimplePoint::FullUpdateFromFile(){ RefreshLine(); } - -void VToolSimplePoint::RefreshLine(){ - QRectF nameRec = namePoint->sceneBoundingRect(); - QPointF p1, p2; - QRectF rec = this->rect(); - LineIntersectCircle(rec.center(), radius, QLineF(rec.center(), nameRec.center()), p1, p2); - QPointF pRec = LineIntersectRect(nameRec, QLineF(rec.center(), nameRec.center())); - line->setLine(QLineF(p1, pRec)); - if(QLineF(p1, pRec).length() <= 4*PrintDPI/25.4){ - line->setVisible(false); - } else { - line->setVisible(true); - } -} diff --git a/tools/vtoolsimplepoint.h b/tools/vtoolsimplepoint.h index 94f6ac407..8f0608ddf 100644 --- a/tools/vtoolsimplepoint.h +++ b/tools/vtoolsimplepoint.h @@ -1,56 +1,28 @@ #ifndef VTOOLSIMPLEPOINT_H #define VTOOLSIMPLEPOINT_H -#include -#include - -#include "../widgets/vgraphicssimpletextitem.h" #include "../container/vcontainer.h" #include "../xml/vdomdocument.h" +#include "vtoolpoint.h" -namespace Tool{ - enum Enum - { - FromGui, - FromFile - }; -} - -class VToolSimplePoint : public QObject, public QGraphicsEllipseItem +class VToolSimplePoint : public VToolPoint { Q_OBJECT public: VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); public slots: - void NameChangePosition(const QPointF pos); - void ChangedActivDraw(const QString newName); - void ChangedNameDraw(const QString oldName, const QString newName); - void FullUpdateFromFile(); + virtual void ChangedActivDraw(const QString newName); + virtual void FullUpdateFromFile(); signals: void FullUpdateTree(); - void haveLiteChange(); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); private: - qreal radius; - VDomDocument *doc; - VContainer *data; - VGraphicsSimpleTextItem *namePoint; - QGraphicsLineItem *line; - qint64 id; - QString nameActivDraw; bool ignoreContextMenuEvent; - qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2) const; - QPointF LineIntersectRect(QRectF rec, QLineF line) const; - QPointF ClosestPoint(QLineF line, QPointF p) const; - QPointF add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const; - void AddSimplePointToFile() const; - void LiteUpdateFromGui(const QString& name, qreal mx, qreal my); + void FullUpdateFromGui(const QString& name, qreal x, qreal y); - void InitializeSimplePoint(VDomDocument *doc, VContainer *data, qint64 id); - void RefreshLine(); }; #endif // VTOOLSIMPLEPOINT_H diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 56420d0e4..a29231d4d 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -61,6 +61,8 @@ void VDomDocument::CreateEmptyFile(){ this->appendChild(domElement); QDomNode xmlNode = this->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); this->insertBefore(xmlNode, this->firstChild()); + QDomElement incrElement = this->createElement("increments"); + domElement.appendChild(incrElement); } bool VDomDocument::CheckNameDraw(const QString& name) const{ @@ -229,8 +231,35 @@ void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *scene, QCombo AddNewDraw(domElement, comboBoxDraws); } ParseDrawElement(scene, domElement, parse); - domNode = domNode.nextSibling(); - continue; + } + if(domElement.tagName()=="increments"){ + ParseIncrementsElement(domElement); + } + } + } + domNode = domNode.nextSibling(); + } +} + +void VDomDocument::ParseIncrementsElement(const QDomNode &node){ + QDomNode domNode = node.firstChild(); + while(!domNode.isNull()){ + if(domNode.isElement()){ + QDomElement domElement = domNode.toElement(); + if(!domElement.isNull()){ + if(domElement.tagName() == "increment"){ + QString name,desc; + qint32 base; + qreal ksize, kgrowth; + qint64 id; + id = domElement.attribute("id", "").toLongLong(); + name = domElement.attribute("name", ""); + base = domElement.attribute("base","").toInt(); + ksize = domElement.attribute("ksize","").toDouble(); + kgrowth = domElement.attribute("kgrowth","").toDouble(); + desc = domElement.attribute("description",""); + data->AddIncrementTableRow(name, + VIncrementTableRow(id, base, ksize, kgrowth, desc)); } } } @@ -263,6 +292,7 @@ void VDomDocument::AddNewDraw(const QDomElement& node, QComboBox *comboBoxDraws) } } } + comboBoxDraws->addItem(name, true); } } } diff --git a/xml/vdomdocument.h b/xml/vdomdocument.h index 1eb80aff6..ebc1c5228 100644 --- a/xml/vdomdocument.h +++ b/xml/vdomdocument.h @@ -57,6 +57,7 @@ private: Document::Enum parse); void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, Document::Enum parse, const QString &type); + void ParseIncrementsElement(const QDomNode& node); void AddNewDraw(const QDomElement &node, QComboBox *comboBoxDraws)const; };