Reload beam's model properties after the change of beam type or "force horizontal" apply
This commit is contained in:
parent
9850337616
commit
acf07f006e
9 changed files with 54 additions and 32 deletions
|
@ -8,7 +8,8 @@ AbstractInspectorModel::AbstractInspectorModel(QObject* parent, IElementReposito
|
|||
if (!m_repository)
|
||||
return;
|
||||
|
||||
connect(m_repository->getQObject(), SIGNAL(elementsUpdated()), this, SLOT(onRepositoryUpdated()));
|
||||
connect(m_repository->getQObject(), SIGNAL(elementsUpdated()), this, SLOT(updateProperties()));
|
||||
connect(this, &AbstractInspectorModel::requestReloadPropertyItems, this, &AbstractInspectorModel::updateProperties);
|
||||
}
|
||||
|
||||
void AbstractInspectorModel::requestResetToDefaults()
|
||||
|
@ -99,18 +100,13 @@ void AbstractInspectorModel::setIsEmpty(bool isEmpty)
|
|||
emit isEmptyChanged(m_isEmpty);
|
||||
}
|
||||
|
||||
void AbstractInspectorModel::onRepositoryUpdated()
|
||||
{
|
||||
updateProperties();
|
||||
|
||||
setIsEmpty(!hasAcceptableElements());
|
||||
}
|
||||
|
||||
void AbstractInspectorModel::updateProperties()
|
||||
{
|
||||
requestElements();
|
||||
|
||||
if (hasAcceptableElements()) {
|
||||
setIsEmpty(!hasAcceptableElements());
|
||||
|
||||
if (!isEmpty()) {
|
||||
loadProperties();
|
||||
} else {
|
||||
resetProperties();
|
||||
|
|
|
@ -53,6 +53,8 @@ signals:
|
|||
void modelReseted();
|
||||
void isEmptyChanged(bool isEmpty);
|
||||
|
||||
void requestReloadPropertyItems();
|
||||
|
||||
protected:
|
||||
PropertyItem* buildPropertyItem(const Ms::Pid& pid,
|
||||
std::function<void(const int propertyId, const QVariant& newValue)> onPropertyChangedCallBack = nullptr);
|
||||
|
@ -72,11 +74,9 @@ protected:
|
|||
protected slots:
|
||||
void onResetToDefaults(const QList<Ms::Pid>& pidList);
|
||||
void onPropertyValueChanged(const Ms::Pid pid, const QVariant& newValue);
|
||||
void onRepositoryUpdated();
|
||||
|
||||
private:
|
||||
void updateProperties();
|
||||
|
||||
private:
|
||||
QString m_title;
|
||||
InspectorModelType m_type;
|
||||
bool m_isEmpty = false;
|
||||
|
|
|
@ -43,11 +43,11 @@ void BeamSettingsModel::loadProperties()
|
|||
});
|
||||
|
||||
loadPropertyItem(m_beamVectorX, [this] (const QVariant& elementPropertyValue) -> QVariant {
|
||||
return elementPropertyValue.toPointF().x();
|
||||
return QString::number(elementPropertyValue.toPointF().x(), 'f', 2).toDouble();
|
||||
});
|
||||
|
||||
loadPropertyItem(m_beamVectorY, [this] (const QVariant& elementPropertyValue) -> QVariant {
|
||||
return elementPropertyValue.toPointF().y();
|
||||
return QString::number(elementPropertyValue.toPointF().y(), 'f', 2).toDouble();
|
||||
});
|
||||
|
||||
m_cachedBeamVector.setX(m_beamVectorX->value().toDouble());
|
||||
|
@ -71,16 +71,9 @@ void BeamSettingsModel::resetProperties()
|
|||
|
||||
void BeamSettingsModel::forceHorizontal()
|
||||
{
|
||||
qreal currentX = m_beamVectorX->value().toDouble();
|
||||
qreal currentY = m_beamVectorY->value().toDouble();
|
||||
onPropertyValueChanged(Ms::Pid::BEAM_NO_SLOPE, true);
|
||||
|
||||
qreal maxValue = qMax(qAbs(currentX), qAbs(currentY));
|
||||
|
||||
if (qFuzzyCompare(qAbs(currentX), maxValue)) {
|
||||
m_beamVectorY->setValue(currentX);
|
||||
} else {
|
||||
m_beamVectorX->setValue(currentY);
|
||||
}
|
||||
emit requestReloadPropertyItems();
|
||||
}
|
||||
|
||||
void BeamSettingsModel::updateBeamHeight(const qreal& x, const qreal& y)
|
||||
|
@ -201,11 +194,13 @@ void BeamSettingsModel::setBeamModesModel(BeamModesModel* beamModesModel)
|
|||
{
|
||||
m_beamModesModel = beamModesModel;
|
||||
|
||||
connect(m_beamModesModel->isFeatheringAvailable(), &PropertyItem::valueChanged, this, [this] (const QVariant& newValue) {
|
||||
connect(m_beamModesModel->isFeatheringAvailable(), &PropertyItem::propertyModified, this, [this] (const QVariant& newValue) {
|
||||
if (!newValue.toBool()) {
|
||||
setFeatheringMode(static_cast<int>(BeamTypes::FEATHERING_NONE));
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_beamModesModel->mode(), &PropertyItem::propertyModified, this, &AbstractInspectorModel::requestReloadPropertyItems);
|
||||
|
||||
emit beamModesModelChanged(m_beamModesModel);
|
||||
}
|
||||
|
|
|
@ -66,5 +66,5 @@ int BeamModeListModel::indexOfBeamMode(const BeamTypes::Mode beamMode) const
|
|||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,12 @@ void BeamModesModel::setModeListModel(BeamModeListModel* modeListModel)
|
|||
});
|
||||
|
||||
connect(m_mode, &PropertyItem::valueChanged, [this] (const QVariant& beamMode) {
|
||||
m_modeListModel->setSelectedBeamMode(static_cast<BeamTypes::Mode>(beamMode.toInt()));
|
||||
|
||||
if (m_mode->isUndefined()) {
|
||||
m_modeListModel->setSelectedBeamMode(BeamTypes::MODE_INVALID);
|
||||
} else {
|
||||
m_modeListModel->setSelectedBeamMode(static_cast<BeamTypes::Mode>(beamMode.toInt()));
|
||||
}
|
||||
});
|
||||
|
||||
emit modeListModelChanged(m_modeListModel);
|
||||
|
|
|
@ -13,8 +13,6 @@ FocusableItem {
|
|||
implicitHeight: contentColumn.height
|
||||
width: parent.width
|
||||
|
||||
enabled: model ? !model.isEmpty : false
|
||||
|
||||
Column {
|
||||
id: contentColumn
|
||||
|
||||
|
@ -32,7 +30,7 @@ FocusableItem {
|
|||
id: beamTypesGridView
|
||||
|
||||
beamTypesModel: beamModesModel ? beamModesModel.modeListModel : null
|
||||
isIndeterminate: beamModesModel ? beamModesModel.mode.isUndefined : false
|
||||
enabled: beamModesModel ? !beamModesModel.isEmpty : false
|
||||
}
|
||||
|
||||
Column {
|
||||
|
@ -41,6 +39,8 @@ FocusableItem {
|
|||
height: implicitHeight
|
||||
width: parent.width
|
||||
|
||||
enabled: model ? !model.isEmpty : false
|
||||
|
||||
SeparatorLine {
|
||||
anchors.margins: -10
|
||||
visible: featheringControlsColumn.visible
|
||||
|
@ -150,7 +150,7 @@ FocusableItem {
|
|||
}
|
||||
|
||||
FlatButton {
|
||||
text: qsTr("Forse horizontal")
|
||||
text: qsTr("Force horizontal")
|
||||
|
||||
onClicked: {
|
||||
if (!model)
|
||||
|
|
|
@ -74,6 +74,6 @@ FocusableItem {
|
|||
radius: 2
|
||||
}
|
||||
|
||||
currentIndex: beamTypesModel && !isIndeterminate ? beamTypesModel.selectedTypeIndex : -1
|
||||
currentIndex: beamTypesModel ? beamTypesModel.selectedTypeIndex : -1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,6 +254,26 @@ bool Beam::isNoSlope() const
|
|||
return qFuzzyCompare(currentBeamPos.x(), currentBeamPos.y());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// alignBeamPosition
|
||||
//---------------------------------------------------------
|
||||
|
||||
void Beam::alignBeamPosition()
|
||||
{
|
||||
QPointF currentBeamPos = beamPos();
|
||||
|
||||
qreal currentX = currentBeamPos.x();
|
||||
qreal currentY = currentBeamPos.y();
|
||||
|
||||
qreal maxValue = qMax(qAbs(currentX), qAbs(currentY));
|
||||
|
||||
if (qFuzzyCompare(qAbs(currentX), maxValue)) {
|
||||
setBeamPos(QPointF(currentX, currentX));
|
||||
} else {
|
||||
setBeamPos(QPointF(currentY, currentY));
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// move
|
||||
//---------------------------------------------------------
|
||||
|
@ -2478,9 +2498,14 @@ bool Beam::setProperty(Pid propertyId, const QVariant& v)
|
|||
if (userModified())
|
||||
setBeamPos(v.toPointF());
|
||||
break;
|
||||
case Pid::BEAM_NO_SLOPE:
|
||||
if (v.toBool())
|
||||
alignBeamPosition();
|
||||
break;
|
||||
default:
|
||||
if (!Element::setProperty(propertyId, v))
|
||||
if (!Element::setProperty(propertyId, v)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
triggerLayout();
|
||||
|
|
|
@ -125,6 +125,7 @@ public:
|
|||
void setId(int i) const { _id = i; }
|
||||
int id() const { return _id; }
|
||||
bool isNoSlope() const;
|
||||
void alignBeamPosition();
|
||||
|
||||
void setBeamDirection(Direction d);
|
||||
Direction beamDirection() const { return _direction; }
|
||||
|
|
Loading…
Reference in a new issue