wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
DolphinCommands.cpp
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
5
7
8SetCellsCommand::SetCellsCommand(SignalModel *model, const QList<QPair<int, int>> &cells,
9 const QList<int> &oldValues, std::function<void()> onApplied,
10 QUndoCommand *parent)
11 : QUndoCommand(parent)
12 , m_model(model)
13 , m_cells(cells)
14 , m_oldValues(oldValues)
15 , m_onApplied(std::move(onApplied))
16{
17 setText(QObject::tr("Edit waveform"));
18
19 // The caller already applied the edit before constructing this command (same contract as
20 // the main Scene's UpdateCommand) -- snapshot the resulting values as "new" here.
21 m_newValues.reserve(m_cells.size());
22 for (const auto &cell : m_cells) {
23 m_newValues.append(m_model->value(cell.first, cell.second));
24 }
25}
26
28{
29 applyValues(m_newValues);
30}
31
33{
34 applyValues(m_oldValues);
35}
36
37void SetCellsCommand::applyValues(const QList<int> &values)
38{
39 for (int i = 0; i < m_cells.size(); ++i) {
40 m_model->setValue(m_cells.at(i).first, m_cells.at(i).second, values.at(i));
41 }
42
43 if (m_onApplied) {
44 m_onApplied();
45 }
46}
DolphinCommands: undo/redo commands for the beWavedDolphin waveform editor.
SignalModel for the beWavedDolphin waveform table.
void undo() override
void redo() override
SetCellsCommand(SignalModel *model, const QList< QPair< int, int > > &cells, const QList< int > &oldValues, std::function< void()> onApplied, QUndoCommand *parent=nullptr)
QStandardItemModel subclass that makes all cells non-editable.
Definition SignalModel.h:21
void setValue(int row, int col, int value)
Sets the logic value (0/1) of the cell at (row, col).