Add tool endLine.

This commit is contained in:
dismine 2013-07-25 15:00:51 +03:00
parent 85b87b8ade
commit 9e78a12d62
39 changed files with 1666 additions and 238 deletions

View File

@ -26,7 +26,9 @@ SOURCES += main.cpp\
container/vstandarttablecell.cpp \ container/vstandarttablecell.cpp \
container/vincrementtablerow.cpp \ container/vincrementtablerow.cpp \
widgets/delegate.cpp \ widgets/delegate.cpp \
widgets/doubledelegate.cpp widgets/doubledelegate.cpp \
dialogs/dialogendline.cpp \
tools/vtoolendline.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \ widgets/vmaingraphicsscene.h \
@ -43,11 +45,14 @@ HEADERS += mainwindow.h \
container/vstandarttablecell.h \ container/vstandarttablecell.h \
container/vincrementtablerow.h \ container/vincrementtablerow.h \
widgets/delegate.h \ widgets/delegate.h \
widgets/doubledelegate.h widgets/doubledelegate.h \
dialogs/dialogendline.h \
tools/vtoolendline.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \ dialogs/dialogsinglepoint.ui \
dialogs/dialogincrements.ui dialogs/dialogincrements.ui \
dialogs/dialogendline.ui
RESOURCES += \ RESOURCES += \
icon.qrc \ icon.qrc \

View File

@ -12,13 +12,15 @@
#define FINISHED 10 #define FINISHED 10
#define EOL 9 #define EOL 9
Calculator::Calculator(VContainer *data){ Calculator::Calculator(const VContainer *data){
index = 0; index = 0;
this->data = data; this->data = data;
} }
qreal Calculator::eval(QString prog){ qreal Calculator::eval(QString prog, QString *errorMsg){
this->errorMsg = errorMsg;
this->errorMsg->clear();
debugFormula.clear(); debugFormula.clear();
this->prog = prog; this->prog = prog;
qDebug()<<"Формула: "<<prog; qDebug()<<"Формула: "<<prog;
@ -187,17 +189,10 @@ void Calculator::serror(qint32 error){
"Непарные круглые скобки", "Непарные круглые скобки",
"Это не выражение", "Это не выражение",
"Предполагается символ равенства", "Предполагается символ равенства",
"Не переменная", "Не переменная"
"Таблица меток переполнена",
"Дублирование меток",
"Неопределенная метка",
"Необходим оператор THEN",
"Необходим оператор TO",
"Уровень вложенности цикла FOR слишком велик",
"NEXT не соответствует FOR",
"Уровень вложенности GOSUB слишком велик",
"RETURN не соответствует GOSUB"
}; };
errorMsg->clear();
*errorMsg = e[error];
qDebug()<<e[error]; qDebug()<<e[error];
} }

View File

@ -19,14 +19,15 @@ public:
* @brief Calculator конструктор класу. Використовується при розрахунку лекала. * @brief Calculator конструктор класу. Використовується при розрахунку лекала.
* @param data покажчик на контейнер змінних * @param data покажчик на контейнер змінних
*/ */
Calculator(VContainer *data); Calculator(const VContainer *data);
/** /**
* @brief eval виконує розрахунок формули. * @brief eval виконує розрахунок формули.
* @param prog рядко в якому зберігається формула. * @param prog рядко в якому зберігається формула.
* @return значення формули. * @return значення формули.
*/ */
qreal eval(QString prog); qreal eval(QString prog, QString *errorMsg);
private: private:
QString *errorMsg;
/** /**
* @brief token теперішня лексема. * @brief token теперішня лексема.
*/ */
@ -50,7 +51,7 @@ private:
/** /**
* @brief data контейнер усіх змінних. * @brief data контейнер усіх змінних.
*/ */
VContainer *data; const VContainer *data;
/** /**
* @brief debugFormula рядок розшифрованої формули. * @brief debugFormula рядок розшифрованої формули.
*/ */

View File

@ -102,12 +102,17 @@ void VContainer::Clear(){
points.clear(); points.clear();
standartTable.clear(); standartTable.clear();
incrementTable.clear(); incrementTable.clear();
lengthLines.clear();
} }
void VContainer::ClearIncrementTable(){ void VContainer::ClearIncrementTable(){
incrementTable.clear(); incrementTable.clear();
} }
void VContainer::ClearLengthLines(){
lengthLines.clear();
}
void VContainer::SetSize(qint32 size){ void VContainer::SetSize(qint32 size){
base["Сг"] = size; base["Сг"] = size;
} }
@ -131,94 +136,57 @@ bool VContainer::IncrementTableContains(const QString& name){
qreal VContainer::FindVar(const QString &name, bool *ok)const{ qreal VContainer::FindVar(const QString &name, bool *ok)const{
if(base.contains(name)){ if(base.contains(name)){
*ok = true; *ok = true;
return base.value(name)/PrintDPI*25.4; return base.value(name);
} }
if(standartTable.contains(name)){ if(standartTable.contains(name)){
*ok = true; *ok = true;
return GetValueStandartTableCell(name)/PrintDPI*25.4; return GetValueStandartTableCell(name);
} }
if(incrementTable.contains(name)){ if(incrementTable.contains(name)){
*ok = true; *ok = true;
return GetValueIncrementTableRow(name)/PrintDPI*25.4; return GetValueIncrementTableRow(name);
}
if(lengthLines.contains(name)){
*ok = true;
return lengthLines.value(name);
} }
*ok = false; *ok = false;
return 0; return 0;
} }
void VContainer::FillStandartTable(QTableWidget *table) const{ const QMap<qint64, VPointF> *VContainer::DataPoints() const{
qint32 currentRow = -1; return &points;
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{ const QMap<QString, qint32> *VContainer::DataBase() const{
qint32 currentRow = -1; return &base;
QMapIterator<QString, VIncrementTableRow> i(incrementTable); }
while (i.hasNext()) {
i.next(); const QMap<QString, VStandartTableCell> *VContainer::DataStandartTable() const{
VIncrementTableRow cell = i.value(); return &standartTable;
currentRow++; }
table->setRowCount ( incrementTable.size() );
const QMap<QString, VIncrementTableRow> *VContainer::DataIncrementTable() const{
QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); return &incrementTable;
item->setTextAlignment(Qt::AlignHCenter); }
item->setFont(QFont("Times", 12, QFont::Bold));
item->setData(Qt::UserRole, cell.getId()); const QMap<QString, qreal> *VContainer::DataLengthLines() const{
table->setItem(currentRow, 0, item); return &lengthLines;
}
item = new QTableWidgetItem(QString().setNum(GetValueIncrementTableRow(i.key())));
item->setTextAlignment(Qt::AlignHCenter); void VContainer::AddLine(const QString &name, const qreal &value){
// set the item non-editable (view only), and non-selectable Q_ASSERT(!name.isEmpty());
Qt::ItemFlags flags = item->flags(); lengthLines[name] = value/PrintDPI*25.4;
flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag }
item->setFlags(flags);
table->setItem(currentRow, 1, item); qreal VContainer::GetLine(const QString &name) const{
Q_ASSERT(!name.isEmpty());
item = new QTableWidgetItem(QString().setNum(cell.getBase())); if(lengthLines.contains(name)){
item->setTextAlignment(Qt::AlignHCenter); return lengthLines.value(name);
table->setItem(currentRow, 2, item); } else {
qCritical()<<"Не можу знайти лінію за імям = "<<name<<" в таблиці.";
item = new QTableWidgetItem(QString().setNum(cell.getKsize())); throw"Не можу знайти лінію таблиці.";
item->setTextAlignment(Qt::AlignHCenter); }
table->setItem(currentRow, 3, item); return 0;
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);
}
} }

View File

@ -15,10 +15,12 @@ public:
VPointF GetPoint(qint64 id) const; VPointF GetPoint(qint64 id) const;
VStandartTableCell GetStandartTableCell(const QString& name) const; VStandartTableCell GetStandartTableCell(const QString& name) const;
VIncrementTableRow GetIncrementTableRow(const QString& name) const; VIncrementTableRow GetIncrementTableRow(const QString& name) const;
qreal GetLine(const QString &name) const;
qint64 getId(); qint64 getId();
qint64 AddPoint(const VPointF& point); qint64 AddPoint(const VPointF& point);
void AddStandartTableCell(const QString& name, const VStandartTableCell& cell); void AddStandartTableCell(const QString& name, const VStandartTableCell& cell);
void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell); void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell);
void AddLine(const QString &name, const qreal &value);
void UpdatePoint(qint64 id, const VPointF& point); void UpdatePoint(qint64 id, const VPointF& point);
void UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell); void UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell);
void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell); void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell);
@ -26,22 +28,28 @@ public:
qreal GetValueIncrementTableRow(const QString& name) const; qreal GetValueIncrementTableRow(const QString& name) const;
void Clear(); void Clear();
void ClearIncrementTable(); void ClearIncrementTable();
void ClearLengthLines();
void SetSize(qint32 size); void SetSize(qint32 size);
void SetGrowth(qint32 growth); void SetGrowth(qint32 growth);
qint32 size() const; qint32 size() const;
qint32 growth() const; qint32 growth() const;
qreal FindVar(const QString& name, bool *ok)const; qreal FindVar(const QString& name, bool *ok)const;
void FillStandartTable(QTableWidget *table) const;
void FillIncrementTable(QTableWidget *table) const;
bool IncrementTableContains(const QString& name); bool IncrementTableContains(const QString& name);
qint64 getNextId(); qint64 getNextId();
void RemoveIncrementTableRow(const QString& name); void RemoveIncrementTableRow(const QString& name);
const QMap<qint64, VPointF> *DataPoints() const;
const QMap<QString, qint32> *DataBase() const;
const QMap<QString, VStandartTableCell> *DataStandartTable() const;
const QMap<QString, VIncrementTableRow> *DataIncrementTable() const;
const QMap<QString, qreal> * DataLengthLines() const;
private: private:
qint64 _id; qint64 _id;
QMap<QString, qint32> base; QMap<QString, qint32> base;
QMap<qint64, VPointF> points; QMap<qint64, VPointF> points;
QMap<QString, VStandartTableCell> standartTable; QMap<QString, VStandartTableCell> standartTable;
QMap<QString, VIncrementTableRow> incrementTable; QMap<QString, VIncrementTableRow> incrementTable;
QMap<QString, qreal> lengthLines;
}; };
#endif // VCONTAINER_H #endif // VCONTAINER_H

