# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2016-09-17 12:03:28 # Node ID 40b3b165830c6c0bf34e0d6c72bc451254965c53 # Parent 52acb9a759b79feb555a5acdcbccb5da677c12f5 show snapshot name with an asterisk if not saved diff --git a/src/snapshot.cpp b/src/snapshot.cpp --- a/src/snapshot.cpp +++ b/src/snapshot.cpp @@ -26,7 +26,7 @@ Snapshot::Snapshot(QMainWindow* parent, QString name) : QObject(parent), - _showAction(name, this), + _showAction(this), _deleteAction("Delete", this) { _name = name; @@ -34,6 +34,7 @@ Snapshot::Snapshot(QMainWindow* parent, view = NULL; mainWindow = parent; + _showAction.setText(displayName()); connect(&_showAction, &QAction::triggered, this, &Snapshot::show); _deleteAction.setToolTip(QString("Delete ") + _name); @@ -86,6 +87,18 @@ QString Snapshot::name() return _name; } +QString Snapshot::displayName() +{ + if (_saved) + { + return name(); + } + else + { + return name() + "*"; + } +} + void Snapshot::setName(QString name) { _name = name; @@ -141,6 +154,7 @@ void Snapshot::save(QString fileName) else { _saved = true; + _showAction.setText(displayName()); } } else diff --git a/src/snapshot.h b/src/snapshot.h --- a/src/snapshot.h +++ b/src/snapshot.h @@ -42,6 +42,7 @@ public: QAction* deleteAction(); QString name(); + QString displayName(); ///< `name()` plus '*' if snapshot is not saved void setName(QString name); void setChannelNames(QStringList names); // must be called when setting data! QString channelName(unsigned channel); diff --git a/src/snapshotview.cpp b/src/snapshotview.cpp --- a/src/snapshotview.cpp +++ b/src/snapshotview.cpp @@ -32,7 +32,7 @@ SnapshotView::SnapshotView(QWidget *pare plotMan = new PlotManager(ui->plotArea); ui->menuSnapshot->insertAction(ui->actionClose, snapshot->deleteAction()); - this->setWindowTitle(snapshot->name()); + this->setWindowTitle(snapshot->displayName()); // initialize curves unsigned numOfChannels = snapshot->data.size(); @@ -49,6 +49,7 @@ SnapshotView::SnapshotView(QWidget *pare connect(ui->actionExport, &QAction::triggered, this, &SnapshotView::save); + // add 'View' menu items for (auto a : plotMan->menuActions()) { ui->menuView->addAction(a); @@ -79,14 +80,15 @@ void SnapshotView::showRenameDialog() void SnapshotView::renameSnapshot(QString name) { _snapshot->setName(name); - setWindowTitle(name); + setWindowTitle(_snapshot->displayName()); } void SnapshotView::save() { QString fileName = QFileDialog::getSaveFileName(this, tr("Export CSV File")); - if (fileName.isNull()) return; // user canceled _snapshot->save(fileName); + + setWindowTitle(_snapshot->displayName()); }