96 lines
2.0 KiB
C++
96 lines
2.0 KiB
C++
|
|
#include <XCEngine/UI/Widgets/UIPropertyEditModel.h>
|
||
|
|
|
||
|
|
#include <utility>
|
||
|
|
|
||
|
|
namespace XCEngine {
|
||
|
|
namespace UI {
|
||
|
|
namespace Widgets {
|
||
|
|
|
||
|
|
bool UIPropertyEditModel::HasActiveEdit() const {
|
||
|
|
return !m_activeFieldId.empty();
|
||
|
|
}
|
||
|
|
|
||
|
|
const std::string& UIPropertyEditModel::GetActiveFieldId() const {
|
||
|
|
return m_activeFieldId;
|
||
|
|
}
|
||
|
|
|
||
|
|
const std::string& UIPropertyEditModel::GetStagedValue() const {
|
||
|
|
return m_stagedValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool UIPropertyEditModel::IsDirty() const {
|
||
|
|
return m_dirty;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool UIPropertyEditModel::BeginEdit(std::string fieldId, std::string initialValue) {
|
||
|
|
if (fieldId.empty()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
const bool stateChanged =
|
||
|
|
m_activeFieldId != fieldId ||
|
||
|
|
m_baselineValue != initialValue ||
|
||
|
|
m_stagedValue != initialValue ||
|
||
|
|
m_dirty;
|
||
|
|
if (!stateChanged) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
m_activeFieldId = std::move(fieldId);
|
||
|
|
m_baselineValue = std::move(initialValue);
|
||
|
|
m_stagedValue = m_baselineValue;
|
||
|
|
m_dirty = false;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool UIPropertyEditModel::UpdateStagedValue(std::string stagedValue) {
|
||
|
|
if (!HasActiveEdit()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (m_stagedValue == stagedValue) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
m_stagedValue = std::move(stagedValue);
|
||
|
|
m_dirty = (m_stagedValue != m_baselineValue);
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool UIPropertyEditModel::CommitEdit(
|
||
|
|
std::string* outFieldId,
|
||
|
|
std::string* outCommittedValue) {
|
||
|
|
if (!HasActiveEdit()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (outFieldId != nullptr) {
|
||
|
|
*outFieldId = m_activeFieldId;
|
||
|
|
}
|
||
|
|
if (outCommittedValue != nullptr) {
|
||
|
|
*outCommittedValue = m_stagedValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
m_activeFieldId.clear();
|
||
|
|
m_baselineValue.clear();
|
||
|
|
m_stagedValue.clear();
|
||
|
|
m_dirty = false;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool UIPropertyEditModel::CancelEdit() {
|
||
|
|
if (!HasActiveEdit()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
m_activeFieldId.clear();
|
||
|
|
m_baselineValue.clear();
|
||
|
|
m_stagedValue.clear();
|
||
|
|
m_dirty = false;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace Widgets
|
||
|
|
} // namespace UI
|
||
|
|
} // namespace XCEngine
|