View File

@ -1,5 +1,6 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>cursor/spoint_cursor.png</file> <file>cursor/spoint_cursor.png</file>
<file>cursor/endline_cursor.png</file>
</qresource> </qresource>
</RCC> </RCC>

BIN
cursor/endline_cursor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

369
dialogs/dialogendline.cpp Normal file
View File

@ -0,0 +1,369 @@
#include "dialogendline.h"
#include "ui_dialogendline.h"
#include <QCloseEvent>
#include <QString>
#include "../container/vpointf.h"
#include "../container/calculator.h"
DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) :
QDialog(parent), ui(new Ui::DialogEndLine)
{
ui->setupUi(this);
flagFormula = false;
flagName = false;
this->data = data;
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogEndLine::DialogAccepted);
bOk->setEnabled(false);
FillComboBoxBasePoint();
QStringList list;
list<<"Лінія"<<"Без лінії";
ui->comboBoxLineType->addItems(list);
connect(ui->toolButtonArrowDown, &QPushButton::clicked, this,
&DialogEndLine::ArrowDown);
connect(ui->toolButtonArrowUp, &QPushButton::clicked, this,
&DialogEndLine::ArrowUp);
connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this,
&DialogEndLine::ArrowLeft);
connect(ui->toolButtonArrowRight, &QPushButton::clicked, this,
&DialogEndLine::ArrowRight);
connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this,
&DialogEndLine::ArrowLeftUp);
connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this,
&DialogEndLine::ArrowLeftDown);
connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this,
&DialogEndLine::ArrowRightUp);
connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this,
&DialogEndLine::ArrowRightDown);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this,
&DialogEndLine::ClickedToolButtonPutHere);
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEndLine::PutVal);
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
ShowBase();
connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this,
&DialogEndLine::ClickedSizeGrowth);
connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this,
&DialogEndLine::ClickedStandartTable);
connect(ui->radioButtonIncrements, &QRadioButton::clicked, this,
&DialogEndLine::ClickedIncrements);
connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this,
&DialogEndLine::ClickedLengthLines);
connect(ui->toolButtonEqual, &QPushButton::clicked, this,
&DialogEndLine::ClickedToolButtonEqual);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NameChanged);
connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogEndLine::FormulaChanged);
timerFormula = new QTimer(this);
connect(timerFormula, &QTimer::timeout, this, &DialogEndLine::ClickedToolButtonEqual);
}
void DialogEndLine::ShowBase(){
disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
ui->listWidget->clear();
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
const QMap<QString, qint32> *base = data->DataBase();
QMapIterator<QString, qint32> i(*base);
while (i.hasNext()) {
i.next();
QListWidgetItem *item = new QListWidgetItem(i.key());
item->setFont(QFont("Times", 12, QFont::Bold));
ui->listWidget->addItem(item);
}
ui->listWidget->setCurrentRow (0);
}
void DialogEndLine::ShowStandartTable(){
disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
ui->listWidget->clear();
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
const QMap<QString, VStandartTableCell> *standartTable = data->DataStandartTable();
QMapIterator<QString, VStandartTableCell> i(*standartTable);
while (i.hasNext()) {
i.next();
QListWidgetItem *item = new QListWidgetItem(i.key());
item->setFont(QFont("Times", 12, QFont::Bold));
ui->listWidget->addItem(item);
}
ui->listWidget->setCurrentRow (0);
}
void DialogEndLine::ShowIncrementTable(){
disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
ui->listWidget->clear();
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
const QMap<QString, VIncrementTableRow> *incrementTable = data->DataIncrementTable();
QMapIterator<QString, VIncrementTableRow> i(*incrementTable);
while (i.hasNext()) {
i.next();
QListWidgetItem *item = new QListWidgetItem(i.key());
item->setFont(QFont("Times", 12, QFont::Bold));
ui->listWidget->addItem(item);
}
ui->listWidget->setCurrentRow (0);
}
void DialogEndLine::ShowLengthLines(){
disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
ui->listWidget->clear();
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogEndLine::ValChenged);
const QMap<QString, qreal> *linesTable = data->DataLengthLines();
QMapIterator<QString, qreal> i(*linesTable);
while (i.hasNext()) {
i.next();
QListWidgetItem *item = new QListWidgetItem(i.key());
item->setFont(QFont("Times", 12, QFont::Bold));
ui->listWidget->addItem(item);
}
ui->listWidget->setCurrentRow (0);
}
void DialogEndLine::CheackState(){
bOk->setEnabled(flagFormula & flagName);
}
void DialogEndLine::ClickedSizeGrowth(){
ShowBase();
}
void DialogEndLine::ClickedStandartTable(){
ShowStandartTable();
}
void DialogEndLine::ClickedLengthLines(){
ShowLengthLines();
}
void DialogEndLine::ClickedIncrements(){
ShowIncrementTable();
}
void DialogEndLine::ChoosedPoint(qint64 id, Scene::Type type){
if(type == Scene::Point){
VPointF point = data->GetPoint(id);
qint32 index = ui->comboBoxBasePoint->findText(point.name());
if ( index != -1 ) { // -1 for not found
ui->comboBoxBasePoint->setCurrentIndex(index);
}
this->show();
}
}
QString DialogEndLine::getPointName() const{
return pointName;
}
void DialogEndLine::setPointName(const QString &value){
pointName = value;
ui->lineEditNamePoint->setText(pointName);
}
QString DialogEndLine::getTypeLine() const{
return typeLine;
}
void DialogEndLine::setTypeLine(const QString &value){
typeLine = value;
if(typeLine == "hair"){
qint32 index = ui->comboBoxLineType->findText("Лінія");
if(index != -1){
ui->comboBoxLineType->setCurrentIndex(index);
}
}
if(typeLine == "none"){
qint32 index = ui->comboBoxLineType->findText("Без лінії");
if(index != -1){
ui->comboBoxLineType->setCurrentIndex(index);
}
}
}
QString DialogEndLine::getFormula() const{
return formula;
}
void DialogEndLine::setFormula(const QString &value){
formula = value;
ui->lineEditFormula->setText(formula);
}
qint32 DialogEndLine::getAngle() const{
return angle;
}
void DialogEndLine::setAngle(const qint32 &value){
angle = value;
ui->spinBoxAngle->setValue(angle);
}
void DialogEndLine::closeEvent ( QCloseEvent * event ){
DialogClosed(QDialog::Rejected);
event->accept();
}
qint64 DialogEndLine::getBasePointId() const
{
return basePointId;
}
void DialogEndLine::setBasePointId(const qint64 &value)
{
basePointId = value;
qint32 index = ui->comboBoxBasePoint->findData(basePointId);
if(index != -1){
ui->comboBoxBasePoint->setCurrentIndex(index);
}
}
void DialogEndLine::FillComboBoxBasePoint(){
const QMap<qint64, VPointF> *points = data->DataPoints();
QMapIterator<qint64, VPointF> i(*points);
while (i.hasNext()) {
i.next();
VPointF point = i.value();
ui->comboBoxBasePoint->addItem(point.name(), i.key());
}
}
void DialogEndLine::ArrowUp(){
ui->spinBoxAngle->setValue(90);
}
void DialogEndLine::ArrowDown(){
ui->spinBoxAngle->setValue(270);
}
void DialogEndLine::ArrowLeft(){
ui->spinBoxAngle->setValue(180);
}
void DialogEndLine::ArrowRight(){
ui->spinBoxAngle->setValue(0);
}
void DialogEndLine::ArrowLeftUp(){
ui->spinBoxAngle->setValue(135);
}
void DialogEndLine::ArrowLeftDown(){
ui->spinBoxAngle->setValue(225);
}
void DialogEndLine::ArrowRightUp(){
ui->spinBoxAngle->setValue(45);
}
void DialogEndLine::ArrowRightDown(){
ui->spinBoxAngle->setValue(315);
}
void DialogEndLine::ClickedToolButtonPutHere(){
QListWidgetItem *item = ui->listWidget->currentItem();
QString val = item->text();
ui->lineEditFormula->setText(ui->lineEditFormula->text().append(val));
}
void DialogEndLine::PutVal(QListWidgetItem *item){
QString val = item->text();
ui->lineEditFormula->setText(ui->lineEditFormula->text().append(val));
}
void DialogEndLine::ValChenged(int row){
if(ui->listWidget->count() == 0){
return;
}
QListWidgetItem *item = ui->listWidget->item( row );
if(ui->radioButtonSizeGrowth->isChecked()){
if(item->text()=="Р"){
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->growth()).arg("Зріст");
ui->labelDescription->setText(desc);
}
if(item->text()=="Сг"){
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg("Розмір");
ui->labelDescription->setText(desc);
}
}
if(ui->radioButtonStandartTable->isChecked()){
VStandartTableCell stable = data->GetStandartTableCell(item->text());
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandartTableCell(item->text()))
.arg(stable.GetDescription());
ui->labelDescription->setText(desc);
}
if(ui->radioButtonIncrements->isChecked()){
VIncrementTableRow itable = data->GetIncrementTableRow(item->text());
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text()))
.arg(itable.getDescription());
ui->labelDescription->setText(desc);
}
}
void DialogEndLine::ClickedToolButtonEqual(){
if(ui->lineEditFormula->text().isEmpty()){
flagFormula = false;
} else {
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(ui->lineEditFormula->text(),&errorMsg);
if(!errorMsg.isEmpty()){
ui->labelResultCalculation->setText("Помилка.");
flagFormula = false;
} else {
ui->labelResultCalculation->setText(QString().setNum(result));
flagFormula = true;
}
}
CheackState();
timerFormula->stop();
}
void DialogEndLine::NameChanged(){
QString name = ui->lineEditNamePoint->text();
if(name.isEmpty() || name.contains(" ")){
flagName = false;
} else {
flagName = true;
}
CheackState();
}
void DialogEndLine::FormulaChanged(){
if(ui->lineEditFormula->text().isEmpty()){
flagFormula = false;
CheackState();
return;
}
timerFormula->start(1000);
}
void DialogEndLine::DialogAccepted(){
pointName = ui->lineEditNamePoint->text();
if(ui->comboBoxLineType->currentText()=="Лінія"){
typeLine = QString("hair");
} else {
typeLine = QString("none");
}
formula = ui->lineEditFormula->text();
angle = ui->spinBoxAngle->value();
qint32 index = ui->comboBoxBasePoint->currentIndex();
basePointId = qvariant_cast<qint64>(ui->comboBoxBasePoint->itemData(index));
DialogClosed(QDialog::Accepted);
}
void DialogEndLine::UpdateList(){
if(ui->radioButtonSizeGrowth->isChecked()){
ShowBase();
}
if(ui->radioButtonStandartTable->isChecked()){
ShowStandartTable();
}
if(ui->radioButtonIncrements->isChecked()){
ShowIncrementTable();
}
}
DialogEndLine::~DialogEndLine()
{
delete ui;
}

