Add tool AlongLine.

This commit is contained in:
dismine 2013-07-28 01:18:06 +03:00
parent 7c06d2f689
commit 6879b732cb
38 changed files with 1384 additions and 586 deletions

View File

@ -31,7 +31,10 @@ SOURCES += main.cpp\
tools/vtoolendline.cpp \
tools/vtoolline.cpp \
tools/vabstracttool.cpp \
dialogs/dialogline.cpp
dialogs/dialogline.cpp \
tools/vtoolalongline.cpp \
dialogs/dialogtool.cpp \
dialogs/dialogalongline.cpp
HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \
@ -53,14 +56,26 @@ HEADERS += mainwindow.h \
tools/vtoolendline.h \
tools/vtoolline.h \
tools/vabstracttool.h \
dialogs/dialogline.h
dialogs/dialogline.h \
tools/vtoolalongline.h \
dialogs/dialogtool.h \
dialogs/dialogalongline.h
FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \
dialogs/dialogincrements.ui \
dialogs/dialogendline.ui \
dialogs/dialogline.ui
dialogs/dialogline.ui \
dialogs/dialogalongline.ui
RESOURCES += \
icon.qrc \
cursor.qrc
CONFIG(debug, debug|release){
# Debug
QMAKE_CXXFLAGS += -O0 -Wall -Wextra -pedantic -std=c++0x
}else{
# Release
QMAKE_CXXFLAGS += -O1 -std=c++0x
}

View File

@ -3,5 +3,6 @@
<file>cursor/spoint_cursor.png</file>
<file>cursor/endline_cursor.png</file>
<file>cursor/line_cursor.png</file>
<file>cursor/alongline_cursor.png</file>
</qresource>
</RCC>

BIN
cursor/alongline_cursor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

142
dialogs/dialogalongline.cpp Normal file
View File

@ -0,0 +1,142 @@
#include "dialogalongline.h"
#include "ui_dialogalongline.h"
DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) :
DialogTool(data, parent), ui(new Ui::DialogAlongLine)
{
ui->setupUi(this);
number = 0;
listWidget = ui->listWidget;
labelResultCalculation = ui->labelResultCalculation;
labelDescription = ui->labelDescription;
radioButtonSizeGrowth = ui->radioButtonSizeGrowth;
radioButtonStandartTable = ui->radioButtonStandartTable;
radioButtonIncrements = ui->radioButtonIncrements;
radioButtonLengthLine = ui->radioButtonLengthLine;
lineEditFormula = ui->lineEditFormula;
flagFormula = false;
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogAlongLine::DialogAccepted);
flagName = false;
CheckState();
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogAlongLine::DialogRejected);
FillComboBoxTypeLine(ui->comboBoxLineType);
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere);
connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogAlongLine::PutVal);
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogAlongLine::ValChenged);
ShowBase();
connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogAlongLine::SizeGrowth);
connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogAlongLine::StandartTable);
connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogAlongLine::Increments);
connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogAlongLine::LengthLines);
connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged);
connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogAlongLine::FormulaChanged);
}
DialogAlongLine::~DialogAlongLine()
{
delete ui;
}
void DialogAlongLine::ChoosedPoint(qint64 id, Scene::Type type){
if(type == Scene::Point){
VPointF point = data->GetPoint(id);
if(number == 0){
qint32 index = ui->comboBoxFirstPoint->findText(point.name());
if ( index != -1 ) { // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;
return;
}
}
if(number == 1){
qint32 index = ui->comboBoxSecondPoint->findText(point.name());
if ( index != -1 ) { // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
number = 0;
}
if(!isInitialized){
this->show();
}
}
}
}
void DialogAlongLine::DialogAccepted(){
pointName = ui->lineEditNamePoint->text();
typeLine = GetTypeLine(ui->comboBoxLineType);
formula = ui->lineEditFormula->text();
qint32 index = ui->comboBoxFirstPoint->currentIndex();
firstPointId = qvariant_cast<qint64>(ui->comboBoxFirstPoint->itemData(index));
index = ui->comboBoxSecondPoint->currentIndex();
secondPointId = qvariant_cast<qint64>(ui->comboBoxSecondPoint->itemData(index));
emit DialogClosed(QDialog::Accepted);
}
qint64 DialogAlongLine::getSecondPointId() const{
return secondPointId;
}
void DialogAlongLine::setSecondPointId(const qint64 &value){
secondPointId = value;
qint32 index = ui->comboBoxSecondPoint->findData(secondPointId);
if(index != -1){
ui->comboBoxSecondPoint->setCurrentIndex(index);
}
}
qint64 DialogAlongLine::getFirstPointId() const{
return firstPointId;
}
void DialogAlongLine::setFirstPointId(const qint64 &value){
firstPointId = value;
qint32 index = ui->comboBoxFirstPoint->findData(firstPointId);
if(index != -1){
ui->comboBoxFirstPoint->setCurrentIndex(index);
}
}
QString DialogAlongLine::getFormula() const{
return formula;
}
void DialogAlongLine::setFormula(const QString &value){
formula = value;
ui->lineEditFormula->setText(formula);
}
QString DialogAlongLine::getTypeLine() const{
return typeLine;
}
void DialogAlongLine::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 DialogAlongLine::getPointName() const{
return pointName;
}
void DialogAlongLine::setPointName(const QString &value){
pointName = value;
ui->lineEditNamePoint->setText(pointName);
}

42
dialogs/dialogalongline.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef DIALOGALONGLINE_H
#define DIALOGALONGLINE_H
#include "dialogtool.h"
#include "../options.h"
#include "../container/vcontainer.h"
#include "../container/calculator.h"
namespace Ui {
class DialogAlongLine;
}
class DialogAlongLine : public DialogTool
{
Q_OBJECT
public:
explicit DialogAlongLine(const VContainer *data, QWidget *parent = 0);
~DialogAlongLine();
QString getPointName() const;
void setPointName(const QString &value);
QString getTypeLine() const;
void setTypeLine(const QString &value);
QString getFormula() const;
void setFormula(const QString &value);
qint64 getFirstPointId() const;
void setFirstPointId(const qint64 &value);
qint64 getSecondPointId() const;
void setSecondPointId(const qint64 &value);
public slots:
virtual void ChoosedPoint(qint64 id, Scene::Type type);
virtual void DialogAccepted();
private:
Ui::DialogAlongLine *ui;
qint32 number;
QString pointName;
QString typeLine;
QString formula;
qint64 firstPointId;
qint64 secondPointId;
};
#endif // DIALOGALONGLINE_H

281
dialogs/dialogalongline.ui Normal file
View File

