14class ChangeQObjectPropertyCommand :
public QUndoCommand
17 ChangeQObjectPropertyCommand (
19 QString property_name,
21 : object_ (
object), property_name_ (property_name),
22 original_value_ (
object.property (property_name.toLatin1 ().data ())),
23 value_ (std::move (value))
25 setText (QObject::tr (
"Change %1").arg (property_name_));
28 int id ()
const override {
return 1762957285; }
29 bool mergeWith (
const QUndoCommand * other)
override
31 if (other->id () != id ())
36 const auto * other_cmd =
37 dynamic_cast<const ChangeQObjectPropertyCommand *
> (other);
38 const auto cur_time = std::chrono::steady_clock::now ();
39 const auto duration = cur_time - last_redo_timestamp_;
41 std::chrono::duration_cast<std::chrono::milliseconds> (duration).count ()
49 &object_ != &other_cmd->object_
50 || property_name_ != other_cmd->property_name_)
53 last_redo_timestamp_ = cur_time;
54 value_ = other_cmd->value_;
60 object_.setProperty (property_name_.toLatin1 ().data (), original_value_);
65 object_.setProperty (property_name_.toLatin1 ().data (), value_);
66 last_redo_timestamp_ = std::chrono::steady_clock::now ();
71 QString property_name_;
72 QVariant original_value_;
74 std::chrono::time_point<std::chrono::steady_clock> last_redo_timestamp_;