84
dialogs/dialogendline.h Normal file
View File

@ -0,0 +1,84 @@
#ifndef DIALOGENDLINE_H
#define DIALOGENDLINE_H
#include <QDialog>
#include <QPushButton>
#include <QListWidgetItem>
#include <QTimer>
#include "../options.h"
#include "../container/vcontainer.h"
#include "../container/calculator.h"
namespace Ui {
class DialogEndLine;
}
class DialogEndLine : public QDialog
{
Q_OBJECT
public:
explicit DialogEndLine(const VContainer *data, QWidget *parent = 0);
~DialogEndLine();
QString getPointName() const;
void setPointName(const QString &value);
QString getTypeLine() const;
void setTypeLine(const QString &value);
QString getFormula() const;
void setFormula(const QString &value);
qint32 getAngle() const;
void setAngle(const qint32 &value);
qint64 getBasePointId() const;
void setBasePointId(const qint64 &value);
signals:
void DialogClosed(int result);
public slots:
void ChoosedPoint(qint64 id, Scene::Type type);
void ArrowUp();
void ArrowDown();
void ArrowLeft();
void ArrowRight();
void ArrowLeftUp();
void ArrowLeftDown();
void ArrowRightUp();
void ArrowRightDown();
void ClickedSizeGrowth();
void ClickedStandartTable();
void ClickedLengthLines();
void ClickedIncrements();
void ClickedToolButtonPutHere();
void PutVal(QListWidgetItem * item);
void ValChenged(int row);
void ClickedToolButtonEqual();
void NameChanged();
void FormulaChanged();
void DialogAccepted();
void UpdateList();
protected:
void closeEvent ( QCloseEvent * event );
private:
Ui::DialogEndLine *ui;
const VContainer *data;
QPushButton *bOk;
QTimer *timerFormula;
bool flagFormula;
bool flagName;
QString pointName;
QString typeLine;
QString formula;
qint32 angle;
qint64 basePointId;
void FillComboBoxBasePoint();
void ShowBase();
void ShowStandartTable();
void ShowIncrementTable();
void ShowLengthLines();
void CheackState();
};
#endif // DIALOGENDLINE_H

487
dialogs/dialogendline.ui Normal file
View File

@ -0,0 +1,487 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogEndLine</class>
<widget class="QDialog" name="DialogEndLine">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>539</width>
<height>559</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Відстань</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditFormula">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonEqual">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/equal.png</normaloff>:/icon/24x24/equal.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelResultCalculation">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>87</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>_</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Базова точка</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxBasePoint"/>
</item>
<item>
<widget class="QToolButton" name="toolButtonPutHere">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/putHere.png</normaloff>:/icon/24x24/putHere.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Ім'я нової точки</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditNamePoint"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Кут градуси</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="horizontalSpacing">
<number>29</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="2">
<widget class="QToolButton" name="toolButtonArrowRightUp">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowRightUp.png</normaloff>:/icon/24x24/arrowRightUp.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonArrowLeftUp">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowLeftUp.png</normaloff>:/icon/24x24/arrowLeftUp.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="toolButtonArrowLeft">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowLeft.png</normaloff>:/icon/24x24/arrowLeft.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="toolButtonArrowRight">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowRight.png</normaloff>:/icon/24x24/arrowRight.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="toolButtonArrowUp">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowUp.png</normaloff>:/icon/24x24/arrowUp.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QToolButton" name="toolButtonArrowDown">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowDown.png</normaloff>:/icon/24x24/arrowDown.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QToolButton" name="toolButtonArrowLeftDown">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowLeftDown.png</normaloff>:/icon/24x24/arrowLeftDown.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="toolButtonArrowRightDown">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icon.qrc">
<normaloff>:/icon/24x24/arrowRightDown.png</normaloff>:/icon/24x24/arrowRightDown.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxAngle">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>52</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>360</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Тип лінії</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLineType"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Вихідні данні</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonSizeGrowth">
<property name="text">
<string>Розмір і зріст</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonStandartTable">
<property name="text">
<string>Стандартна таблиця</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonIncrements">
<property name="text">
<string>Прибавки</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonLengthLine">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Довжини ліній</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonLengthArc">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Довжини дуг</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonLengthSpline">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Довжини сплайні</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelDescription">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../icon.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogEndLine</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>DialogEndLine</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>

View File