@ -0,0 +1,281 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogAlongLine</class>
<widget class="QDialog" name="DialogAlongLine">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>454</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"/>
</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="baseSize">
<size>
<width>0</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="text">
<string>Ім'я нової точки</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditNamePoint"/>
</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="text">
<string>Перша точка</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxFirstPoint"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Друга точка</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxSecondPoint"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<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_7">
<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="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>DialogAlongLine</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>DialogAlongLine</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

@ -7,19 +7,27 @@
#include "../container/calculator.h"
DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) :
QDialog(parent), ui(new Ui::DialogEndLine)
DialogTool(data, parent), ui(new Ui::DialogEndLine)
{
ui->setupUi(this);
spinBoxAngle = ui->spinBoxAngle;
listWidget = ui->listWidget;
labelResultCalculation = ui->labelResultCalculation;
labelDescription = ui->labelDescription;
radioButtonSizeGrowth = ui->radioButtonSizeGrowth;
radioButtonStandartTable = ui->radioButtonStandartTable;
radioButtonIncrements = ui->radioButtonIncrements;
radioButtonLengthLine = ui->radioButtonLengthLine;
lineEditFormula = ui->lineEditFormula;
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);
flagName = false;
CheckState();
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogEndLine::DialogRejected);
FillComboBoxPoints(ui->comboBoxBasePoint);
FillComboBoxTypeLine(ui->comboBoxLineType);
connect(ui->toolButtonArrowDown, &QPushButton::clicked, this,
&DialogEndLine::ArrowDown);
@ -37,107 +45,18 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) :
&DialogEndLine::ArrowRightUp);
connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this,
&DialogEndLine::ArrowRightDown);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this,
&DialogEndLine::ClickedToolButtonPutHere);
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEndLine::PutHere);
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->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogEndLine::SizeGrowth);
connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogEndLine::StandartTable);
connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogEndLine::Increments);
connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogEndLine::LengthLines);
connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEndLine::EvalFormula);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged);
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){
@ -198,11 +117,6 @@ void DialogEndLine::setAngle(const qint32 &value){
ui->spinBoxAngle->setValue(angle);
}
void DialogEndLine::closeEvent ( QCloseEvent * event ){
DialogClosed(QDialog::Rejected);
event->accept();
}
qint64 DialogEndLine::getBasePointId() const
{
return basePointId;
@ -217,150 +131,14 @@ void DialogEndLine::setBasePointId(const qint64 &value)
}
}
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");
}
typeLine = GetTypeLine(ui->comboBoxLineType);
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();
}
emit DialogClosed(QDialog::Accepted);
}
DialogEndLine::~DialogEndLine()

View File

@ -1,7 +1,7 @@
#ifndef DIALOGENDLINE_H
#define DIALOGENDLINE_H
#include <QDialog>
#include "dialogtool.h"
#include <QPushButton>
#include <QListWidgetItem>
#include <QTimer>
@ -14,71 +14,32 @@ namespace Ui {
class DialogEndLine;
}
class DialogEndLine : public QDialog
class DialogEndLine : public DialogTool
{
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 );
virtual void ChoosedPoint(qint64 id, Scene::Type type);
virtual void DialogAccepted();
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

View File

@ -361,7 +361,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Вихідні данні</string>
<string>Вхідні данні</string>
</property>
</widget>
</item>

View File

