fix: cpn: custom curve edit default points and expand curve tab details column (#1815)

This commit is contained in:
Neil Horne
2022-04-14 10:16:57 +10:00
committed by GitHub
parent 6da73376e1
commit dc3b55771f
5 changed files with 58 additions and 35 deletions
+9 -8
View File
@@ -36,18 +36,19 @@ void CurveData::clear(int count)
void CurveData::init()
{
float incr = 200.0 / ((float)count - 1.0);
memset(points, 0, sizeof(CurvePoint) * CPN_MAX_POINTS);
// points[0].x must be -100
for (int i = 0; i < count; i++) {
if (i < count - 1)
points[i].x = -100 + (int)(incr * i);
else
points[i].x = 100; // points[count - 1].x must be +100 do not risk a rounding issue using incr
float incr = 200.0 / (float)(count - 1);
for (int i = 1; i < (count - 1); i++) {
points[i].x = -100 + (int)(incr * (float)i);
points[i].y = points[i].x;
}
points[0].x = -100;
points[0].y = -100;
points[count - 1].x = 100;
points[count - 1].y = 100;
}
bool CurveData::isEmpty() const
+8
View File
@@ -672,6 +672,14 @@ void TableLayout::pushColumnsLeft(int col)
#endif
}
void TableLayout::setColumnStretch(int col, int stretch)
{
#if defined(TABLE_LAYOUT)
#else
gridWidget->setColumnStretch(col, stretch);
#endif
}
QString Helpers::getChecklistsPath()
{
return QDir::toNativeSeparators(g.profile[g.id()].sdPath() + "/MODELS/"); // TODO : add sub folder to constants
+1
View File
@@ -196,6 +196,7 @@ public:
void setColumnWidth(int col, QString str);
void pushRowsUp(int row);
void pushColumnsLeft(int col);
void setColumnStretch(int col, int stretch);
private:
#if defined(TABLE_LAYOUT)
+3
View File
@@ -62,6 +62,7 @@ CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings &
connect(image[i], &CurveImageWidget::doubleClicked, this, &CurvesPanel::on_curveImageDoubleClicked);
tableLayout->addWidget(i, col++, image[i]);
tableLayout->setColumnStretch(col, 1);
grp[i] = new QWidget(); // layouts are not hideable so use widget as parent for grid
@@ -80,6 +81,8 @@ CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings &
numpoints[i] = new QLabel();
grid[i]->addWidget(numpoints[i], row, 1);
points[i] = new QLabel();
points[i]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
points[i]->setWordWrap(true);
grid[i]->addWidget(points[i], row++, 2, Qt::AlignLeft);
grid[i]->addWidget(new QLabel(tr("Smooth:")), row, 0, Qt::AlignLeft);
+37 -27
View File
@@ -333,15 +333,19 @@ void CurveDialog::updateCurvePoints()
for (int i = 0; i < count; i++) {
spny[i]->show();
spny[i]->setValue(curve.points[i].y);
if (curve.type == CurveData::CURVE_TYPE_CUSTOM) {
spnx[i]->show();
if (i == 0 || i == count - 1) {
spnx[i]->setDisabled(true);
spnx[i]->setDisabled(false);
spnx[i]->setMaximum(+100);
spnx[i]->setMinimum(-100);
spnx[i]->setDisabled(true);
}
else {
spnx[i]->setDisabled(false);
spnx[i]->setMaximum(+100);
spnx[i]->setMinimum(-100);
spnx[i]->setMaximum(curve.points[i + 1].x);
spnx[i]->setMinimum(curve.points[i - 1].x);
}
@@ -432,7 +436,8 @@ void CurveDialog::on_curvePointsChanged(int index)
if (allowCurveType(numpoints, curve.type)) {
curve.count = numpoints;
curve.init();
update();
updateCurve();
updateCurvePoints();
}
else {
updateCurveType();
@@ -447,9 +452,9 @@ void CurveDialog::on_curveTypeChanged(int index)
int numpoints = ui->curvePoints->itemData(ui->curvePoints->currentIndex()).toInt();
if (allowCurveType(numpoints, type)) {
//curve.clear(numpoints);
curve.type = type;
//curve.init();
curve.count = numpoints;
curve.init();
update();
}
else {
@@ -463,6 +468,7 @@ void CurveDialog::resizeEvent(QResizeEvent *event)
QRect qr = ui->curvePreview->contentsRect();
ui->curvePreview->scene()->setSceneRect(GFX_MARGIN, GFX_MARGIN, qr.width() - GFX_MARGIN * 2, qr.height() - GFX_MARGIN * 2);
updateCurve();
updateCurvePoints();
}
void CurveDialog::on_curveTemplateChanged(int index)
@@ -539,37 +545,41 @@ void CurveDialog::onNodeDelete()
curve.points[numpoints].x = 0;
curve.points[numpoints].y = 0;
curve.count = numpoints;
update();
updateCurve();
updateCurvePoints();
}
}
void CurveDialog::onSceneNewPoint(int x, int y)
{
if ((curve.type == CurveData::CURVE_TYPE_CUSTOM) && (curve.count < CPN_MAX_POINTS)) {
int newidx = 0;
int numpoints = curve.count;
if (x < curve.points[0].x) {
newidx = 0;
}
else if (x > curve.points[numpoints - 1].x) {
newidx = numpoints;
}
else {
for (int i = 0; i < numpoints; i++) {
if (x < curve.points[i].x) {
newidx = i;
break;
if (!lock) {
if ((curve.type == CurveData::CURVE_TYPE_CUSTOM) && (curve.count < CPN_MAX_POINTS)) {
int newidx = 0;
int numpoints = curve.count;
if (x < curve.points[0].x) {
newidx = 0;
}
else if (x > curve.points[numpoints - 1].x) {
newidx = numpoints;
}
else {
for (int i = 0; i < numpoints; i++) {
if (x < curve.points[i].x) {
newidx = i;
break;
}
}
}
numpoints++;
curve.count = numpoints;
for (int idx = (numpoints - 1); idx > newidx; idx--) {
curve.points[idx] = curve.points[idx - 1];
}
curve.points[newidx].x = x;
curve.points[newidx].y = y;
updateCurve();
updateCurvePoints();
}
numpoints++;
curve.count = numpoints;
for (int idx = (numpoints - 1); idx > newidx; idx--) {
curve.points[idx] = curve.points[idx - 1];
}
curve.points[newidx].x = x;
curve.points[newidx].y = y;
update();
}
}