@ -12,24 +12,9 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget
ui->setupUi(this); ui->setupUi(this);
this->data = data; this->data = data;
this->doc = doc; this->doc = doc;
ui->tableWidgetStandart->resizeColumnsToContents(); InitialStandartTable();
ui->tableWidgetStandart->resizeRowsToContents(); InitialIncrementTable();
ui->tableWidgetStandart->verticalHeader()->setDefaultSectionSize(20); InitialLinesTable();
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("Опис"));
SpinBoxDelegate *delegate = new SpinBoxDelegate(ui->tableWidgetIncrement); SpinBoxDelegate *delegate = new SpinBoxDelegate(ui->tableWidgetIncrement);
DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(2, delegate); ui->tableWidgetIncrement->setItemDelegateForColumn(2, delegate);
@ -37,6 +22,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget
ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate); ui->tableWidgetIncrement->setItemDelegateForColumn(4, doubleDelegate);
FillStandartTable(); FillStandartTable();
FillIncrementTable(); FillIncrementTable();
FillLengthLines();
connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd);
connect(ui->toolButtonRemove, &QPushButton::clicked, this, connect(ui->toolButtonRemove, &QPushButton::clicked, this,
@ -52,35 +38,124 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget
} }
void DialogIncrements::FillStandartTable(){ void DialogIncrements::FillStandartTable(){
data->FillStandartTable(ui->tableWidgetStandart); const QMap<QString, VStandartTableCell> *standartTable = data->DataStandartTable();
qint32 currentRow = -1;
QMapIterator<QString, VStandartTableCell> i(*standartTable);
while (i.hasNext()) {
i.next();
VStandartTableCell cell = i.value();
currentRow++;
ui->tableWidgetStandart->setRowCount ( standartTable->size() );
QTableWidgetItem *item = new QTableWidgetItem(QString(i.key()));
item->setTextAlignment(Qt::AlignHCenter);
item->setFont(QFont("Times", 12, QFont::Bold));
ui->tableWidgetStandart->setItem(currentRow, 0, item);
item = new QTableWidgetItem(QString().setNum(data->GetValueStandartTableCell(i.key())));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetStandart->setItem(currentRow, 1, item);
item = new QTableWidgetItem(QString().setNum(cell.GetBase()));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetStandart->setItem(currentRow, 2, item);
item = new QTableWidgetItem(QString().setNum(cell.GetKsize()));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetStandart->setItem(currentRow, 3, item);
item = new QTableWidgetItem(QString().setNum(cell.GetKgrowth()));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetStandart->setItem(currentRow, 4, item);
item = new QTableWidgetItem(cell.GetDescription());
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetStandart->setItem(currentRow, 5, item);
}
} }
void DialogIncrements::FillIncrementTable(){ void DialogIncrements::FillIncrementTable(){
data->FillIncrementTable(ui->tableWidgetIncrement); const QMap<QString, VIncrementTableRow> *incrementTable = data->DataIncrementTable();
qint32 currentRow = -1;
QMapIterator<QString, VIncrementTableRow> i(*incrementTable);
while (i.hasNext()) {
i.next();
VIncrementTableRow cell = i.value();
currentRow++;
ui->tableWidgetIncrement->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());
ui->tableWidgetIncrement->setItem(currentRow, 0, item);
item = new QTableWidgetItem(QString().setNum(data->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);
ui->tableWidgetIncrement->setItem(currentRow, 1, item);
item = new QTableWidgetItem(QString().setNum(cell.getBase()));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetIncrement->setItem(currentRow, 2, item);
item = new QTableWidgetItem(QString().setNum(cell.getKsize()));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetIncrement->setItem(currentRow, 3, item);
item = new QTableWidgetItem(QString().setNum(cell.getKgrowth()));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetIncrement->setItem(currentRow, 4, item);
item = new QTableWidgetItem(cell.getDescription());
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetIncrement->setItem(currentRow, 5, item);
}
if(ui->tableWidgetIncrement->rowCount()>0){ if(ui->tableWidgetIncrement->rowCount()>0){
ui->toolButtonRemove->setEnabled(true); ui->toolButtonRemove->setEnabled(true);
} }
} }
void DialogIncrements::FillLengthLines(){
const QMap<QString, qreal> *linesTable = data->DataLengthLines();
qint32 currentRow = -1;
QMapIterator<QString, qreal> i(*linesTable);
while (i.hasNext()) {
i.next();
qreal length = i.value();
currentRow++;
ui->tableWidgetLines->setRowCount ( linesTable->size() );
QTableWidgetItem *item = new QTableWidgetItem(QString(i.key()));
item->setTextAlignment(Qt::AlignHCenter);
item->setFont(QFont("Times", 12, QFont::Bold));
ui->tableWidgetLines->setItem(currentRow, 0, item);
item = new QTableWidgetItem(QString().setNum(length));
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetLines->setItem(currentRow, 1, item);
}
}
void DialogIncrements::FullUpdateFromFile(){ void DialogIncrements::FullUpdateFromFile(){
disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this,
&DialogIncrements::cellChanged); &DialogIncrements::cellChanged);
ui->tableWidgetStandart->clear(); ui->tableWidgetStandart->clear();
ui->tableWidgetStandart->setHorizontalHeaderItem(0, new QTableWidgetItem("Позначення")); InitialStandartTable();
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(); FillStandartTable();
ui->tableWidgetIncrement->clear();
InitialIncrementTable();
FillIncrementTable(); FillIncrementTable();
ui->tableWidgetLines->clear();
InitialLinesTable();
FillLengthLines();
connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this,
&DialogIncrements::cellChanged); &DialogIncrements::cellChanged);
} }
@ -265,6 +340,38 @@ void DialogIncrements::closeEvent ( QCloseEvent * event ){
event->accept(); event->accept();
} }
void DialogIncrements::InitialStandartTable(){
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("Опис"));
}
void DialogIncrements::InitialIncrementTable(){
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("Опис"));
}
void DialogIncrements::InitialLinesTable(){
ui->tableWidgetLines->resizeColumnsToContents();
ui->tableWidgetLines->resizeRowsToContents();
ui->tableWidgetLines->verticalHeader()->setDefaultSectionSize(20);
ui->tableWidgetLines->setHorizontalHeaderItem(0, new QTableWidgetItem("Лінія"));
ui->tableWidgetLines->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина"));
}
void DialogIncrements::clickedButtonOk(){ void DialogIncrements::clickedButtonOk(){
emit closedActionTable(); emit closedActionTable();
} }

View File

@ -34,8 +34,12 @@ private:
Ui::DialogIncrements *ui; Ui::DialogIncrements *ui;
VContainer *data; VContainer *data;
VDomDocument *doc; VDomDocument *doc;
void InitialStandartTable();
void InitialIncrementTable();
void InitialLinesTable();
void FillStandartTable(); void FillStandartTable();
void FillIncrementTable(); void FillIncrementTable();
void FillLengthLines();
void AddIncrementToFile(quint64 id, QString name, qint32 base, qreal ksize, qreal kgrowth, void AddIncrementToFile(quint64 id, QString name, qint32 base, qreal ksize, qreal kgrowth,
QString description); QString description);
}; };

View File

@ -20,7 +20,7 @@
<enum>QTabWidget::North</enum> <enum>QTabWidget::North</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>4</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="tabStandart"> <widget class="QWidget" name="tabStandart">
<attribute name="title"> <attribute name="title">
@ -209,7 +209,7 @@
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTableWidget" name="tableWidget"> <widget class="QTableWidget" name="tableWidgetLines">
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>

View File

@ -8,5 +8,16 @@
<file>icon/32x32/new_draw.png</file> <file>icon/32x32/new_draw.png</file>
<file>icon/32x32/option_draw.png</file> <file>icon/32x32/option_draw.png</file>
<file>icon/32x32/table.png</file> <file>icon/32x32/table.png</file>
<file>icon/24x24/putHere.png</file>
<file>icon/24x24/arrowDown.png</file>
<file>icon/24x24/arrowUp.png</file>
<file>icon/24x24/arrowRightUp.png</file>
<file>icon/24x24/arrowRightDown.png</file>
<file>icon/24x24/arrowRight.png</file>
<file>icon/24x24/arrowLeftUp.png</file>
<file>icon/24x24/arrowLeftDown.png</file>
<file>icon/24x24/arrowLeft.png</file>
<file>icon/24x24/equal.png</file>
<file>icon/32x32/segment.png</file>
</qresource> </qresource>
</RCC> </RCC>

BIN
icon/24x24/arrowDown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

BIN
icon/24x24/arrowLeft.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B

BIN
icon/24x24/arrowLeftUp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

BIN
icon/24x24/arrowRight.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

BIN
icon/24x24/arrowRightUp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

BIN
icon/24x24/arrowUp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

BIN
icon/24x24/equal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

BIN
icon/24x24/putHere.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
icon/32x32/segment.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

View File