@ -8,10 +8,10 @@
#include "../widgets/doubledelegate.h"
DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) :
QDialog(parent), ui(new Ui::DialogIncrements){
DialogTool(data, parent), ui(new Ui::DialogIncrements){
ui->setupUi(this);
this->data = data;
this->doc = doc;
this->data = data;
InitialStandartTable();
InitialIncrementTable();
InitialLinesTable();
@ -33,8 +33,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget
connect(this->doc, &VDomDocument::FullUpdateFromFile, this,
&DialogIncrements::FullUpdateFromFile);
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogIncrements::clickedButtonOk);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogIncrements::DialogAccepted);
}
void DialogIncrements::FillStandartTable(){
@ -335,11 +335,6 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){
}
}
void DialogIncrements::closeEvent ( QCloseEvent * event ){
emit closedActionTable();
event->accept();
}
void DialogIncrements::InitialStandartTable(){
ui->tableWidgetStandart->resizeColumnsToContents();
ui->tableWidgetStandart->resizeRowsToContents();
@ -372,8 +367,8 @@ void DialogIncrements::InitialLinesTable(){
ui->tableWidgetLines->setHorizontalHeaderItem(1, new QTableWidgetItem("Довжина"));
}
void DialogIncrements::clickedButtonOk(){
emit closedActionTable();
void DialogIncrements::DialogAccepted(){
emit DialogClosed(QDialog::Accepted);
}
DialogIncrements::~DialogIncrements(){

View File

@ -1,7 +1,7 @@
#ifndef DIALOGINCREMENTS_H
#define DIALOGINCREMENTS_H
#include <QDialog>
#include "dialogtool.h"
#include <QPushButton>
#include "../container/vcontainer.h"
@ -11,10 +11,9 @@ namespace Ui {
class DialogIncrements;
}
class DialogIncrements : public QDialog
class DialogIncrements : public DialogTool
{
Q_OBJECT
public:
explicit DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0);
~DialogIncrements();
@ -23,13 +22,10 @@ public slots:
void clickedToolButtonRemove();
void cellChanged ( qint32 row, qint32 column );
void FullUpdateFromFile();
void clickedButtonOk();
virtual void DialogAccepted();
signals:
void FullUpdateTree();
void haveLiteChange();
void closedActionTable();
protected:
void closeEvent ( QCloseEvent * event );
private:
Ui::DialogIncrements *ui;
VContainer *data;

View File

@ -4,14 +4,15 @@
#include <QCloseEvent>
DialogLine::DialogLine(const VContainer *data, QWidget *parent) :
QDialog(parent), ui(new Ui::DialogLine)
DialogTool(data, parent), ui(new Ui::DialogLine)
{
ui->setupUi(this);
this->data = data;
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogLine::DialogAccepted);
FillComboBox(ui->comboBoxFirstPoint);
FillComboBox(ui->comboBoxSecondPoint);
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogLine::DialogRejected);
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
number = 0;
}
@ -45,26 +46,6 @@ void DialogLine::setFirstPoint(const qint64 &value){
}
}
void DialogLine::closeEvent(QCloseEvent *event){
DialogClosed(QDialog::Rejected);
event->accept();
}
void DialogLine::showEvent(QShowEvent *event){
QDialog::showEvent( event );
if( event->spontaneous() ){
return;
}
if(isInitialized){
return;
}
// do your init stuff here
isInitialized = true;//перший показ вікна вже відбувся
}
void DialogLine::DialogAccepted(){
qint32 index = ui->comboBoxFirstPoint->currentIndex();
@ -74,17 +55,6 @@ void DialogLine::DialogAccepted(){
DialogClosed(QDialog::Accepted);
}
void DialogLine::FillComboBox(QComboBox *box){
const QMap<qint64, VPointF> *points = data->DataPoints();
QMapIterator<qint64, VPointF> i(*points);
while (i.hasNext()) {
i.next();
VPointF point = i.value();
box->addItem(point.name(), i.key());
}
}
void DialogLine::ChoosedPoint(qint64 id, Scene::Type type){
if(type == Scene::Point){
VPointF point = data->GetPoint(id);

View File

@ -1,7 +1,7 @@
#ifndef DIALOGLINE_H
#define DIALOGLINE_H
#include <QDialog>
#include "dialogtool.h"
#include "../container/vcontainer.h"
#include "../options.h"
#include <QComboBox>
@ -10,35 +10,24 @@ namespace Ui {
class DialogLine;
}
class DialogLine : public QDialog
class DialogLine : public DialogTool
{
Q_OBJECT
public:
explicit DialogLine(const VContainer *data, QWidget *parent = 0);
~DialogLine();
qint64 getFirstPoint() const;
void setFirstPoint(const qint64 &value);
qint64 getSecondPoint() const;
void setSecondPoint(const qint64 &value);
signals:
void DialogClosed(int result);
public slots:
void ChoosedPoint(qint64 id, Scene::Type type);
void DialogAccepted();
protected:
void closeEvent ( QCloseEvent * event );
void showEvent( QShowEvent *event );
virtual void DialogAccepted();
private:
Ui::DialogLine *ui;
const VContainer *data;
qint32 number;
qint64 firstPoint;
qint64 secondPoint;
bool isInitialized;
void FillComboBox(QComboBox *box);
};
#endif // DIALOGLINE_H

View File

@ -6,20 +6,19 @@
#include "../options.h"
DialogSinglePoint::DialogSinglePoint(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogSinglePoint)
DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) :
DialogTool(data, parent), ui(new Ui::DialogSinglePoint)
{
ui->setupUi(this);
isInitialized = false;
ui->doubleSpinBoxX->setRange(0,PaperSize/PrintDPI*25.4);
ui->doubleSpinBoxY->setRange(0,PaperSize/PrintDPI*25.4);
QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok);
pOkButton->setEnabled(false);
connect(pOkButton, &QPushButton::clicked, this, &DialogSinglePoint::OkOperation);
connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSinglePoint::NameChanged);
QPushButton* pCanselButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(pCanselButton, &QPushButton::clicked, this, &DialogSinglePoint::CanselOperation);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
flagName = false;
CheckState();
connect(bOk, &QPushButton::clicked, this, &DialogSinglePoint::DialogAccepted);
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogSinglePoint::DialogRejected);
connect(ui->lineEditName,&QLineEdit::textChanged, this, &DialogSinglePoint::NamePointChanged);
}
void DialogSinglePoint::mousePress(QPointF scenePos){
@ -33,46 +32,11 @@ void DialogSinglePoint::mousePress(QPointF scenePos){
}
}
void DialogSinglePoint::showEvent( QShowEvent *event ){
QDialog::showEvent( event );
if( event->spontaneous() ){
return;
}
if(isInitialized){
return;
}
// do your init stuff here
isInitialized = true;//перший показ вікна вже відбувся
}
void DialogSinglePoint::NameChanged(){
QString name = ui->lineEditName->text();
if(name.isEmpty() || name.contains(" ")){
QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok);
pOkButton->setEnabled(false);
} else {
QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok);
pOkButton->setEnabled(true);
}
}
void DialogSinglePoint::CanselOperation(){
emit ToolCanseled();
}
void DialogSinglePoint::OkOperation(){
void DialogSinglePoint::DialogAccepted(){
point = QPointF(ui->doubleSpinBoxX->value()*PrintDPI/25.4,
ui->doubleSpinBoxY->value()*PrintDPI/25.4);
name = ui->lineEditName->text();
emit SinglePointCreated(ui->lineEditName->text(), point);
}
void DialogSinglePoint::closeEvent ( QCloseEvent * event ){
emit ToolCanseled();
event->accept();
emit DialogClosed(QDialog::Accepted);
}
void DialogSinglePoint::setData(const QString name, const QPointF point){

View File

@ -1,35 +1,27 @@
#ifndef DIALOGSINGLEPOINT_H
#define DIALOGSINGLEPOINT_H
#include <QDialog>
#include "dialogtool.h"
#include "../container/vcontainer.h"
namespace Ui {
class DialogSinglePoint;
}
class DialogSinglePoint : public QDialog
class DialogSinglePoint : public DialogTool
{
Q_OBJECT
public:
explicit DialogSinglePoint(QWidget *parent = 0);
explicit DialogSinglePoint(const VContainer *data, QWidget *parent = 0);
void setData(const QString name, const QPointF point);
QString getName()const;
QPointF getPoint()const;
~DialogSinglePoint();
signals:
void ToolCanseled();
void SinglePointCreated(const QString name, const QPointF point);
public slots:
void mousePress(QPointF scenePos);
void NameChanged();
void CanselOperation();
void OkOperation();
protected:
void showEvent( QShowEvent *event );
void closeEvent ( QCloseEvent * event );
virtual void DialogAccepted();
private:
Ui::DialogSinglePoint *ui;
bool isInitialized;
QString name;
QPointF point;
};

320
dialogs/dialogtool.cpp Normal file
View File

@ -0,0 +1,320 @@
#include "dialogtool.h"
#include <QListWidgetItem>
#include <QCloseEvent>
#include "../container/calculator.h"
DialogTool::DialogTool(const VContainer *data, QWidget *parent):QDialog(parent){
Q_CHECK_PTR(data);
this->data = data;
flagName = true;
flagFormula = true;
timerFormula = new QTimer(this);
connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula);
isInitialized = false;
bOk = 0;
spinBoxAngle = 0;
lineEditFormula = 0;
listWidget = 0;
labelResultCalculation = 0;
labelDescription = 0;
radioButtonSizeGrowth = 0;
radioButtonStandartTable = 0;
radioButtonIncrements = 0;
radioButtonLengthLine = 0;
}
DialogTool::~DialogTool()
{
}
void DialogTool::closeEvent(QCloseEvent *event){
DialogClosed(QDialog::Rejected);
event->accept();
}
void DialogTool::showEvent(QShowEvent *event){
QDialog::showEvent( event );
if( event->spontaneous() ){
return;
}
if(isInitialized){
return;
}
// do your init stuff here
isInitialized = true;//перший показ вікна вже відбувся
}
void DialogTool::FillComboBoxPoints(QComboBox *box) const{
const QMap<qint64, VPointF> *points = data->DataPoints();
QMapIterator<qint64, VPointF> i(*points);
while (i.hasNext()) {
i.next();
VPointF point = i.value();
box->addItem(point.name(), i.key());
}
}
void DialogTool::FillComboBoxTypeLine(QComboBox *box) const{
QStringList list;
list<<"Лінія"<<"Без лінії";
box->addItems(list);
}
QString DialogTool::GetTypeLine(const QComboBox *box) const{
if(box->currentText()=="Лінія"){
return QString("hair");
} else {
return QString("none");
}
}
void DialogTool::ShowBase(){
Q_CHECK_PTR(listWidget);
disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged);
listWidget->clear();
connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::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));
listWidget->addItem(item);
}
listWidget->setCurrentRow (0);
}
void DialogTool::ShowStandartTable(){
Q_CHECK_PTR(listWidget);
disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged);
listWidget->clear();
connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::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));
listWidget->addItem(item);
}
listWidget->setCurrentRow (0);
}
void DialogTool::ShowIncrementTable(){
Q_CHECK_PTR(listWidget);
disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged);
listWidget->clear();
connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::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));
listWidget->addItem(item);
}
listWidget->setCurrentRow (0);
}
void DialogTool::ShowLengthLines(){
Q_CHECK_PTR(listWidget);
disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged);
listWidget->clear();
connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::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));
listWidget->addItem(item);
}
listWidget->setCurrentRow (0);
}
void DialogTool::CheckState(){
Q_CHECK_PTR(bOk);
bOk->setEnabled(flagFormula & flagName);
}
void DialogTool::ChoosedPoint(qint64 id, Scene::Type type){
Q_UNUSED(id);
Q_UNUSED(type);
}
void DialogTool::NamePointChanged(){
QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
if (edit){
QString name = edit->text();
if(name.isEmpty() || name.contains(" ")){
flagName = false;
} else {
flagName = true;
}
}
CheckState();
}
void DialogTool::DialogAccepted(){
emit DialogClosed(QDialog::Accepted);
}
void DialogTool::DialogRejected(){
emit DialogClosed(QDialog::Rejected);
}
void DialogTool::FormulaChanged(){
QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
if(edit){
if(edit->text().isEmpty()){
flagFormula = false;
CheckState();
return;
}
timerFormula->start(1000);
}
}
void DialogTool::ArrowUp(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(90);
}
void DialogTool::ArrowDown(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(270);
}
void DialogTool::ArrowLeft(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(180);
}
void DialogTool::ArrowRight(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(0);
}
void DialogTool::ArrowLeftUp(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(135);
}
void DialogTool::ArrowLeftDown(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(225);
}
void DialogTool::ArrowRightUp(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(45);
}
void DialogTool::ArrowRightDown(){
Q_CHECK_PTR(spinBoxAngle);
spinBoxAngle->setValue(315);
}
void DialogTool::EvalFormula(){
Q_CHECK_PTR(lineEditFormula);
Q_CHECK_PTR(labelResultCalculation);
if(lineEditFormula->text().isEmpty()){
flagFormula = false;
} else {
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(lineEditFormula->text(),&errorMsg);
if(!errorMsg.isEmpty()){
labelResultCalculation->setText("Помилка.");
flagFormula = false;
} else {
labelResultCalculation->setText(QString().setNum(result));
flagFormula = true;
}
}
CheckState();
timerFormula->stop();
}
void DialogTool::SizeGrowth(){
ShowBase();
}
void DialogTool::StandartTable(){
ShowStandartTable();
}
void DialogTool::LengthLines(){
ShowLengthLines();
}
void DialogTool::Increments(){
ShowIncrementTable();
}
void DialogTool::PutHere(){
Q_CHECK_PTR(lineEditFormula);
Q_CHECK_PTR(listWidget);
QListWidgetItem *item = listWidget->currentItem();
QString val = item->text();
lineEditFormula->setText(lineEditFormula->text().append(val));
}
void DialogTool::PutVal(QListWidgetItem *item){
Q_CHECK_PTR(lineEditFormula);
QString val = item->text();
lineEditFormula->setText(lineEditFormula->text().append(val));
}
void DialogTool::ValChenged(int row){
Q_CHECK_PTR(listWidget);
Q_CHECK_PTR(labelDescription);
Q_CHECK_PTR(radioButtonSizeGrowth);
Q_CHECK_PTR(radioButtonStandartTable);
Q_CHECK_PTR(radioButtonIncrements);
if(listWidget->count() == 0){
return;
}
QListWidgetItem *item = listWidget->item( row );
if(radioButtonSizeGrowth->isChecked()){
if(item->text()=="Р"){
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->growth()).arg("Зріст");
labelDescription->setText(desc);
}
if(item->text()=="Сг"){
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg("Розмір");
labelDescription->setText(desc);
}
}
if(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());
labelDescription->setText(desc);
}
if(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());
labelDescription->setText(desc);
}
}
void DialogTool::UpdateList(){
Q_CHECK_PTR(radioButtonSizeGrowth);
Q_CHECK_PTR(radioButtonStandartTable);
Q_CHECK_PTR(radioButtonIncrements);
if(radioButtonSizeGrowth->isChecked()){
ShowBase();
}
if(radioButtonStandartTable->isChecked()){
ShowStandartTable();
}
if(radioButtonIncrements->isChecked()){
ShowIncrementTable();
}
}

