2022-01-09 06:42:13 +01:00
|
|
|
#include "pathpropertiesdialog.h"
|
|
|
|
|
#include "ui_pathpropertiesdialog.h"
|
|
|
|
|
|
2022-01-10 21:49:06 +01:00
|
|
|
#include <QSpinBox>
|
|
|
|
|
#include <QLabel>
|
2022-01-09 06:42:13 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
#include "projectcontainer.h"
|
2022-01-14 21:21:17 +01:00
|
|
|
#include "models/projecttreemodel.h"
|
|
|
|
|
#include "models/pathpointsmodel.h"
|
2022-01-09 06:42:13 +01:00
|
|
|
|
2022-01-09 23:05:01 +01:00
|
|
|
PathPropertiesDialog::PathPropertiesDialog(Path &path, ProjectTreeModel &projectModel, QWidget *parent) :
|
2022-01-09 06:42:13 +01:00
|
|
|
QDialog{parent},
|
|
|
|
|
m_ui{std::make_unique<Ui::PathPropertiesDialog>()},
|
|
|
|
|
m_path{path},
|
2022-01-09 23:05:01 +01:00
|
|
|
m_projectModel{projectModel},
|
2022-01-10 21:49:06 +01:00
|
|
|
m_points{path.points},
|
|
|
|
|
m_pointsModel{std::make_unique<PathPointsModel>(m_points, this)},
|
|
|
|
|
m_spinBoxSnapX{new QSpinBox{this}},
|
|
|
|
|
m_spinBoxSnapY{new QSpinBox{this}},
|
2022-01-09 06:42:13 +01:00
|
|
|
m_labelX{new QLabel{tr("x: %0").arg(0)}},
|
|
|
|
|
m_labelY{new QLabel{tr("y: %0").arg(0)}},
|
|
|
|
|
m_labelArea{new QLabel{tr("Area: (%0,%1)->(%2,%3)").arg(0).arg(0).arg(0).arg(0)}}
|
|
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
2022-01-10 21:49:06 +01:00
|
|
|
m_ui->widget->setPoints(&m_points);
|
|
|
|
|
|
2022-01-09 23:05:01 +01:00
|
|
|
updateTitle();
|
2022-01-09 06:42:13 +01:00
|
|
|
|
2022-01-10 21:49:06 +01:00
|
|
|
{
|
|
|
|
|
auto label = new QLabel{tr("Snap X:"), this};
|
|
|
|
|
label->setBuddy(m_spinBoxSnapX);
|
|
|
|
|
m_ui->toolBar->insertWidget(m_ui->toolBar->actions().at(18), label);
|
|
|
|
|
}
|
|
|
|
|
m_spinBoxSnapX->setValue(m_ui->widget->gridX());
|
|
|
|
|
m_spinBoxSnapX->setMaximumWidth(50);
|
|
|
|
|
m_ui->toolBar->insertWidget(m_ui->toolBar->actions().at(19), m_spinBoxSnapX);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto label = new QLabel{tr("Snap Y:"), this};
|
|
|
|
|
label->setBuddy(m_spinBoxSnapY);
|
|
|
|
|
m_ui->toolBar->insertWidget(m_ui->toolBar->actions().at(20), label);
|
|
|
|
|
}
|
|
|
|
|
m_spinBoxSnapY->setValue(m_ui->widget->gridY());
|
|
|
|
|
m_spinBoxSnapY->setMaximumWidth(50);
|
|
|
|
|
m_ui->toolBar->insertWidget(m_ui->toolBar->actions().at(21), m_spinBoxSnapY);
|
|
|
|
|
|
|
|
|
|
m_ui->actionGrid->setChecked(m_ui->widget->showGrid());
|
|
|
|
|
|
|
|
|
|
m_ui->treeView->setModel(m_pointsModel.get());
|
|
|
|
|
|
|
|
|
|
m_ui->radioButtonStraight->setChecked(m_path.type == Path::Type::Straight);
|
|
|
|
|
m_ui->radioButtonSmooth->setChecked(m_path.type == Path::Type::Smooth);
|
|
|
|
|
m_ui->checkBoxClosed->setChecked(m_path.closed);
|
|
|
|
|
m_ui->spinBoxPrecision->setValue(m_path.precision);
|
|
|
|
|
|
|
|
|
|
m_ui->widget->setClosed(m_path.closed);
|
|
|
|
|
|
2022-01-09 06:42:13 +01:00
|
|
|
m_labelX->setFrameStyle(QFrame::Sunken);
|
|
|
|
|
m_ui->statusbar->addWidget(m_labelX, 1);
|
|
|
|
|
m_labelY->setFrameStyle(QFrame::Sunken);
|
|
|
|
|
m_ui->statusbar->addWidget(m_labelY, 1);
|
|
|
|
|
m_labelArea->setFrameStyle(QFrame::Sunken);
|
|
|
|
|
m_ui->statusbar->addWidget(m_labelArea, 4);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto frame = new QFrame{this};
|
|
|
|
|
frame->setFrameStyle(QFrame::Sunken);
|
|
|
|
|
m_ui->statusbar->addPermanentWidget(frame, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_ui->lineEditName->setText(m_path.name);
|
|
|
|
|
|
2022-01-10 21:49:06 +01:00
|
|
|
m_ui->treeView->setColumnWidth(1, 75);
|
|
|
|
|
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::pointInserted,
|
|
|
|
|
m_pointsModel.get(), &PathPointsModel::pointInserted);
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::pointMoved,
|
|
|
|
|
m_pointsModel.get(), &PathPointsModel::pointMoved);
|
|
|
|
|
|
2022-01-09 23:05:01 +01:00
|
|
|
connect(&m_projectModel, &ProjectTreeModel::pathNameChanged,
|
|
|
|
|
this, &PathPropertiesDialog::pathNameChanged);
|
|
|
|
|
|
2022-01-10 21:49:06 +01:00
|
|
|
connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
|
|
|
this, &PathPropertiesDialog::selectionChanged);
|
|
|
|
|
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::gridXChanged,
|
|
|
|
|
m_spinBoxSnapX, &QSpinBox::setValue);
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::gridYChanged,
|
|
|
|
|
m_spinBoxSnapY, &QSpinBox::setValue);
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::showGridChanged,
|
|
|
|
|
m_ui->actionGrid, &QAction::setChecked);
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::closedChanged,
|
|
|
|
|
m_ui->checkBoxClosed, &QCheckBox::setChecked);
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::cursorMoved,
|
|
|
|
|
this, &PathPropertiesDialog::cursorMoved);
|
|
|
|
|
connect(m_ui->widget, &PathPointsWidget::selectedIndexChanged,
|
|
|
|
|
this, &PathPropertiesDialog::selectedPointChanged);
|
|
|
|
|
|
|
|
|
|
connect(m_spinBoxSnapX, &QSpinBox::valueChanged,
|
|
|
|
|
m_ui->widget, &PathPointsWidget::setGridX);
|
|
|
|
|
connect(m_spinBoxSnapY, &QSpinBox::valueChanged,
|
|
|
|
|
m_ui->widget, &PathPointsWidget::setGridY);
|
|
|
|
|
connect(m_ui->actionGrid, &QAction::toggled,
|
|
|
|
|
m_ui->widget, &PathPointsWidget::setShowGrid);
|
|
|
|
|
connect(m_ui->checkBoxClosed, &QCheckBox::toggled,
|
|
|
|
|
m_ui->widget, &PathPointsWidget::setClosed);
|
|
|
|
|
|
2022-01-11 02:35:26 +01:00
|
|
|
connect(m_ui->pushButtonAdd, &QAbstractButton::clicked,
|
2022-01-09 23:05:01 +01:00
|
|
|
this, &PathPropertiesDialog::add);
|
2022-01-11 02:35:26 +01:00
|
|
|
connect(m_ui->pushButtonInsert, &QAbstractButton::clicked,
|
2022-01-09 23:05:01 +01:00
|
|
|
this, &PathPropertiesDialog::insert);
|
2022-01-11 02:35:26 +01:00
|
|
|
connect(m_ui->pushButtonDelete, &QAbstractButton::clicked,
|
2022-01-09 23:05:01 +01:00
|
|
|
this, &PathPropertiesDialog::delete_);
|
|
|
|
|
|
2022-01-09 06:42:13 +01:00
|
|
|
connect(m_ui->lineEditName, &QLineEdit::textChanged,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
2022-01-10 21:49:06 +01:00
|
|
|
|
|
|
|
|
connect(m_pointsModel.get(), &QAbstractTableModel::rowsInserted,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
|
|
|
|
connect(m_pointsModel.get(), &QAbstractTableModel::rowsRemoved,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
|
|
|
|
connect(m_pointsModel.get(), &QAbstractTableModel::dataChanged,
|
|
|
|
|
this, &PathPropertiesDialog::dataChanged);
|
|
|
|
|
connect(m_pointsModel.get(), &QAbstractTableModel::dataChanged,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
|
|
|
|
connect(m_ui->radioButtonStraight, &QRadioButton::toggled,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
|
|
|
|
connect(m_ui->radioButtonSmooth, &QRadioButton::toggled,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
|
|
|
|
connect(m_ui->checkBoxClosed, &QCheckBox::toggled,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
|
|
|
|
connect(m_ui->spinBoxPrecision, &QSpinBox::valueChanged,
|
|
|
|
|
this, &PathPropertiesDialog::changed);
|
2022-01-09 06:42:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PathPropertiesDialog::~PathPropertiesDialog() = default;
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::accept()
|
|
|
|
|
{
|
2022-01-10 21:49:06 +01:00
|
|
|
if (!m_unsavedChanges)
|
|
|
|
|
{
|
|
|
|
|
QDialog::reject();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 06:42:13 +01:00
|
|
|
if (m_path.name != m_ui->lineEditName->text())
|
|
|
|
|
{
|
2022-01-10 01:43:41 +01:00
|
|
|
if (!m_projectModel.rename<Path>(m_path, m_ui->lineEditName->text()))
|
2022-01-09 23:05:01 +01:00
|
|
|
{
|
|
|
|
|
QMessageBox::critical(this, tr("Renaming Path failed!"), tr("Renaming Path failed!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-09 06:42:13 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-10 21:49:06 +01:00
|
|
|
m_path.points = m_points;
|
|
|
|
|
|
|
|
|
|
if (m_ui->radioButtonStraight->isChecked())
|
|
|
|
|
m_path.type = Path::Type::Straight;
|
|
|
|
|
else if (m_ui->radioButtonSmooth->isChecked())
|
|
|
|
|
m_path.type = Path::Type::Smooth;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::critical(this, tr("No kind selected!"), tr("No kind selected!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_path.closed = m_ui->checkBoxClosed->isChecked();
|
|
|
|
|
m_path.precision = m_ui->spinBoxPrecision->value();
|
|
|
|
|
|
|
|
|
|
// TODO update points
|
2022-01-09 06:42:13 +01:00
|
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::reject()
|
|
|
|
|
{
|
|
|
|
|
if (!m_unsavedChanges)
|
|
|
|
|
{
|
|
|
|
|
QDialog::reject();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto result = QMessageBox::warning(
|
|
|
|
|
this,
|
|
|
|
|
tr("The Path has been modified."),
|
|
|
|
|
tr("Do you want to save your changes?"),
|
|
|
|
|
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
|
|
|
|
|
QMessageBox::Save
|
|
|
|
|
);
|
|
|
|
|
switch (result)
|
|
|
|
|
{
|
|
|
|
|
case QMessageBox::Save:
|
|
|
|
|
accept();
|
|
|
|
|
return;
|
|
|
|
|
case QMessageBox::Discard:
|
|
|
|
|
QDialog::reject();
|
|
|
|
|
return;
|
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
qWarning() << "unexpected dialog result" << result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 21:49:06 +01:00
|
|
|
void PathPropertiesDialog::selectionChanged(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
{
|
|
|
|
|
m_ui->widget->setSelectedIndex(std::nullopt);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_ui->widget->setSelectedIndex(index.row());
|
|
|
|
|
|
|
|
|
|
updatePointFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::selectedPointChanged(const std::optional<std::size_t> &index)
|
|
|
|
|
{
|
|
|
|
|
m_ui->treeView->setCurrentIndex(index ? m_pointsModel->index(*index, 0, {}) : QModelIndex{});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::dataChanged(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (index == m_ui->treeView->currentIndex())
|
|
|
|
|
updatePointFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::cursorMoved(const QPoint &point)
|
|
|
|
|
{
|
|
|
|
|
m_labelX->setText(tr("X: %0").arg(point.x()));
|
|
|
|
|
m_labelY->setText(tr("Y: %0").arg(point.y()));
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 23:05:01 +01:00
|
|
|
void PathPropertiesDialog::add()
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::insert()
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::delete_()
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 06:42:13 +01:00
|
|
|
void PathPropertiesDialog::changed()
|
|
|
|
|
{
|
|
|
|
|
if (!m_unsavedChanges)
|
|
|
|
|
{
|
|
|
|
|
m_unsavedChanges = true;
|
2022-01-09 23:05:01 +01:00
|
|
|
updateTitle();
|
2022-01-09 06:42:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-09 23:05:01 +01:00
|
|
|
|
|
|
|
|
void PathPropertiesDialog::pathNameChanged(const Path &path)
|
|
|
|
|
{
|
|
|
|
|
if (&path != &m_path)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QSignalBlocker blocker{m_ui->lineEditName};
|
|
|
|
|
m_ui->lineEditName->setText(path.name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTitle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathPropertiesDialog::updateTitle()
|
|
|
|
|
{
|
|
|
|
|
setWindowTitle(tr("Path Properties: %0%1")
|
|
|
|
|
.arg(m_path.name)
|
|
|
|
|
.arg(m_unsavedChanges ? tr("*") : QString{})
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-01-10 21:49:06 +01:00
|
|
|
|
|
|
|
|
void PathPropertiesDialog::updatePointFields()
|
|
|
|
|
{
|
|
|
|
|
const auto point = m_pointsModel->getPoint(m_ui->treeView->currentIndex());
|
|
|
|
|
m_ui->spinBoxX->setValue(point.point.x());
|
|
|
|
|
m_ui->spinBoxY->setValue(point.point.y());
|
|
|
|
|
m_ui->spinBoxSp->setValue(point.sp);
|
|
|
|
|
}
|