@ -2,8 +2,30 @@
#include <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
int main(int argc, char *argv[]) void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){
{ QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
context.function);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
context.function);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line,
context.function);
abort();
}
}
int main(int argc, char *argv[]){
qInstallMessageHandler(myMessageOutput);
QApplication app(argc, argv); QApplication app(argc, argv);
MainWindow w; MainWindow w;
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png")); app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));

View File

@ -8,8 +8,10 @@
#include <QDebug> #include <QDebug>
#include <QInputDialog> #include <QInputDialog>
#include <QFileDialog> #include <QFileDialog>
#include <QDebug>
#include "options.h" #include "options.h"
#include "tools/vtoolendline.h"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow) QMainWindow(parent), ui(new Ui::MainWindow)
@ -25,20 +27,22 @@ MainWindow::MainWindow(QWidget *parent) :
connect(scene, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); connect(scene, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
connect(ui->toolButtonSinglePoint, &QToolButton::clicked, this, connect(ui->toolButtonSinglePoint, &QToolButton::clicked, this,
&MainWindow::clickedToolButtonSinglePoint); &MainWindow::ToolSinglePoint);
helpLabel = new QLabel("Створіть новий файл для початку роботи."); helpLabel = new QLabel("Створіть новий файл для початку роботи.");
ui->statusBar->addWidget(helpLabel); ui->statusBar->addWidget(helpLabel);
connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::triggeredActionAroowTool); connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::ActionAroowTool);
connect(ui->actionDraw, &QAction::triggered, this, &MainWindow::triggeredActionDraw); connect(ui->actionDraw, &QAction::triggered, this, &MainWindow::ActionDraw);
connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::triggeredActionDetails); connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::ActionDetails);
connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::triggeredActionNewDraw); connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::ActionNewDraw);
connect(ui->actionOptionDraw, &QAction::triggered, this, &MainWindow::triggeredOptionDraw); connect(ui->actionOptionDraw, &QAction::triggered, this, &MainWindow::OptionDraw);
connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::triggeredActionSaveAs); connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::ActionSaveAs);
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::triggeredActionSave); connect(ui->actionSave, &QAction::triggered, this, &MainWindow::ActionSave);
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::triggeredActionOpen); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::ActionOpen);
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::triggeredActionNew); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::ActionNew);
connect(ui->actionTable, &QAction::triggered, this, &MainWindow::triggeredActionTable); connect(ui->actionTable, &QAction::triggered, this, &MainWindow::ActionTable);
connect(ui->toolButtonEndLine, &QToolButton::clicked, this,
&MainWindow::ToolEndLine);
data = new VContainer; data = new VContainer;
CreateManTableIGroup (); CreateManTableIGroup ();
@ -49,9 +53,10 @@ MainWindow::MainWindow(QWidget *parent) :
fileName.clear(); fileName.clear();
changeInFile = false; changeInFile = false;
} }
void MainWindow::triggeredActionNewDraw(){ void MainWindow::ActionNewDraw(){
QString nameDraw; QString nameDraw;
bool bOk; bool bOk;
qint32 index; qint32 index;
@ -90,9 +95,10 @@ void MainWindow::triggeredActionNewDraw(){
comboBoxDraws->setCurrentIndex(index); comboBoxDraws->setCurrentIndex(index);
} }
SetEnableWidgets(true); SetEnableWidgets(true);
SetEnableTool(false);
} }
void MainWindow::triggeredOptionDraw(){ void MainWindow::OptionDraw(){
QString nameDraw; QString nameDraw;
bool bOk; bool bOk;
qint32 index; qint32 index;
@ -128,7 +134,7 @@ void MainWindow::triggeredOptionDraw(){
/* /*
* Інструмет базова точка креслення. * Інструмет базова точка креслення.
*/ */
void MainWindow::clickedToolButtonSinglePoint(bool checked){ void MainWindow::ToolSinglePoint(bool checked){
if(checked){ if(checked){
CanselTool(); CanselTool();
tool = Tools::SinglePointTool; tool = Tools::SinglePointTool;
@ -149,6 +155,52 @@ void MainWindow::clickedToolButtonSinglePoint(bool checked){
} }
} }
void MainWindow::ToolEndLine(bool checked){
if(checked){
CanselTool();
tool = Tools::EndLineTool;
QPixmap pixmap(":/cursor/endline_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Заповніть усі поля.");
dialogEndLine = new DialogEndLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogEndLine,
&DialogEndLine::ChoosedPoint);
connect(dialogEndLine, &DialogEndLine::DialogClosed, this,
&MainWindow::ClosedDialogEndLine);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine, &DialogEndLine::UpdateList);
} else {
ui->toolButtonEndLine->setChecked(true);
}
}
void MainWindow::ClosedDialogEndLine(int result){
if(result == QDialog::Accepted){
QString pointName = dialogEndLine->getPointName();
QString typeLine = dialogEndLine->getTypeLine();
QString formula = dialogEndLine->getFormula();
qint32 angle = dialogEndLine->getAngle();
qint64 basePointId = dialogEndLine->getBasePointId();
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
line.setAngle(angle);
qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10));
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, basePointId,
Tool::FromGui);
scene->addItem(point);
connect(point, &VToolPoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
void MainWindow::showEvent( QShowEvent *event ){ void MainWindow::showEvent( QShowEvent *event ){
QMainWindow::showEvent( event ); QMainWindow::showEvent( event );
if( event->spontaneous() ){ if( event->spontaneous() ){
@ -230,6 +282,11 @@ void MainWindow::currentDrawChanged( int index ){
if(index != -1) { if(index != -1) {
bool status = qvariant_cast<bool>(comboBoxDraws->itemData(index)); bool status = qvariant_cast<bool>(comboBoxDraws->itemData(index));
ui->toolButtonSinglePoint->setEnabled(status); ui->toolButtonSinglePoint->setEnabled(status);
if(ui->toolButtonSinglePoint->isEnabled()==false){
SetEnableTool(true);
} else {
SetEnableTool(false);
}
doc->ChangeActivDraw(comboBoxDraws->itemText(index)); doc->ChangeActivDraw(comboBoxDraws->itemText(index));
} }
} }
@ -252,6 +309,11 @@ void MainWindow::CanselTool(){
delete dialogSinglePoint; delete dialogSinglePoint;
ui->toolButtonSinglePoint->setChecked(false); ui->toolButtonSinglePoint->setChecked(false);
break; break;
case Tools::EndLineTool:
delete dialogEndLine;
ui->toolButtonEndLine->setChecked(false);
scene->clearSelection();
break;
} }
} }
@ -264,7 +326,7 @@ void MainWindow::ArrowTool(){
helpLabel->setText(""); helpLabel->setText("");
} }
void MainWindow::triggeredActionAroowTool(){ void MainWindow::ActionAroowTool(){
ArrowTool(); ArrowTool();
} }
@ -285,14 +347,16 @@ void MainWindow::SinglePointCreated(const QString name, const QPointF point){
qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10)); qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10));
VToolSimplePoint *spoint = new VToolSimplePoint(doc, data, id, Tool::FromGui); VToolSimplePoint *spoint = new VToolSimplePoint(doc, data, id, Tool::FromGui);
scene->addItem(spoint); scene->addItem(spoint);
connect(spoint, &VToolPoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
ArrowTool(); ArrowTool();
ui->toolButtonSinglePoint->setEnabled(false); ui->toolButtonSinglePoint->setEnabled(false);
qint32 index = comboBoxDraws->currentIndex(); qint32 index = comboBoxDraws->currentIndex();
comboBoxDraws->setItemData(index, false); comboBoxDraws->setItemData(index, false);
ui->actionSave->setEnabled(true); ui->actionSave->setEnabled(true);
SetEnableTool(true);
} }
void MainWindow::triggeredActionDraw(bool checked){ void MainWindow::ActionDraw(bool checked){
if(checked){ if(checked){
ui->actionDetails->setChecked(false); ui->actionDetails->setChecked(false);
} else { } else {
@ -300,7 +364,7 @@ void MainWindow::triggeredActionDraw(bool checked){
} }
} }
void MainWindow::triggeredActionDetails(bool checked){ void MainWindow::ActionDetails(bool checked){
if(checked){ if(checked){
ui->actionDraw->setChecked(false); ui->actionDraw->setChecked(false);
} else { } else {
@ -308,7 +372,7 @@ void MainWindow::triggeredActionDetails(bool checked){
} }
} }
void MainWindow::triggeredActionSaveAs(){ void MainWindow::ActionSaveAs(){
QString filters("Lekalo files (*.xml);;All files (*.*)"); QString filters("Lekalo files (*.xml);;All files (*.*)");
QString defaultFilter("Lekalo files (*.xml)"); QString defaultFilter("Lekalo files (*.xml)");
QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(), QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(),
@ -333,7 +397,7 @@ void MainWindow::triggeredActionSaveAs(){
changeInFile = false; changeInFile = false;
} }
void MainWindow::triggeredActionSave(){ void MainWindow::ActionSave(){
if(!fileName.isEmpty()){ if(!fileName.isEmpty()){
QFile file(fileName); QFile file(fileName);
if(file.open(QIODevice::WriteOnly| QIODevice::Truncate)){ if(file.open(QIODevice::WriteOnly| QIODevice::Truncate)){
@ -347,7 +411,7 @@ void MainWindow::triggeredActionSave(){
} }
} }
void MainWindow::triggeredActionOpen(){ void MainWindow::ActionOpen(){
QString filter("Lekalo files (*.xml)"); QString filter("Lekalo files (*.xml)");
QString fName = QFileDialog::getOpenFileName(this, tr("Відкрити файл"), QDir::homePath(), filter); QString fName = QFileDialog::getOpenFileName(this, tr("Відкрити файл"), QDir::homePath(), filter);
fileName = fName; fileName = fName;
@ -377,9 +441,14 @@ void MainWindow::triggeredActionOpen(){
} }
file.close(); file.close();
} }
if(ui->toolButtonSinglePoint->isEnabled()==false){
SetEnableTool(true);
} else {
SetEnableTool(false);
}
} }
void MainWindow::triggeredActionNew(){ void MainWindow::ActionNew(){
setWindowTitle("Valentina"); setWindowTitle("Valentina");
data->Clear(); data->Clear();
doc->clear(); doc->clear();
@ -390,6 +459,7 @@ void MainWindow::triggeredActionNew(){
ui->toolButtonSinglePoint->setEnabled(true); ui->toolButtonSinglePoint->setEnabled(true);
ui->actionOptionDraw->setEnabled(false); ui->actionOptionDraw->setEnabled(false);
ui->actionSave->setEnabled(false); ui->actionSave->setEnabled(false);
SetEnableTool(false);
} }
void MainWindow::haveChange(){ void MainWindow::haveChange(){
@ -474,15 +544,17 @@ void MainWindow::SetEnableWidgets(bool enable){
ui->actionDetails->setEnabled(enable); ui->actionDetails->setEnabled(enable);
ui->toolButtonSinglePoint->setEnabled(enable); ui->toolButtonSinglePoint->setEnabled(enable);
ui->actionOptionDraw->setEnabled(enable); ui->actionOptionDraw->setEnabled(enable);
ui->actionSave->setEnabled(enable); if(enable == true && !fileName.isEmpty()){
ui->actionSave->setEnabled(enable);
}
ui->actionTable->setEnabled(enable); ui->actionTable->setEnabled(enable);
} }
void MainWindow::triggeredActionTable(bool checked){ void MainWindow::ActionTable(bool checked){
if(checked){ if(checked){
dialogTable = new DialogIncrements(data, doc, 0); dialogTable = new DialogIncrements(data, doc, 0);
connect(dialogTable, &DialogIncrements::closedActionTable, this, connect(dialogTable, &DialogIncrements::closedActionTable, this,
&MainWindow::closedActionTable); &MainWindow::ClosedActionTable);
dialogTable->show(); dialogTable->show();
} else { } else {
ui->actionTable->setChecked(true); ui->actionTable->setChecked(true);
@ -490,7 +562,7 @@ void MainWindow::triggeredActionTable(bool checked){
} }
} }
void MainWindow::closedActionTable(){ void MainWindow::ClosedActionTable(){
ui->actionTable->setChecked(false); ui->actionTable->setChecked(false);
delete dialogTable; delete dialogTable;
} }
@ -502,6 +574,10 @@ void MainWindow::closeEvent ( QCloseEvent * event ){
event->accept(); event->accept();
} }
void MainWindow::SetEnableTool(bool enable){
ui->toolButtonEndLine->setEnabled(enable);
}
MainWindow::~MainWindow(){ MainWindow::~MainWindow(){
CanselTool(); CanselTool();
delete ui; delete ui;

View File

@ -12,6 +12,7 @@
#include "tools/vtoolsimplepoint.h" #include "tools/vtoolsimplepoint.h"
#include "xml/vdomdocument.h" #include "xml/vdomdocument.h"
#include "container/vcontainer.h" #include "container/vcontainer.h"
#include "dialogs/dialogendline.h"
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
@ -21,7 +22,8 @@ namespace Tools{
enum Enum enum Enum
{ {
ArrowTool, ArrowTool,
SinglePointTool SinglePointTool,
EndLineTool
}; };
} }
@ -33,24 +35,26 @@ public:
~MainWindow(); ~MainWindow();
public slots: public slots:
void mouseMove(QPointF scenePos); void mouseMove(QPointF scenePos);
void clickedToolButtonSinglePoint(bool checked); void ToolSinglePoint(bool checked);
void triggeredActionAroowTool(); void ActionAroowTool();
void triggeredActionDraw(bool checked); void ActionDraw(bool checked);
void triggeredActionDetails(bool checked); void ActionDetails(bool checked);
void ToolCanseled(); void ToolCanseled();
void SinglePointCreated(const QString name, const QPointF point); void SinglePointCreated(const QString name, const QPointF point);
void triggeredActionNewDraw(); void ActionNewDraw();
void currentDrawChanged( int index ); void currentDrawChanged( int index );
void triggeredOptionDraw(); void OptionDraw();
void triggeredActionSaveAs(); void ActionSaveAs();
void triggeredActionSave(); void ActionSave();
void triggeredActionOpen(); void ActionOpen();
void triggeredActionNew(); void ActionNew();
void haveChange(); void haveChange();
void ChangedSize(const QString &text); void ChangedSize(const QString &text);
void ChangedGrowth(const QString & text); void ChangedGrowth(const QString & text);
void triggeredActionTable(bool checked); void ActionTable(bool checked);
void closedActionTable(); void ClosedActionTable();
void ToolEndLine(bool checked);
void ClosedDialogEndLine(int result);
protected: protected:
virtual void keyPressEvent ( QKeyEvent * event ); virtual void keyPressEvent ( QKeyEvent * event );
virtual void showEvent( QShowEvent *event ); virtual void showEvent( QShowEvent *event );
@ -64,6 +68,7 @@ private:
bool isInitialized; bool isInitialized;
DialogSinglePoint *dialogSinglePoint; DialogSinglePoint *dialogSinglePoint;
DialogIncrements *dialogTable; DialogIncrements *dialogTable;
DialogEndLine *dialogEndLine;
VDomDocument *doc; VDomDocument *doc;
VContainer *data; VContainer *data;
QComboBox *comboBoxDraws; QComboBox *comboBoxDraws;
@ -75,6 +80,7 @@ private:
void ArrowTool(); void ArrowTool();
void CreateManTableIGroup () const; void CreateManTableIGroup () const;
void SetEnableWidgets(bool enable); void SetEnableWidgets(bool enable);
void SetEnableTool(bool enable);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -51,7 +51,7 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QToolBox" name="toolBox"> <widget class="QToolBox" name="toolBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -86,10 +86,26 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QToolButton" name="toolButton_2"> <widget class="QToolButton" name="toolButtonEndLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
</property> </property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/segment.png</normaloff>:/icon/32x32/segment.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="2">

View File

@ -6,4 +6,14 @@
#define WidthMainLine 0.8*PrintDPI/25.4 #define WidthMainLine 0.8*PrintDPI/25.4
#define widthHairLine WidthMainLine/3 #define widthHairLine WidthMainLine/3
namespace Scene{
enum Type
{
Point,
Line,
Spline,
Arc
};
}
#endif // OPTIONS_H #endif // OPTIONS_H

152
tools/vtoolendline.cpp Normal file
View File

@ -0,0 +1,152 @@
#include "vtoolendline.h"
#include <QDebug>
#include <QMenu>
#include "../widgets/vmaingraphicsscene.h"
VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula, const qint32 &angle,
const qint64 &basePointId, Tool::Enum typeCreation,
QGraphicsItem *parent):VToolPoint(doc, data, id, parent){
ignoreContextMenuEvent = false;//don't ignore context menu events;
connect(this, &VToolEndLine::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
this->typeLine = typeLine;
this->formula = formula;
this->angle = angle;
this->basePointId = basePointId;
//Лінія, що з'єднує дві точки
VPointF basePoint = data->GetPoint(basePointId);
VPointF point = data->GetPoint(id);
mainLine = new QGraphicsLineItem(QLineF(basePoint.toQPointF(), point.toQPointF()), this);
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
QString nameLine = GetNameLine(basePointId, id);
QLineF line = QLineF(basePoint.toQPointF(), point.toQPointF());
data->AddLine(nameLine, line.length());
if(typeCreation == Tool::FromGui){
AddToFile();
}
}
void VToolEndLine::FullUpdateFromFile(){
QString name;
qreal mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
basePointId = domElement.attribute("basePoint", "").toLongLong();
angle = domElement.attribute("angle", "").toInt();
}
VPointF point = data->GetPoint(id);
RefreshBaseGeometry(name, point.x(), point.y(), mx, my);
VPointF basePoint = data->GetPoint(basePointId);
mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF()));
QString nameLine = GetNameLine(basePointId, id);
QLineF line = QLineF(basePoint.toQPointF(), point.toQPointF());
data->AddLine(nameLine, line.length());
}
void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogEndLine = QSharedPointer<DialogEndLine>(new DialogEndLine(data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogEndLine.data(), &DialogEndLine::ChoosedPoint);
connect(dialogEndLine.data(), &DialogEndLine::DialogClosed, this, &VToolEndLine::ClosedDialogEndLine);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine.data(), &DialogEndLine::UpdateList);
VPointF p = data->GetPoint(id);
dialogEndLine->setTypeLine(typeLine);
dialogEndLine->setFormula(formula);
dialogEndLine->setAngle(angle);
dialogEndLine->setBasePointId(basePointId);
dialogEndLine->setPointName(p.name());
dialogEndLine->show();
}
}
}
void VToolEndLine::ClosedDialogEndLine(int result){
if(result == QDialog::Accepted){
QString pointName = dialogEndLine->getPointName();
QString typeLine = dialogEndLine->getTypeLine();
QString formula = dialogEndLine->getFormula();
qint32 angle = dialogEndLine->getAngle();
qint64 basePointId = dialogEndLine->getBasePointId();
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result/PrintDPI*25.4);
line.setAngle(angle);
FullUpdateFromGui(pointName, typeLine, formula, angle, basePointId);
}
}
dialogEndLine.clear();
}
void VToolEndLine::AddToFile(){
VPointF point = data->GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
AddAttribute(domElement, "type", "endLine");
AddAttribute(domElement, "name", point.name());
AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4);
AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
AddAttribute(domElement, "typeLine", typeLine);
AddAttribute(domElement, "length", formula);
AddAttribute(domElement, "angle", angle);
AddAttribute(domElement, "basePoint", basePointId);
QDomElement calcElement;
bool ok = doc->GetActivCalculationElement(calcElement);
if(ok){
calcElement.appendChild(domElement);
} else {
qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO;
}
}
void VToolEndLine::FullUpdateFromGui(const QString &name, const QString &typeLine, const QString &formula,
const qreal &angle, const qint64 &basePointId){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
this->typeLine = typeLine;
this->formula = formula;
this->angle = angle;
this->basePointId = basePointId;
domElement.setAttribute("name", name);
domElement.setAttribute("typeLine", typeLine);
domElement.setAttribute("length", formula);
domElement.setAttribute("angle", QString().setNum(angle));
domElement.setAttribute("basePoint", QString().setNum(basePointId));
emit FullUpdateTree();
}
}