75
dialogs/dialogtool.h Normal file
View File

@ -0,0 +1,75 @@
#ifndef DIALOGTOOL_H
#define DIALOGTOOL_H
#include <QDialog>
#include <QComboBox>
#include <QSpinBox>
#include <QPushButton>
#include <QLineEdit>
#include <QListWidget>
#include <QLabel>
#include <QRadioButton>
#include <QTimer>
#include "../container/vcontainer.h"
#include "../options.h"
class DialogTool : public QDialog
{
Q_OBJECT
public:
DialogTool(const VContainer *data, QWidget *parent = 0);
virtual ~DialogTool();
signals:
void DialogClosed(int result);
public slots:
virtual void ChoosedPoint(qint64 id, Scene::Type type);
void NamePointChanged();
virtual void DialogAccepted();
virtual void DialogRejected();
void FormulaChanged();
void ArrowUp();
void ArrowDown();
void ArrowLeft();
void ArrowRight();
void ArrowLeftUp();
void ArrowLeftDown();
void ArrowRightUp();
void ArrowRightDown();
void EvalFormula();
void SizeGrowth();
void StandartTable();
void LengthLines();
void Increments();
void PutHere();
void PutVal(QListWidgetItem * item);
void ValChenged(int row);
void UpdateList();
protected:
const VContainer *data;
bool isInitialized;
bool flagName;
bool flagFormula;
QTimer *timerFormula;
QPushButton *bOk;
QSpinBox *spinBoxAngle;
QLineEdit *lineEditFormula;
QListWidget *listWidget;
QLabel *labelResultCalculation;
QLabel *labelDescription;
QRadioButton *radioButtonSizeGrowth;
QRadioButton *radioButtonStandartTable;
QRadioButton *radioButtonIncrements;
QRadioButton *radioButtonLengthLine;
void closeEvent ( QCloseEvent * event );
void showEvent( QShowEvent *event );
void FillComboBoxPoints(QComboBox *box)const;
void FillComboBoxTypeLine(QComboBox *box) const;
void CheckState();
QString GetTypeLine(const QComboBox *box)const;
void ShowBase();
void ShowStandartTable();
void ShowIncrementTable();
void ShowLengthLines();
};
#endif // DIALOGTOOL_H

