cabana: show command's text in statusbar (#27398)

old-commit-hash: 10ed70d952
beeps
Dean Lee 2 years ago committed by GitHub
parent 3d8bc65317
commit 9b9a90bf7a
  1. 24
      tools/cabana/commands.cc
  2. 4
      tools/cabana/commands.h
  3. 22
      tools/cabana/mainwin.cc
  4. 3
      tools/cabana/mainwin.h

@ -4,24 +4,26 @@
// EditMsgCommand // EditMsgCommand
EditMsgCommand::EditMsgCommand(const MessageId &id, const QString &title, int size, QUndoCommand *parent) EditMsgCommand::EditMsgCommand(const MessageId &id, const QString &name, int size, QUndoCommand *parent)
: id(id), new_title(title), new_size(size), QUndoCommand(parent) { : id(id), new_name(name), new_size(size), QUndoCommand(parent) {
if (auto msg = dbc()->msg(id)) { if (auto msg = dbc()->msg(id)) {
old_title = msg->name; old_name = msg->name;
old_size = msg->size; old_size = msg->size;
setText(QObject::tr("edit message %1:%2").arg(name).arg(id.address));
} else {
setText(QObject::tr("new message %1:%2").arg(name).arg(id.address));
} }
setText(QObject::tr("Edit message %1:%2").arg(id.address).arg(title));
} }
void EditMsgCommand::undo() { void EditMsgCommand::undo() {
if (old_title.isEmpty()) if (old_name.isEmpty())
dbc()->removeMsg(id); dbc()->removeMsg(id);
else else
dbc()->updateMsg(id, old_title, old_size); dbc()->updateMsg(id, old_name, old_size);
} }
void EditMsgCommand::redo() { void EditMsgCommand::redo() {
dbc()->updateMsg(id, new_title, new_size); dbc()->updateMsg(id, new_name, new_size);
} }
// RemoveMsgCommand // RemoveMsgCommand
@ -29,7 +31,7 @@ void EditMsgCommand::redo() {
RemoveMsgCommand::RemoveMsgCommand(const MessageId &id, QUndoCommand *parent) : id(id), QUndoCommand(parent) { RemoveMsgCommand::RemoveMsgCommand(const MessageId &id, QUndoCommand *parent) : id(id), QUndoCommand(parent) {
if (auto msg = dbc()->msg(id)) { if (auto msg = dbc()->msg(id)) {
message = *msg; message = *msg;
setText(QObject::tr("Remove message %1:%2").arg(id.address).arg(message.name)); setText(QObject::tr("remove message %1:%2").arg(message.name).arg(id.address));
} }
} }
@ -50,7 +52,7 @@ void RemoveMsgCommand::redo() {
AddSigCommand::AddSigCommand(const MessageId &id, const Signal &sig, QUndoCommand *parent) AddSigCommand::AddSigCommand(const MessageId &id, const Signal &sig, QUndoCommand *parent)
: id(id), signal(sig), QUndoCommand(parent) { : id(id), signal(sig), QUndoCommand(parent) {
setText(QObject::tr("Add signal %1 to %2").arg(sig.name).arg(id.address)); setText(QObject::tr("add signal %1 to %2:%3").arg(sig.name).arg(msgName(id)).arg(id.address));
} }
void AddSigCommand::undo() { dbc()->removeSignal(id, signal.name); } void AddSigCommand::undo() { dbc()->removeSignal(id, signal.name); }
@ -60,7 +62,7 @@ void AddSigCommand::redo() { dbc()->addSignal(id, signal); }
RemoveSigCommand::RemoveSigCommand(const MessageId &id, const Signal *sig, QUndoCommand *parent) RemoveSigCommand::RemoveSigCommand(const MessageId &id, const Signal *sig, QUndoCommand *parent)
: id(id), signal(*sig), QUndoCommand(parent) { : id(id), signal(*sig), QUndoCommand(parent) {
setText(QObject::tr("Remove signal %1 from %2").arg(signal.name).arg(id.address)); setText(QObject::tr("remove signal %1 from %2:%3").arg(signal.name).arg(msgName(id)).arg(id.address));
} }
void RemoveSigCommand::undo() { dbc()->addSignal(id, signal); } void RemoveSigCommand::undo() { dbc()->addSignal(id, signal); }
@ -70,7 +72,7 @@ void RemoveSigCommand::redo() { dbc()->removeSignal(id, signal.name); }
EditSignalCommand::EditSignalCommand(const MessageId &id, const Signal *sig, const Signal &new_sig, QUndoCommand *parent) EditSignalCommand::EditSignalCommand(const MessageId &id, const Signal *sig, const Signal &new_sig, QUndoCommand *parent)
: id(id), old_signal(*sig), new_signal(new_sig), QUndoCommand(parent) { : id(id), old_signal(*sig), new_signal(new_sig), QUndoCommand(parent) {
setText(QObject::tr("Edit signal %1").arg(old_signal.name)); setText(QObject::tr("edit signal %1 in %2:%3").arg(old_signal.name).arg(msgName(id)).arg(id.address));
} }
void EditSignalCommand::undo() { dbc()->updateSignal(id, new_signal.name, old_signal); } void EditSignalCommand::undo() { dbc()->updateSignal(id, new_signal.name, old_signal); }

@ -9,13 +9,13 @@ using namespace dbcmanager;
class EditMsgCommand : public QUndoCommand { class EditMsgCommand : public QUndoCommand {
public: public:
EditMsgCommand(const MessageId &id, const QString &title, int size, QUndoCommand *parent = nullptr); EditMsgCommand(const MessageId &id, const QString &name, int size, QUndoCommand *parent = nullptr);
void undo() override; void undo() override;
void redo() override; void redo() override;
private: private:
const MessageId id; const MessageId id;
QString old_title, new_title; QString old_name, new_name;
int old_size = 0, new_size = 0; int old_size = 0, new_size = 0;
}; };

@ -65,6 +65,7 @@ MainWindow::MainWindow() : QMainWindow() {
QObject::connect(can, &AbstractStream::streamStarted, this, &MainWindow::loadDBCFromFingerprint); QObject::connect(can, &AbstractStream::streamStarted, this, &MainWindow::loadDBCFromFingerprint);
QObject::connect(dbc(), &DBCManager::DBCFileChanged, this, &MainWindow::DBCFileChanged); QObject::connect(dbc(), &DBCManager::DBCFileChanged, this, &MainWindow::DBCFileChanged);
QObject::connect(UndoStack::instance(), &QUndoStack::cleanChanged, this, &MainWindow::undoStackCleanChanged); QObject::connect(UndoStack::instance(), &QUndoStack::cleanChanged, this, &MainWindow::undoStackCleanChanged);
QObject::connect(UndoStack::instance(), &QUndoStack::indexChanged, this, &MainWindow::undoStackIndexChanged);
} }
void MainWindow::createActions() { void MainWindow::createActions() {
@ -186,7 +187,28 @@ void MainWindow::createShortcuts() {
// TODO: add more shortcuts here. // TODO: add more shortcuts here.
} }
void MainWindow::undoStackIndexChanged(int index) {
int count = UndoStack::instance()->count();
if (count >= 0) {
QString command_text;
if (index == count) {
command_text = (count == prev_undostack_count ? "Redo " : "") + UndoStack::instance()->text(index - 1);
} else if (index < prev_undostack_index) {
command_text = tr("Undo %1").arg(UndoStack::instance()->text(index));
} else if (index > prev_undostack_index) {
command_text = tr("Redo %1").arg(UndoStack::instance()->text(index - 1));
}
statusBar()->showMessage(command_text, 2000);
}
prev_undostack_index = index;
prev_undostack_count = count;
}
void MainWindow::undoStackCleanChanged(bool clean) { void MainWindow::undoStackCleanChanged(bool clean) {
if (clean) {
prev_undostack_index = 0;
prev_undostack_count = 0;
}
setWindowModified(!clean); setWindowModified(!clean);
} }

@ -54,6 +54,7 @@ protected:
void setOption(); void setOption();
void findSimilarBits(); void findSimilarBits();
void undoStackCleanChanged(bool clean); void undoStackCleanChanged(bool clean);
void undoStackIndexChanged(int index);
void onlineHelp(); void onlineHelp();
VideoWidget *video_widget = nullptr; VideoWidget *video_widget = nullptr;
@ -70,6 +71,8 @@ protected:
enum { MAX_RECENT_FILES = 15 }; enum { MAX_RECENT_FILES = 15 };
QAction *recent_files_acts[MAX_RECENT_FILES] = {}; QAction *recent_files_acts[MAX_RECENT_FILES] = {};
QMenu *open_recent_menu = nullptr; QMenu *open_recent_menu = nullptr;
int prev_undostack_index = 0;
int prev_undostack_count = 0;
friend class OnlineHelp; friend class OnlineHelp;
}; };

Loading…
Cancel
Save