34
tools/vtoolendline.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef VTOOLENDLINE_H
#define VTOOLENDLINE_H
#include <QSharedPointer>
#include "vtoolpoint.h"
#include "../dialogs/dialogendline.h"
class VToolEndLine : public VToolPoint
{
Q_OBJECT
public:
VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula, const qint32 &angle,
const qint64 &basePointId, Tool::Enum typeCreation,
QGraphicsItem * parent = 0);
public slots:
virtual void FullUpdateFromFile();
void ClosedDialogEndLine(int result);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
QString typeLine;
QString formula;
qint32 angle;
qint64 basePointId;
QGraphicsLineItem *mainLine;
QSharedPointer<DialogEndLine> dialogEndLine;
void FullUpdateFromGui(const QString &name, const QString &typeLine, const QString &formula,
const qreal &angle, const qint64 &basePointId);
};
#endif // VTOOLENDLINE_H

View File

@ -5,8 +5,8 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include <cmath> #include <cmath>
#include "../options.h"
#include "../container/vpointf.h" #include "../container/vpointf.h"
#include "../widgets/vmaingraphicsscene.h"
VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id,
QGraphicsItem *parent):QGraphicsEllipseItem(parent){ QGraphicsItem *parent):QGraphicsEllipseItem(parent){
@ -56,7 +56,7 @@ void VToolPoint::NameChangePosition(const QPointF pos){
point.setMx(pos.x() - rec.center().x()); point.setMx(pos.x() - rec.center().x());
point.setMy(pos.y() - rec.center().y()); point.setMy(pos.y() - rec.center().y());
RefreshLine(); RefreshLine();
LiteUpdateFromGui(point.name(), point.mx(), point.my()); LiteUpdateFromGui(point.mx(), point.my());
data->UpdatePoint(id, point); data->UpdatePoint(id, point);
} }
@ -158,10 +158,9 @@ void VToolPoint::RefreshLine(){
} }
} }
void VToolPoint::LiteUpdateFromGui(const QString& name, qreal mx, qreal my){ void VToolPoint::LiteUpdateFromGui(qreal mx, qreal my){
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){ if(domElement.isElement()){
domElement.setAttribute("name", name);
domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4)); domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4));
domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4)); domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4));
emit haveLiteChange(); emit haveLiteChange();
@ -183,6 +182,7 @@ void VToolPoint::ChangedActivDraw(const QString newName){
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
namePoint->setBrush(QBrush(Qt::black)); namePoint->setBrush(QBrush(Qt::black));
line->setPen(QPen(Qt::black, widthHairLine)); line->setPen(QPen(Qt::black, widthHairLine));
ignoreContextMenuEvent = false;
} else { } else {
this->setPen(QPen(Qt::gray, widthHairLine)); this->setPen(QPen(Qt::gray, widthHairLine));
this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setFlag(QGraphicsItem::ItemIsSelectable, false);
@ -191,5 +191,61 @@ void VToolPoint::ChangedActivDraw(const QString newName){
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
namePoint->setBrush(QBrush(Qt::gray)); namePoint->setBrush(QBrush(Qt::gray));
line->setPen(QPen(Qt::gray, widthHairLine)); line->setPen(QPen(Qt::gray, widthHairLine));
ignoreContextMenuEvent = true;
} }
} }
void VToolPoint::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ){
if(event->button() == Qt::LeftButton){
emit ChoosedPoint(id, Scene::Point);
}
QGraphicsItem::mouseReleaseEvent(event);
}
void VToolPoint::AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(QString().setNum(value));
domElement.setAttributeNode(domAttr);
}
void VToolPoint::AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(QString().setNum(value));
domElement.setAttributeNode(domAttr);
}
void VToolPoint::AddAttribute(QDomElement &domElement, const QString &name, const qreal &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(QString().setNum(value));
domElement.setAttributeNode(domAttr);
}
void VToolPoint::AddAttribute(QDomElement &domElement, const QString &name, const QString &value){
QDomAttr domAttr = doc->createAttribute(name);
domAttr.setValue(value);
domElement.setAttributeNode(domAttr);
}
void VToolPoint::RefreshBaseGeometry(const QString &name, const qreal &x, const qreal &y, const qreal &mx,
const qreal &my){
QRectF rec = QRectF(x, y, radius*2, radius*2);
rec.translate(x-rec.center().x(), y-rec.center().y());
this->setRect(rec);
rec = this->rect();
namePoint->setText(name);
namePoint->setPos(QPointF(rec.center().x()+mx, rec.center().y()+my));
RefreshLine();
}
QString VToolPoint::GetNameLine(qint64 firstPoint, qint64 secondPoint) const{
VPointF first = data->GetPoint(firstPoint);
VPointF second = data->GetPoint(secondPoint);
QString name = QString("Line_%1_%2").arg(first.name(), second.name());
return name;
}
VToolPoint::~VToolPoint(){
}