View File

@ -20,5 +20,6 @@
<file>icon/24x24/equal.png</file>
<file>icon/32x32/segment.png</file>
<file>icon/32x32/line.png</file>
<file>icon/32x32/along_line.png</file>
</qresource>
</RCC>

BIN
icon/32x32/along_line.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 689 B

View File

@ -13,6 +13,7 @@
#include "options.h"
#include "tools/vtoolendline.h"
#include "tools/vtoolline.h"
#include "tools/vtoolalongline.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
@ -46,6 +47,8 @@ MainWindow::MainWindow(QWidget *parent) :
&MainWindow::ToolEndLine);
connect(ui->toolButtonLine, &QToolButton::clicked, this,
&MainWindow::ToolLine);
connect(ui->toolButtonAlongLine, &QToolButton::clicked, this,
&MainWindow::ToolAlongLine);
data = new VContainer;
CreateManTableIGroup ();
@ -145,14 +148,12 @@ void MainWindow::ToolSinglePoint(bool checked){
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть розташування для точки.");
dialogSinglePoint = new DialogSinglePoint;
dialogSinglePoint = new DialogSinglePoint(data);
//покажемо вікно як тільки буде вибрано місце розташування для точки
connect(scene, &VMainGraphicsScene::mousePress, dialogSinglePoint,
&DialogSinglePoint::mousePress);
//головне вікно отримає сигнал відміни створення точки
connect(dialogSinglePoint, &DialogSinglePoint::ToolCanseled, this, &MainWindow::ToolCanseled);
connect(dialogSinglePoint, &DialogSinglePoint::SinglePointCreated, this,
&MainWindow::SinglePointCreated);
connect(dialogSinglePoint, &DialogSinglePoint::DialogClosed, this,
&MainWindow::ClosedDialogSinglePoint);
} else { //не даємо користувачу зняти виділення кнопки
ui->toolButtonSinglePoint->setChecked(true);
}
@ -234,6 +235,48 @@ void MainWindow::ClosedDialogLine(int result){
ArrowTool();
}
void MainWindow::ToolAlongLine(bool checked){
if(checked){
CanselTool();
tool = Tools::AlongLineTool;
QPixmap pixmap(":/cursor/alongline_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogAlongLine = new DialogAlongLine(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogAlongLine, &DialogAlongLine::ChoosedPoint);
connect(dialogAlongLine, &DialogLine::DialogClosed, this, &MainWindow::ClosedDialogAlongLine);
} else {
ui->toolButtonAlongLine->setChecked(true);
}
}
void MainWindow::ClosedDialogAlongLine(int result){
if(result == QDialog::Accepted){
QString formula = dialogAlongLine->getFormula();
qint64 firstPointId = dialogAlongLine->getFirstPointId();
qint64 secondPointId = dialogAlongLine->getSecondPointId();
QString typeLine = dialogAlongLine->getTypeLine();
QString pointName = dialogAlongLine->getPointName();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
qint64 id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, 5, 10));
VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId,
typeLine, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolAlongLine::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
void MainWindow::showEvent( QShowEvent *event ){
QMainWindow::showEvent( event );
if( event->spontaneous() ){
@ -352,6 +395,11 @@ void MainWindow::CanselTool(){
ui->toolButtonLine->setChecked(false);
scene->clearFocus();
break;
case Tools::AlongLineTool:
delete dialogAlongLine;
ui->toolButtonAlongLine->setChecked(false);
scene->clearFocus();
break;
}
}
@ -377,11 +425,10 @@ void MainWindow::keyPressEvent ( QKeyEvent * event ){
QMainWindow::keyPressEvent ( event );
}
void MainWindow::ToolCanseled(){
ArrowTool();
}
void MainWindow::SinglePointCreated(const QString name, const QPointF point){
void MainWindow::ClosedDialogSinglePoint(int result){
if(result == QDialog::Accepted){
QPointF point = dialogSinglePoint->getPoint();
QString name = dialogSinglePoint->getName();
qint64 id = data->AddPoint(VPointF(point.x(), point.y(), name, 5, 10));
VToolSimplePoint *spoint = new VToolSimplePoint(doc, data, id, Tool::FromGui);
scene->addItem(spoint);
@ -392,6 +439,8 @@ void MainWindow::SinglePointCreated(const QString name, const QPointF point){
comboBoxDraws->setItemData(index, false);
ui->actionSave->setEnabled(true);
SetEnableTool(true);
}
ArrowTool();
}
void MainWindow::ActionDraw(bool checked){
@ -590,8 +639,8 @@ void MainWindow::SetEnableWidgets(bool enable){
void MainWindow::ActionTable(bool checked){
if(checked){
dialogTable = new DialogIncrements(data, doc, 0);
connect(dialogTable, &DialogIncrements::closedActionTable, this,
dialogTable = new DialogIncrements(data, doc, this);
connect(dialogTable, &DialogIncrements::DialogClosed, this,
&MainWindow::ClosedActionTable);
dialogTable->show();
} else {
@ -605,16 +654,10 @@ void MainWindow::ClosedActionTable(){
delete dialogTable;
}
void MainWindow::closeEvent ( QCloseEvent * event ){
if(ui->actionTable->isChecked()==true){
delete dialogTable;
}
event->accept();
}
void MainWindow::SetEnableTool(bool enable){
ui->toolButtonEndLine->setEnabled(enable);
ui->toolButtonLine->setEnabled(enable);
ui->toolButtonAlongLine->setEnabled(enable);
}
MainWindow::~MainWindow(){

View File

@ -5,11 +5,13 @@
#include <QLabel>
#include <QtXml>
#include <QComboBox>
#include <QSharedPointer>
#include "widgets/vmaingraphicsscene.h"
#include "dialogs/dialogsinglepoint.h"
#include "dialogs/dialogincrements.h"
#include "dialogs/dialogline.h"
#include "dialogs/dialogalongline.h"
#include "tools/vtoolsimplepoint.h"
#include "xml/vdomdocument.h"
#include "container/vcontainer.h"
@ -25,7 +27,8 @@ namespace Tools{
ArrowTool,
SinglePointTool,
EndLineTool,
LineTool
LineTool,
AlongLineTool
};
}
@ -41,8 +44,7 @@ public slots:
void ActionAroowTool();
void ActionDraw(bool checked);
void ActionDetails(bool checked);
void ToolCanseled();
void SinglePointCreated(const QString name, const QPointF point);
void ClosedDialogSinglePoint(int result);
void ActionNewDraw();
void currentDrawChanged( int index );
void OptionDraw();
@ -59,10 +61,11 @@ public slots:
void ClosedDialogEndLine(int result);
void ToolLine(bool checked);
void ClosedDialogLine(int result);
void ToolAlongLine(bool checked);
void ClosedDialogAlongLine(int result);
protected:
virtual void keyPressEvent ( QKeyEvent * event );
virtual void showEvent( QShowEvent *event );
virtual void closeEvent ( QCloseEvent * event );
private:
Ui::MainWindow *ui;
Tools::Enum tool;
@ -74,6 +77,7 @@ private:
DialogIncrements *dialogTable;
DialogEndLine *dialogEndLine;
DialogLine *dialogLine;
DialogAlongLine *dialogAlongLine;
VDomDocument *doc;
VContainer *data;
QComboBox *comboBoxDraws;

View File

@ -57,7 +57,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
@ -109,10 +109,26 @@
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="toolButton_3">
<widget class="QToolButton" name="toolButtonAlongLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/along_line.png</normaloff>:/icon/32x32/along_line.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
@ -202,7 +218,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>154</width>
<width>117</width>
<height>45</height>
</rect>
</property>
@ -230,7 +246,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>154</width>
<width>117</width>
<height>45</height>
</rect>
</property>
@ -474,11 +490,4 @@
<include location="icon.qrc"/>
</resources>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup_2">
<property name="exclusive">
<bool>false</bool>
</property>
</buttongroup>
</buttongroups>
</ui>

View File

@ -3,8 +3,8 @@
#define PrintDPI 96
#define PaperSize 50000
#define WidthMainLine 0.8*PrintDPI/25.4
#define widthHairLine WidthMainLine/3
#define widthMainLine 0.8*PrintDPI/25.4
#define widthHairLine widthMainLine/3
namespace Scene{
enum Type

View File

@ -54,9 +54,15 @@ void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, c
VAbstractTool::~VAbstractTool(){
}
QString VAbstractTool::GetNameLine(qint64 firstPoint, qint64 secondPoint) const{
QString VAbstractTool::GetNameLine(const qint64 &firstPoint, const 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;
return QString("Line_%1_%2").arg(first.name(), second.name());
}
void VAbstractTool::AddLine(const qint64 &firstPointId, const qint64 &secondPointId) const{
QString nameLine = GetNameLine(firstPointId, secondPointId);
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
data->AddLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length());
}

View File

@ -24,6 +24,7 @@ public slots:
virtual void FullUpdateFromFile()=0;
void ChangedNameDraw(const QString oldName, const QString newName);
virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromGui(int result)=0;
signals:
void haveLiteChange();
void ChoosedPoint(qint64 id, Scene::Type type);
@ -39,6 +40,7 @@ protected:
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);
QString GetNameLine(qint64 firstPoint, qint64 secondPoint) const;
QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const;
void AddLine(const qint64 &firstPointId, const qint64 &secondPointId) const;
};
#endif // VABSTRACTTOOL_H

142
tools/vtoolalongline.cpp Normal file
View File

@ -0,0 +1,142 @@
#include "vtoolalongline.h"
#include "../container/calculator.h"
#include <QDialog>
#include <QMenu>
#include <QDebug>
VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula,
const qint64 &firstPointId, const qint64 &secondPointId,
const QString &typeLine, Tool::Enum typeCreation,
QGraphicsItem *parent):VToolPoint(doc, data, id, parent){
connect(this, &VToolAlongLine::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
this->typeLine = typeLine;
this->formula = formula;
this->firstPointId = firstPointId;
this->secondPointId = secondPointId;
//Лінія, якщо потрібно.
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
mainLine = new QGraphicsLineItem(line, this);
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
AddLine(firstPointId, id);
AddLine(id, secondPointId);
if(typeCreation == Tool::FromGui){
AddToFile();
}
}
}
void VToolAlongLine::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", "");
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
}
VPointF point = VAbstractTool::data->GetPoint(id);
RefreshBaseGeometry(name, point.x(), point.y(), mx, my);
VPointF firstPoint = VAbstractTool::data->GetPoint(firstPointId);
VPointF secondPoint = VAbstractTool::data->GetPoint(secondPointId);
mainLine->setLine(QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()));
AddLine(firstPointId, id);
AddLine(id, secondPointId);
}
void VToolAlongLine::FullUpdateFromGui(int result){
if(result == QDialog::Accepted){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("name", dialogAlongLine->getPointName());
domElement.setAttribute("typeLine", dialogAlongLine->getTypeLine());
domElement.setAttribute("length", dialogAlongLine->getFormula());
domElement.setAttribute("firstPoint", QString().setNum(dialogAlongLine->getFirstPointId()));
domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId()));
emit FullUpdateTree();
}
}
dialogAlongLine.clear();
}
void VToolAlongLine::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
mainLine->setPen(QPen(Qt::black, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
} else {
mainLine->setPen(QPen(Qt::gray, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
}
}
void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogAlongLine = QSharedPointer<DialogAlongLine>(new DialogAlongLine(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogAlongLine.data(), &DialogAlongLine::ChoosedPoint);
connect(dialogAlongLine.data(), &DialogAlongLine::DialogClosed, this,
&VToolAlongLine::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogAlongLine.data(),
&DialogAlongLine::UpdateList);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogAlongLine->setTypeLine(typeLine);
dialogAlongLine->setFormula(formula);
dialogAlongLine->setFirstPointId(firstPointId);
dialogAlongLine->setSecondPointId(secondPointId);
dialogAlongLine->setPointName(p.name());
dialogAlongLine->show();
}
}
}
void VToolAlongLine::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
AddAttribute(domElement, "type", "alongLine");
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, "firstPoint", firstPointId);
AddAttribute(domElement, "secondPoint", secondPointId);
QDomElement calcElement;
bool ok = doc->GetActivCalculationElement(calcElement);
if(ok){
calcElement.appendChild(domElement);
} else {
qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO;
}
}

