Create window table of variables
This commit is contained in:
parent
0b6311d4cd
commit
1cd249cc14
|
@ -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 \
|
||||
|
|
323
container/calculator.cpp
Normal file
323
container/calculator.cpp
Normal file
|
@ -0,0 +1,323 @@
|
|||
#include "calculator.h"
|
||||
#include <cmath>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#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()<<"Формула: "<<prog;
|
||||
index = 0;
|
||||
qreal result = get_exp();
|
||||
QString str = QString(" = %1").arg(result, 0, 'f', 3);
|
||||
debugFormula.append(str);
|
||||
qDebug()<<"Результат:"<<debugFormula;
|
||||
return result;
|
||||
}
|
||||
|
||||
qreal Calculator::get_exp(){
|
||||
qreal result = 0;
|
||||
get_token();
|
||||
if(token.isEmpty()) {
|
||||
serror(2);
|
||||
return 0;
|
||||
}
|
||||
level2(&result);
|
||||
putback(); /* возвращает последнюю считаную
|
||||
лексему обратно во входной поток */
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Сложение или вычитание двух термов */
|
||||
void Calculator::level2(qreal *result){
|
||||
QChar op;
|
||||
qreal hold;
|
||||
|
||||
level3(result);
|
||||
while((op=token[0]) == '+' || op == '-') {
|
||||
get_token();
|
||||
level3(&hold);
|
||||
arith(op,result,&hold);
|
||||
}
|
||||
}
|
||||
|
||||
/* Вычисление произведения или частного двух фвкторов */
|
||||
void Calculator::level3(qreal *result){
|
||||
QChar op;
|
||||
qreal hold;
|
||||
|
||||
level4(result);
|
||||
|
||||
while((op = token[0]) == '*' || op == '/' || op == '%') {
|
||||
get_token();
|
||||
level4(&hold);
|
||||
arith(op,result,&hold);
|
||||
}
|
||||
}
|
||||
|
||||
/* Обработка степени числа (целочисленной) */
|
||||
void Calculator::level4(qreal *result){
|
||||
qreal hold;
|
||||
|
||||
level5(result);
|
||||
if(token[0] == '^') {
|
||||
get_token();
|
||||
level4(&hold);
|
||||
arith('^', result, &hold);
|
||||
}
|
||||
}
|
||||
|
||||
/* Унарный + или - */
|
||||
void Calculator::level5(qreal *result){
|
||||
QChar op;
|
||||
|
||||
op = '\0';
|
||||
if((token_type==DELIMITER) && token[0]=='+' || token[0]=='-') {
|
||||
op = token[0];
|
||||
get_token();
|
||||
}
|
||||
level6(result);
|
||||
if(op != '\0')
|
||||
unary(op, result);
|
||||
}
|
||||
|
||||
/* Обработка выражения в круглых скобках */
|
||||
void Calculator::level6(qreal *result){
|
||||
if((token[0] == '(') && (token_type == DELIMITER)) {
|
||||
get_token();
|
||||
level2(result);
|
||||
if(token[0] != ')')
|
||||
serror(1);
|
||||
get_token();
|
||||
} else
|
||||
primitive(result);
|
||||
}
|
||||
|
||||
/* Определение значения переменной по ее имени */
|
||||
void Calculator::primitive(qreal *result){
|
||||
QString str;
|
||||
switch(token_type) {
|
||||
case VARIABLE:
|
||||
*result = find_var(token);
|
||||
str = QString("%1").arg(*result, 0, 'f', 3);
|
||||
debugFormula.append(str);
|
||||
get_token();
|
||||
return;
|
||||
case NUMBER:
|
||||
*result = token.toDouble();
|
||||
str = QString("%1").arg(*result, 0, 'f', 3);
|
||||
debugFormula.append(str);
|
||||
get_token();
|
||||
return;
|
||||
default:
|
||||
serror(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Выполнение специфицированной арифметики */
|
||||
void Calculator::arith(QChar o, qreal *r, qreal *h){
|
||||
qreal t;//, ex;
|
||||
|
||||
switch(o.toLatin1()) {
|
||||
case '-':
|
||||
*r = *r-*h;
|
||||
break;
|
||||
case '+':
|
||||
*r = *r+*h;
|
||||
break;
|
||||
case '*':
|
||||
*r = *r * *h;
|
||||
break;
|
||||
case '/':
|
||||
*r = (*r)/(*h);
|
||||
break;
|
||||
case '%':
|
||||
t = (*r)/(*h);
|
||||
*r = *r-(t*(*h));
|
||||
break;
|
||||
case '^':
|
||||
*r = pow(*r, *h);
|
||||
// ex =*r;
|
||||
// if(*h==0) {
|
||||
// *r = 1;
|
||||
// break;
|
||||
// }
|
||||
// for(t=*h-1; t>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()<<e[error];
|
||||
}
|
||||
|
||||
/* Поиск соответствия внутреннего формата для
|
||||
текущей лексемы в таблице лексем.
|
||||
*/
|
||||
char Calculator::look_up(QString s){
|
||||
QString p;
|
||||
|
||||
/* преобразование к нижнему регистру */
|
||||
p = s;
|
||||
p = p.toLower();
|
||||
|
||||
/* просматривается, если лексема обнаружена в
|
||||
таблице */
|
||||
/*
|
||||
*у нас більше немає команд що потрібно опрацьовувати
|
||||
*/
|
||||
// if(commands.contains(p)){
|
||||
// return commands[p];
|
||||
// }
|
||||
return 0; /* нераспознанная команда */
|
||||
}
|
||||
|
||||
/* Возвращает "истину", если "c" разделитель */
|
||||
bool Calculator::isdelim(QChar c){
|
||||
if(StrChr(" ;,+-<>/*%^=()",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();
|
||||
}
|
148
container/calculator.h
Normal file
148
container/calculator.h
Normal file
|
@ -0,0 +1,148 @@
|
|||
#ifndef CALCULATOR_H
|
||||
#define CALCULATOR_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QLineF>
|
||||
#include <QPointF>
|
||||
#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
|
|
@ -1,8 +1,12 @@
|
|||
#include "vcontainer.h"
|
||||
#include <QDebug>
|
||||
|
||||
#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()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
|
||||
throw"Не можу знайти змінну в стандартній таблиці вимірів за ім'ям.";
|
||||
}
|
||||
return VStandartTableCell();
|
||||
}
|
||||
|
||||
VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const{
|
||||
if(incrementTable.contains(name)){
|
||||
return incrementTable.value(name);
|
||||
} else {
|
||||
qCritical()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
|
||||
throw"Не можу знайти змінну в таблиці прибавок за ім'ям.";
|
||||
}
|
||||
return VIncrementTableRow();
|
||||
}
|
||||
|
||||
qint64 VContainer::AddPoint(const VPointF& point){
|
||||
qint64 id = getNextId();
|
||||
points[id] = point;
|
||||
return id;
|
||||
}
|
||||
|
||||
void VContainer::AddStandartTableCell(const QString& name, const VStandartTableCell& cell){
|
||||
standartTable[name] = cell;
|
||||
}
|
||||
|
||||
void VContainer::AddIncrementTableRow(const QString& name, const VIncrementTableRow& cell){
|
||||
incrementTable[name] = cell;
|
||||
}
|
||||
|
||||
qint64 VContainer::getId(){
|
||||
return _id;
|
||||
}
|
||||
|
@ -30,6 +62,10 @@ qint64 VContainer::getNextId(){
|
|||
return _id;
|
||||
}
|
||||
|
||||
void VContainer::RemoveIncrementTableRow(const QString& name){
|
||||
incrementTable.remove(name);
|
||||
}
|
||||
|
||||
void VContainer::UpdatePoint(qint64 id, const VPointF& point){
|
||||
points[id] = point;
|
||||
if(id > _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<QString, VStandartTableCell> 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<QString, VIncrementTableRow> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,46 @@
|
|||
#define VCONTAINER_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QTableWidget>
|
||||
|
||||
#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<QString, qint32> base;
|
||||
QMap<qint64, VPointF> points;
|
||||
qint64 getNextId();
|
||||
QMap<QString, VStandartTableCell> standartTable;
|
||||
QMap<QString, VIncrementTableRow> incrementTable;
|
||||
};
|
||||
|
||||
#endif // VCONTAINER_H
|
||||
|
|
58
container/vincrementtablerow.cpp
Normal file
58
container/vincrementtablerow.cpp
Normal file
|
@ -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;
|
||||
}
|
35
container/vincrementtablerow.h
Normal file
35
container/vincrementtablerow.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef VINCREMENTTABLEROW_H
|
||||
#define VINCREMENTTABLEROW_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
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
|
31
container/vstandarttablecell.cpp
Normal file
31
container/vstandarttablecell.cpp
Normal file
|
@ -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;
|
||||
}
|
22
container/vstandarttablecell.h
Normal file
22
container/vstandarttablecell.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef VSTANDARTTABLECELL_H
|
||||
#define VSTANDARTTABLECELL_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
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
|
267
dialogs/dialogincrements.cpp
Normal file
267
dialogs/dialogincrements.cpp
Normal file
|
@ -0,0 +1,267 @@
|
|||
#include "dialogincrements.h"
|
||||
#include "ui_dialogincrements.h"
|
||||
#include <QHeaderView>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#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<qint64>(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<qint64>(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<qint64>(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<qint64>(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<qint64>(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<qint64>(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;
|
||||
}
|
43
dialogs/dialogincrements.h
Normal file
43
dialogs/dialogincrements.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#ifndef DIALOGINCREMENTS_H
|
||||
#define DIALOGINCREMENTS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
|
||||
#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
|
366
dialogs/dialogincrements.ui
Normal file
366
dialogs/dialogincrements.ui
Normal file
|
@ -0,0 +1,366 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogIncrements</class>
|
||||
<widget class="QDialog" name="DialogIncrements">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>681</width>
|
||||
<height>422</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabStandart">
|
||||
<attribute name="title">
|
||||
<string>Табличні розміри</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableWidget" name="tableWidgetStandart">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>95</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>25</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>45</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderMinimumSectionSize">
|
||||
<number>8</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Позначення</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Розраховане знач.</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Базове знач.</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>В розмірах</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>В ростах</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Опис</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabIncrements">
|
||||
<attribute name="title">
|
||||
<string>Прибавки</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QTableWidget" name="tableWidgetIncrement">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>95</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>17</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>45</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Позначення</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Розраховане знач.</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Базове знач.</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>В розмірах</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>В ростах</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Опис</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QToolButton" name="toolButtonAdd">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="list-add">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QToolButton" name="toolButtonRemove">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="list-remove">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Лінії</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>137</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Лінія</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Довжина лінії</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
<string>Сплайни</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableWidget" name="tableWidget_2">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>137</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Сплайн</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Довжина сплайну</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_5">
|
||||
<attribute name="title">
|
||||
<string>Дуги</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableWidget" name="tableWidget_3">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>137</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Дуга</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Довжина дуги</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>DialogIncrements</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>DialogIncrements</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
1
icon.qrc
1
icon.qrc
|
@ -7,5 +7,6 @@
|
|||
<file>icon/32x32/arrow_cursor.png</file>
|
||||
<file>icon/32x32/new_draw.png</file>
|
||||
<file>icon/32x32/option_draw.png</file>
|
||||
<file>icon/32x32/table.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
BIN
icon/32x32/table.png
Normal file
BIN
icon/32x32/table.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
129
mainwindow.cpp
129
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<void (QComboBox::*)(const QString &)>(&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<void (QComboBox::*)(const QString &)>(&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<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &MainWindow::currentDrawChanged);
|
||||
doc->Parse(Document::FullParse, scene, comboBoxDraws);
|
||||
CreateManTableIGroup ();
|
||||
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -447,6 +447,18 @@
|
|||
<string>Змінити ім'я креслення</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionTable">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icon.qrc">
|
||||
<normaloff>:/icon/32x32/table.png</normaloff>:/icon/32x32/table.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Таблиці змінних</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
|
195
tools/vtoolpoint.cpp
Normal file
195
tools/vtoolpoint.cpp
Normal file
|
@ -0,0 +1,195 @@
|
|||
#include "vtoolpoint.h"
|
||||
#include <QPen>
|
||||
#include <QBrush>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsItem>
|
||||
#include <cmath>
|
||||
|
||||
#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));
|
||||
}
|
||||
}
|
50
tools/vtoolpoint.h
Normal file
50
tools/vtoolpoint.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef VTOOLPOINT_H
|
||||
#define VTOOLPOINT_H
|
||||
|
||||
#include <QGraphicsEllipseItem>
|
||||
#include <QGraphicsLineItem>
|
||||
|
||||
#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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +1,28 @@
|
|||
#ifndef VTOOLSIMPLEPOINT_H
|
||||
#define VTOOLSIMPLEPOINT_H
|
||||
|
||||
#include <QGraphicsEllipseItem>
|
||||
#include <QGraphicsLineItem>
|
||||
|
||||
#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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user