View File

@ -7,6 +7,7 @@
#include "../widgets/vgraphicssimpletextitem.h" #include "../widgets/vgraphicssimpletextitem.h"
#include "../container/vcontainer.h" #include "../container/vcontainer.h"
#include "../xml/vdomdocument.h" #include "../xml/vdomdocument.h"
#include "../options.h"
namespace Tool{ namespace Tool{
enum Enum enum Enum
@ -21,6 +22,7 @@ class VToolPoint: public QObject, public QGraphicsEllipseItem
Q_OBJECT Q_OBJECT
public: public:
VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0);
virtual ~VToolPoint();
public slots: public slots:
void NameChangePosition(const QPointF pos); void NameChangePosition(const QPointF pos);
virtual void ChangedActivDraw(const QString newName); virtual void ChangedActivDraw(const QString newName);
@ -28,6 +30,8 @@ public slots:
void ChangedNameDraw(const QString oldName, const QString newName); void ChangedNameDraw(const QString oldName, const QString newName);
signals: signals:
void haveLiteChange(); void haveLiteChange();
void ChoosedPoint(qint64 id, Scene::Type type);
void FullUpdateTree();
protected: protected:
qreal radius; qreal radius;
VDomDocument *doc; VDomDocument *doc;
@ -36,15 +40,24 @@ protected:
QGraphicsLineItem *line; QGraphicsLineItem *line;
qint64 id; qint64 id;
QString nameActivDraw; QString nameActivDraw;
bool ignoreContextMenuEvent;
virtual void AddToFile()=0; virtual void AddToFile()=0;
void RefreshLine(); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
void AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value);
void AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value);
void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value);
void AddAttribute(QDomElement &domElement, const QString &name, const QString &value);
void RefreshBaseGeometry(const QString &name, const qreal &x, const qreal &y,
const qreal &mx, const qreal &my);
QString GetNameLine(qint64 firstPoint, qint64 secondPoint) const;
private: private:
qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1,
QPointF &p2) const; QPointF &p2) const;
QPointF LineIntersectRect(QRectF rec, QLineF line) const; QPointF LineIntersectRect(QRectF rec, QLineF line) const;
QPointF ClosestPoint(QLineF line, QPointF p) const; QPointF ClosestPoint(QLineF line, QPointF p) const;
QPointF add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const; QPointF add_vector (QPointF p, QPointF p1, QPointF p2, qreal k) const;
void LiteUpdateFromGui(const QString& name, qreal mx, qreal my); void LiteUpdateFromGui(qreal mx, qreal my);
void RefreshLine();
}; };
#endif // VTOOLPOINT_H #endif // VTOOLPOINT_H