30
tools/vtoolalongline.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef VTOOLALONGLINE_H
#define VTOOLALONGLINE_H
#include "vtoolpoint.h"
#include "../dialogs/dialogalongline.h"
class VToolAlongLine : public VToolPoint
{
Q_OBJECT
public:
VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula,
const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine,
Tool::Enum typeCreation, QGraphicsItem * parent = 0);
public slots:
virtual void FullUpdateFromFile();
virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromGui(int result);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
QString typeLine;
QString formula;
qint64 firstPointId;
qint64 secondPointId;
QGraphicsLineItem *mainLine;
QSharedPointer<DialogAlongLine> dialogAlongLine;
};
#endif // VTOOLALONGLINE_H

View File

@ -25,9 +25,7 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id
mainLine->setVisible(true);
}
QString nameLine = GetNameLine(basePointId, id);
QLineF line = QLineF(basePoint.toQPointF(), point.toQPointF());
data->AddLine(nameLine, line.length());
AddLine(basePointId, id);
if(typeCreation == Tool::FromGui){
AddToFile();
@ -52,9 +50,7 @@ void VToolEndLine::FullUpdateFromFile(){
VPointF basePoint = VAbstractTool::data->GetPoint(basePointId);
mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF()));
QString nameLine = GetNameLine(basePointId, id);
QLineF line = QLineF(basePoint.toQPointF(), point.toQPointF());
VAbstractTool::data->AddLine(nameLine, line.length());
AddLine(basePointId, id);
}
void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
@ -67,7 +63,8 @@ void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogEndLine.data(), &DialogEndLine::ChoosedPoint);
connect(dialogEndLine.data(), &DialogEndLine::DialogClosed, this, &VToolEndLine::ClosedDialogEndLine);
connect(dialogEndLine.data(), &DialogEndLine::DialogClosed, this,
&VToolEndLine::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogEndLine.data(), &DialogEndLine::UpdateList);
VPointF p = VAbstractTool::data->GetPoint(id);
@ -83,26 +80,17 @@ void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
}
}
void VToolEndLine::ClosedDialogEndLine(int result){
void VToolEndLine::FullUpdateFromGui(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 = VAbstractTool::data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
Calculator cal(VAbstractTool::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);
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("name", dialogEndLine->getPointName());
domElement.setAttribute("typeLine", dialogEndLine->getTypeLine());
domElement.setAttribute("length", dialogEndLine->getFormula());
domElement.setAttribute("angle", QString().setNum(dialogEndLine->getAngle()));
domElement.setAttribute("basePoint", QString().setNum(dialogEndLine->getBasePointId()));
emit FullUpdateTree();
}
}
dialogEndLine.clear();
}
@ -140,22 +128,3 @@ void VToolEndLine::AddToFile(){
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();
}
}

