return nullptr;
}
-shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
- views::ViewType type, Session &session)
+shared_ptr<views::ViewBase> MainWindow::add_view(views::ViewType type,
+ Session &session)
{
GlobalSettings settings;
shared_ptr<views::ViewBase> v;
shared_ptr<MainBar> main_bar = session.main_bar();
+ // Only use the view type in the name if it's not the main view
+ QString title;
+ if (main_bar)
+ title = QString("%1 (%2)").arg(session.name()).arg(views::ViewTypeNames[type]);
+ else
+ title = session.name();
+
QDockWidget* dock = new QDockWidget(title, main_window);
dock->setObjectName(title);
main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
if (type == views::ViewTypeTrace)
// This view will be the main view if there's no main bar yet
- v = make_shared<views::trace::View>(session,
- (main_bar ? false : true), dock_main);
+ v = make_shared<views::trace::View>(session, (main_bar ? false : true), dock_main);
#ifdef ENABLE_DECODE
if (type == views::ViewTypeDecoderOutput)
v = make_shared<views::decoder_output::View>(session, false, dock_main);
dock_main->addToolBar(main_bar.get());
session.set_main_bar(main_bar);
- connect(main_bar.get(), SIGNAL(new_view(Session*)),
- this, SLOT(on_new_view(Session*)));
+ connect(main_bar.get(), SIGNAL(new_view(Session*, int)),
+ this, SLOT(on_new_view(Session*, int)));
connect(main_bar.get(), SIGNAL(show_decoder_selector(Session*)),
this, SLOT(on_show_decoder_selector(Session*)));
shared_ptr<Session> session = make_shared<Session>(device_manager_, name);
- connect(session.get(), SIGNAL(add_view(const QString&, views::ViewType, Session*)),
- this, SLOT(on_add_view(const QString&, views::ViewType, Session*)));
+ connect(session.get(), SIGNAL(add_view(views::ViewType, Session*)),
+ this, SLOT(on_add_view(views::ViewType, Session*)));
connect(session.get(), SIGNAL(name_changed()),
this, SLOT(on_session_name_changed()));
session_state_mapper_.setMapping(session.get(), session.get());
window->setDockNestingEnabled(true);
- shared_ptr<views::ViewBase> main_view =
- add_view(name, views::ViewTypeTrace, *session);
+ shared_ptr<views::ViewBase> main_view = add_view(views::ViewTypeTrace, *session);
return session;
}
return false;
}
-void MainWindow::on_add_view(const QString &title, views::ViewType type,
- Session *session)
+void MainWindow::on_add_view(views::ViewType type, Session *session)
{
// We get a pointer and need a reference
for (shared_ptr<Session>& s : sessions_)
if (s.get() == session)
- add_view(title, type, *s);
+ add_view(type, *s);
}
void MainWindow::on_focus_changed()
tr("Run") : tr("Stop"));
}
-void MainWindow::on_new_view(Session *session)
+void MainWindow::on_new_view(Session *session, int view_type)
{
// We get a pointer and need a reference
for (shared_ptr<Session>& s : sessions_)
if (s.get() == session)
- add_view(session->name(), views::ViewTypeTrace, *s);
+ add_view((views::ViewType)view_type, *s);
}
void MainWindow::on_view_close_clicked()
shared_ptr<views::ViewBase> get_active_view() const;
- shared_ptr<views::ViewBase> add_view(const QString &title,
- views::ViewType type, Session &session);
+ shared_ptr<views::ViewBase> add_view(views::ViewType type, Session &session);
void remove_view(shared_ptr<views::ViewBase> view);
virtual bool restoreState(const QByteArray &state, int version = 0);
private Q_SLOTS:
- void on_add_view(const QString &title, views::ViewType type,
- Session *session);
+ void on_add_view(views::ViewType type, Session *session);
void on_focus_changed();
void on_focused_session_changed(shared_ptr<Session> session);
void on_session_name_changed();
void on_capture_state_changed(QObject *obj);
- void on_new_view(Session *session);
+ void on_new_view(Session *session, int view_type);
void on_view_close_clicked();
void on_tab_changed(int index);
if (i > 0) {
views::ViewType type = (views::ViewType)settings.value("type").toInt();
- add_view(name_, type, this);
+ add_view(type, this);
views_.back()->restore_settings(settings);
} else
main_view_->restore_settings(settings);
void data_received();
- void add_view(const QString &title, views::ViewType type,
- Session *session);
+ void add_view(views::ViewType type, Session *session);
public Q_SLOTS:
void on_data_saved();
action_restore_setup_(new QAction(this)),
action_save_setup_(new QAction(this)),
action_connect_(new QAction(this)),
+ new_view_button_(new QToolButton()),
open_button_(new QToolButton()),
save_button_(new QToolButton()),
device_selector_(parent, session.device_manager(), action_connect_),
connect(action_connect_, SIGNAL(triggered(bool)),
this, SLOT(on_actionConnect_triggered()));
+ // New view button
+ QMenu *menu_new_view = new QMenu();
+ connect(menu_new_view, SIGNAL(triggered(QAction*)),
+ this, SLOT(on_actionNewView_triggered(QAction*)));
+
+ for (int i = 0; i < views::ViewTypeCount; i++) {
+ QAction *const action = menu_new_view->addAction(tr(views::ViewTypeNames[i]));
+ action->setData(qVariantFromValue(i));
+ }
+
+ new_view_button_->setMenu(menu_new_view);
+ new_view_button_->setDefaultAction(action_new_view_);
+ new_view_button_->setPopupMode(QToolButton::MenuButtonPopup);
+
// Open button
vector<QAction*> open_actions;
open_actions.push_back(action_open_);
commit_sample_rate();
}
-void MainBar::on_actionNewView_triggered()
+void MainBar::on_actionNewView_triggered(QAction* action)
{
- new_view(&session_);
+ if (action)
+ new_view(&session_, action->data().toInt());
+ else
+ // When the icon of the button is clicked, we create a trace view
+ new_view(&session_, views::ViewTypeTrace);
}
void MainBar::on_actionOpen_triggered()
void MainBar::add_toolbar_widgets()
{
- addAction(action_new_view_);
+ addWidget(new_view_button_);
addSeparator();
addWidget(open_button_);
addWidget(save_button_);
void on_config_changed();
- void on_actionNewView_triggered();
+ void on_actionNewView_triggered(QAction* action = nullptr);
void on_actionOpen_triggered();
void on_actionSaveAs_triggered();
bool eventFilter(QObject *watched, QEvent *event);
Q_SIGNALS:
- void new_view(Session *session);
+ void new_view(Session *session, int type);
void show_decoder_selector(Session *session);
private:
- QToolButton *open_button_, *save_button_;
+ QToolButton *new_view_button_, *open_button_, *save_button_;
pv::widgets::DeviceToolButton device_selector_;
namespace pv {
namespace views {
+const char* ViewTypeNames[ViewTypeCount] = {
+ "Trace View",
+#ifdef ENABLE_DECODE
+ "Decoder Output View"
+#endif
+};
+
const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz
ViewBase::ViewBase(Session &session, bool is_main_view, QWidget *parent) :
namespace views {
+// When adding an entry here, don't forget to update ViewTypeNames as well
enum ViewType {
ViewTypeTrace,
+#ifdef ENABLE_DECODE
ViewTypeDecoderOutput,
- ViewTypeTabularDecode
+#endif
+ ViewTypeCount // Indicates how many view types there are, must always be last
};
+extern const char* ViewTypeNames[ViewTypeCount];
+
class ViewBase : public QWidget
{
Q_OBJECT
${PROJECT_SOURCE_DIR}/pv/subwindows/decoder_selector/item.cpp
${PROJECT_SOURCE_DIR}/pv/subwindows/decoder_selector/model.cpp
${PROJECT_SOURCE_DIR}/pv/subwindows/decoder_selector/subwindow.cpp
+ ${PROJECT_SOURCE_DIR}/pv/views/decoder_output/view.cpp
${PROJECT_SOURCE_DIR}/pv/views/trace/decodetrace.cpp
${PROJECT_SOURCE_DIR}/pv/widgets/decodergroupbox.cpp
${PROJECT_SOURCE_DIR}/pv/widgets/decodermenu.cpp
list(APPEND pulseview_TEST_HEADERS
${PROJECT_SOURCE_DIR}/pv/data/decodesignal.hpp
${PROJECT_SOURCE_DIR}/pv/subwindows/decoder_selector/subwindow.hpp
+ ${PROJECT_SOURCE_DIR}/pv/views/decoder_output/view.hpp
${PROJECT_SOURCE_DIR}/pv/views/trace/decodetrace.hpp
${PROJECT_SOURCE_DIR}/pv/widgets/decodergroupbox.hpp
${PROJECT_SOURCE_DIR}/pv/widgets/decodermenu.hpp