View File

@ -20,47 +20,17 @@ VToolSimplePoint::VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64
} }
} }
void VToolSimplePoint::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
VToolPoint::ChangedActivDraw(newName);
ignoreContextMenuEvent = false;
} else {
VToolPoint::ChangedActivDraw(newName);
ignoreContextMenuEvent = true;
}
}
void VToolSimplePoint::AddToFile(){ void VToolSimplePoint::AddToFile(){
VPointF point = data->GetPoint(id); VPointF point = data->GetPoint(id);
QDomElement domElement = doc->createElement("point"); QDomElement domElement = doc->createElement("point");
QDomAttr domAttr = doc->createAttribute("id"); AddAttribute(domElement, "id", id);
domAttr.setValue(QString().setNum(id)); AddAttribute(domElement, "type", "simple");
domElement.setAttributeNode(domAttr); AddAttribute(domElement, "name", point.name());
AddAttribute(domElement, "x", point.x()/PrintDPI*25.4);
domAttr = doc->createAttribute("type"); AddAttribute(domElement, "y", point.y()/PrintDPI*25.4);
domAttr.setValue("simple"); AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4);
domElement.setAttributeNode(domAttr); AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
domAttr = doc->createAttribute("name");
domAttr.setValue(point.name());
domElement.setAttributeNode(domAttr);
domAttr = doc->createAttribute("x");
domAttr.setValue(QString().setNum(point.x()/PrintDPI*25.4));
domElement.setAttributeNode(domAttr);
domAttr = doc->createAttribute("y");
domAttr.setValue(QString().setNum(point.y()/PrintDPI*25.4));
domElement.setAttributeNode(domAttr);
domAttr = doc->createAttribute("mx");
domAttr.setValue(QString().setNum(point.mx()/PrintDPI*25.4));
domElement.setAttributeNode(domAttr);
domAttr = doc->createAttribute("my");
domAttr.setValue(QString().setNum(point.my()/PrintDPI*25.4));
domElement.setAttributeNode(domAttr);
QDomElement calcElement; QDomElement calcElement;
bool ok = doc->GetActivCalculationElement(calcElement); bool ok = doc->GetActivCalculationElement(calcElement);
@ -111,13 +81,5 @@ void VToolSimplePoint::FullUpdateFromFile(){
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4; mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4; my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
} }
QRectF rec = QRectF(x, y, radius*2, radius*2); RefreshBaseGeometry(name, x, y, mx, my);
rec.translate(x-rec.center().x(), y-rec.center().y());
this->setRect(rec);
rec = this->rect();
namePoint->setText(name);
namePoint->setPos(QPointF(rec.center().x()+mx, rec.center().y()+my));
RefreshLine();
} }

View File

@ -12,16 +12,11 @@ public:
VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id, VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id,
Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); Tool::Enum typeCreation, QGraphicsItem * parent = 0 );
public slots: public slots:
virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
signals:
void FullUpdateTree();
protected: protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile(); virtual void AddToFile();
private: private:
bool ignoreContextMenuEvent;
void FullUpdateFromGui(const QString& name, qreal x, qreal y); void FullUpdateFromGui(const QString& name, qreal x, qreal y);
}; };

View File

@ -20,3 +20,7 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event){
emit mousePress(event->scenePos()); emit mousePress(event->scenePos());
QGraphicsScene::mousePressEvent(event); QGraphicsScene::mousePressEvent(event);
} }
void VMainGraphicsScene::ChoosedItem(qint64 id, Scene::Type type){
emit ChoosedObject(id, type);
}

View File

@ -4,18 +4,23 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include "../options.h"
class VMainGraphicsScene : public QGraphicsScene class VMainGraphicsScene : public QGraphicsScene
{ {
Q_OBJECT Q_OBJECT
public: public:
VMainGraphicsScene(); VMainGraphicsScene();
VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0); VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0);
public slots:
void ChoosedItem(qint64 id, Scene::Type type);
private: private:
void mouseMoveEvent(QGraphicsSceneMouseEvent* event); void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
signals: signals:
void mouseMove(QPointF scenePos); void mouseMove(QPointF scenePos);
void mousePress(QPointF scenePos); void mousePress(QPointF scenePos);
void ChoosedObject(qint64 id, Scene::Type type);
}; };
#endif // VMAINGRAPHICSSCENE_H #endif // VMAINGRAPHICSSCENE_H

View File

@ -1,9 +1,12 @@
#include "vdomdocument.h" #include "vdomdocument.h"
#include "../tools/vtoolsimplepoint.h"
#include "../options.h"
#include <QDebug> #include <QDebug>
#include "../tools/vtoolsimplepoint.h"
#include "../tools/vtoolendline.h"
#include "../options.h"
#include "../container/calculator.h"
VDomDocument::VDomDocument(VContainer *data) : QDomDocument() { VDomDocument::VDomDocument(VContainer *data) : QDomDocument() {
this->data = data; this->data = data;
} }
@ -214,6 +217,8 @@ void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *scene, QCombo
nameActivDraw.clear(); nameActivDraw.clear();
scene->clear(); scene->clear();
comboBoxDraws->clear(); comboBoxDraws->clear();
} else {
data->ClearLengthLines();
} }
QDomElement rootElement = this->documentElement(); QDomElement rootElement = this->documentElement();
QDomNode domNode = rootElement.firstChild(); QDomNode domNode = rootElement.firstChild();
@ -330,11 +335,6 @@ void VDomDocument::ParseCalculationElement(VMainGraphicsScene *scene, const QDom
if(!domElement.isNull()){ if(!domElement.isNull()){
if(domElement.tagName() == "point"){ if(domElement.tagName() == "point"){
ParsePointElement(scene, domElement, parse, domElement.attribute("type", "")); ParsePointElement(scene, domElement, parse, domElement.attribute("type", ""));
qDebug()<<domElement.tagName()<<"type="<<domElement.attribute("type", "")<<
"id="<<domElement.attribute("id", "")<<"x="<<domElement.attribute("x", "")<<
"y="<<domElement.attribute("y", "")<<"mx="<<domElement.attribute("mx", "")<<
"my="<<domElement.attribute("my", "")<<"name="<<domElement.attribute("name", "");
} }
} }
} }
@ -359,6 +359,43 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
if(parse == Document::FullParse){ if(parse == Document::FullParse){
VToolSimplePoint *spoint = new VToolSimplePoint(this, data, id, Tool::FromFile); VToolSimplePoint *spoint = new VToolSimplePoint(this, data, id, Tool::FromFile);
scene->addItem(spoint); scene->addItem(spoint);
connect(spoint, &VToolSimplePoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
}
}
if(type == "endLine"){
if(!domElement.isNull()){
QString name, typeLine, formula;
qreal mx=5, my=10;
qint64 id, basePointId;
qint32 angle;
if(!domElement.isNull()){
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
basePointId = domElement.attribute("basePoint", "").toLongLong();
angle = domElement.attribute("angle", "").toInt();
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
line.setAngle(angle);
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), name, mx, my));
if(parse == Document::FullParse){
VToolEndLine *point = new VToolEndLine(this, data, id, typeLine, formula, angle,
basePointId, Tool::FromFile);
scene->addItem(point);
connect(point, &VToolPoint::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
} }
} }
} }