View File

@ -16,7 +16,7 @@ public:
QGraphicsItem * parent = 0);
public slots:
virtual void FullUpdateFromFile();
void ClosedDialogEndLine(int result);
virtual void FullUpdateFromGui(int result);
virtual void ChangedActivDraw(const QString newName);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
@ -28,8 +28,6 @@ private:
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

@ -3,7 +3,8 @@
#include <QDebug>
VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint,
Tool::Enum typeCreation):VAbstractTool(doc, data, id){
Tool::Enum typeCreation, QGraphicsItem *parent):VAbstractTool(doc, data, id),
QGraphicsLineItem(parent){
connect(this, &VToolLine::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
this->firstPoint = firstPoint;
this->secondPoint = secondPoint;
@ -14,9 +15,9 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs
this->setLine(QLineF(first.toQPointF(), second.toQPointF()));
this->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
QString nameLine = GetNameLine(firstPoint, secondPoint);
data->AddLine(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length());
AddLine(firstPoint, secondPoint);
if(typeCreation == Tool::FromGui){
AddToFile();
@ -32,15 +33,17 @@ void VToolLine::FullUpdateFromFile(){
VPointF first = VAbstractTool::data->GetPoint(firstPoint);
VPointF second = VAbstractTool::data->GetPoint(secondPoint);
this->setLine(QLineF(first.toQPointF(), second.toQPointF()));
QString nameLine = GetNameLine(firstPoint, secondPoint);
VAbstractTool::data->AddLine(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length());
AddLine(firstPoint, secondPoint);
}
void VToolLine::ClosedDialogLine(int result){
void VToolLine::FullUpdateFromGui(int result){
if(result == QDialog::Accepted){
qint64 firstPoint = dialogLine->getFirstPoint();
qint64 secondPoint = dialogLine->getSecondPoint();
FullUpdateFromGui(firstPoint, secondPoint);
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("firstPoint", QString().setNum(dialogLine->getFirstPoint()));
domElement.setAttribute("secondPoint", QString().setNum(dialogLine->getSecondPoint()));
emit FullUpdateTree();
}
}
dialogLine.clear();
}
@ -48,9 +51,11 @@ void VToolLine::ClosedDialogLine(int result){
void VToolLine::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
this->setPen(QPen(Qt::black, widthHairLine));
this->setAcceptHoverEvents (true);
VAbstractTool::ChangedActivDraw(newName);
} else {
this->setPen(QPen(Qt::gray, widthHairLine));
this->setAcceptHoverEvents (false);
VAbstractTool::ChangedActivDraw(newName);
}
}
@ -65,7 +70,7 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogLine.data(), &DialogLine::ChoosedPoint);
connect(dialogLine.data(), &DialogLine::DialogClosed, this, &VToolLine::ClosedDialogLine);
connect(dialogLine.data(), &DialogLine::DialogClosed, this, &VToolLine::FullUpdateFromGui);
dialogLine->setFirstPoint(firstPoint);
dialogLine->setSecondPoint(secondPoint);
@ -78,9 +83,7 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
void VToolLine::AddToFile(){
QDomElement domElement = doc->createElement("line");
AddAttribute(domElement, "id", id);
AddAttribute(domElement, "firstPoint", firstPoint);
AddAttribute(domElement, "secondPoint", secondPoint);
@ -93,14 +96,13 @@ void VToolLine::AddToFile(){
}
}
void VToolLine::FullUpdateFromGui(qint64 firstPoint, qint64 secondPoint){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
this->firstPoint = firstPoint;
this->secondPoint = secondPoint;
domElement.setAttribute("firstPoint", QString().setNum(firstPoint));
domElement.setAttribute("secondPoint", QString().setNum(secondPoint));
emit FullUpdateTree();
}
void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event);
this->setPen(QPen(Qt::black, widthMainLine));
}
void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event);
this->setPen(QPen(Qt::black, widthHairLine));
}

View File

@ -10,19 +10,20 @@ class VToolLine: public VAbstractTool, public QGraphicsLineItem
Q_OBJECT
public:
VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint,
Tool::Enum typeCreation);
Tool::Enum typeCreation, QGraphicsItem * parent = 0);
public slots:
virtual void FullUpdateFromFile();
void ClosedDialogLine(int result);
virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromGui(int result);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
private:
qint64 firstPoint;
qint64 secondPoint;
QSharedPointer<DialogLine> dialogLine;
void FullUpdateFromGui(qint64 firstPoint, qint64 secondPoint);
};
#endif // VTOOLLINE_H

View File

@ -19,6 +19,7 @@ VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id,
this->setPen(QPen(Qt::black, widthHairLine));
this->setBrush(QBrush(Qt::NoBrush));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
//Тексто мітка точки
namePoint = new VGraphicsSimpleTextItem(point.name(), this);
@ -166,7 +167,9 @@ void VToolPoint::ChangedActivDraw(const QString newName){
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true);
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
namePoint->setBrush(QBrush(Qt::black));
namePoint->setAcceptHoverEvents(true);
lineName->setPen(QPen(Qt::black, widthHairLine));
this->setAcceptHoverEvents(true);
VAbstractTool::ChangedActivDraw(newName);
} else {
this->setPen(QPen(Qt::gray, widthHairLine));
@ -175,7 +178,9 @@ void VToolPoint::ChangedActivDraw(const QString newName){
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false);
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
namePoint->setBrush(QBrush(Qt::gray));
namePoint->setAcceptHoverEvents(false);
lineName->setPen(QPen(Qt::gray, widthHairLine));
this->setAcceptHoverEvents (false);
VAbstractTool::ChangedActivDraw(newName);
}
}
@ -200,6 +205,16 @@ void VToolPoint::RefreshBaseGeometry(const QString &name, const qreal &x, const
RefreshLine();
}
void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event);
this->setPen(QPen(Qt::black, widthMainLine));
}
void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event);
this->setPen(QPen(Qt::black, widthHairLine));
}
VToolPoint::~VToolPoint(){
}

View File

@ -17,6 +17,7 @@ public:
public slots:
void NameChangePosition(const QPointF pos);
virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromGui(int result) = 0;
protected:
qreal radius;
VGraphicsSimpleTextItem *namePoint;
@ -24,7 +25,8 @@ protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
void RefreshBaseGeometry(const QString &name, const qreal &x, const qreal &y,
const qreal &mx, const qreal &my);
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
private:
qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1,
QPointF &p2) const;

View File

@ -9,11 +9,9 @@
#include "../options.h"
#include "../container/vpointf.h"
#include "../dialogs/dialogsinglepoint.h"
VToolSimplePoint::VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
QGraphicsItem * parent ):VToolPoint(doc, data, id, parent){
ignoreContextMenuEvent = false;//don't ignore context menu events;
connect(this, &VToolSimplePoint::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
if(typeCreation == Tool::FromGui){
AddToFile();
@ -41,14 +39,18 @@ void VToolSimplePoint::AddToFile(){
}
}
void VToolSimplePoint::FullUpdateFromGui(const QString &name, qreal x, qreal y){
void VToolSimplePoint::FullUpdateFromGui(int result){
if(result == QDialog::Accepted){
QPointF p = dialogSinglePoint->getPoint();
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("name", name);
domElement.setAttribute("x", QString().setNum(x/PrintDPI*25.4));
domElement.setAttribute("y", QString().setNum(y/PrintDPI*25.4));
domElement.setAttribute("name", dialogSinglePoint->getName());
domElement.setAttribute("x", QString().setNum(p.x()/PrintDPI*25.4));
domElement.setAttribute("y", QString().setNum(p.y()/PrintDPI*25.4));
emit FullUpdateTree();
}
}
dialogSinglePoint.clear();
}
void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){
@ -57,15 +59,12 @@ void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
DialogSinglePoint *dialogSinglePoint = new DialogSinglePoint;
dialogSinglePoint = QSharedPointer<DialogSinglePoint>(new DialogSinglePoint(VAbstractTool::data));
connect(dialogSinglePoint.data(), &DialogSinglePoint::DialogClosed, this,
&VToolSimplePoint::FullUpdateFromGui);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogSinglePoint->setData(p.name(), p.toQPointF());
qint32 result = dialogSinglePoint->exec();
if(result == QDialog::Accepted){
QPointF p = dialogSinglePoint->getPoint();
FullUpdateFromGui(dialogSinglePoint->getName(), p.x(), p.y());
}
delete dialogSinglePoint;
dialogSinglePoint->exec();
}
}
}

View File

@ -4,6 +4,7 @@
#include "../container/vcontainer.h"
#include "../xml/vdomdocument.h"
#include "vtoolpoint.h"
#include "../dialogs/dialogsinglepoint.h"
class VToolSimplePoint : public VToolPoint
{
@ -13,11 +14,12 @@ public:
Tool::Enum typeCreation, QGraphicsItem * parent = 0 );
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
void FullUpdateFromGui(const QString& name, qreal x, qreal y);
QSharedPointer<DialogSinglePoint> dialogSinglePoint;
};
#endif // VTOOLSIMPLEPOINT_H

View File

@ -8,6 +8,7 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphic
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setAcceptHoverEvents(true);
}
QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value){
@ -25,4 +26,14 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV
emit NameChangePosition(newPos);
}
return QGraphicsItem::itemChange(change, value);
}
}
void VGraphicsSimpleTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event);
this->setBrush(Qt::green);
}
void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
Q_UNUSED(event);
this->setBrush(Qt::black);
}

View File

@ -13,6 +13,8 @@ signals:
void NameChangePosition(const QPointF pos);
protected:
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
};
#endif // VGRAPHICSSIMPLETEXTITEM_H

View File

@ -4,6 +4,7 @@
#include "../tools/vtoolsimplepoint.h"
#include "../tools/vtoolendline.h"
#include "../tools/vtoolline.h"
#include "../tools/vtoolalongline.h"
#include "../options.h"
#include "../container/calculator.h"
@ -367,6 +368,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
}
}
return;
}
if(type == "endLine"){
if(!domElement.isNull()){
@ -403,6 +405,43 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
}
}
return;
}
if(type == "alongLine"){
if(!domElement.isNull()){
QString name, typeLine, formula;
qreal mx=5, my=10;
qint64 id, firstPointId, secondPointId;
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", "");
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), name, mx, my));
if(parse == Document::FullParse){
VToolAlongLine *point = new VToolAlongLine(this, data, id, formula, firstPointId,
secondPointId, typeLine, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolAlongLine::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
}
}
return;
}
}