* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "globalsettings.hpp"
-#include "application.hpp"
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/serialization/serialization.hpp>
#include <QApplication>
#include <QColor>
#include <QStyle>
#include <QtGlobal>
+#include "globalsettings.hpp"
+#include "application.hpp"
+
using std::map;
using std::pair;
using std::string;
+using std::stringstream;
using std::vector;
namespace pv {
return ret_val;
}
+void GlobalSettings::store_timestamp(QSettings &settings, const char *name, const pv::util::Timestamp &ts)
+{
+ stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << boost::serialization::make_nvp(name, ts);
+ settings.setValue(name, QString::fromStdString(ss.str()));
+}
+
+pv::util::Timestamp GlobalSettings::restore_timestamp(QSettings &settings, const char *name)
+{
+ util::Timestamp result;
+ stringstream ss;
+ ss << settings.value(name).toString().toStdString();
+
+ try {
+ boost::archive::text_iarchive ia(ss);
+ ia >> boost::serialization::make_nvp(name, result);
+ } catch (boost::archive::archive_exception&) {
+ qDebug() << "Could not restore setting" << name;
+ }
+
+ return result;
+}
+
} // namespace pv
#include <QString>
#include <QVariant>
+#include "util.hpp"
+
using std::map;
using std::pair;
using std::vector;
void undo_tracked_changes();
static void store_gvariant(QSettings &settings, GVariant *v);
-
static GVariant* restore_gvariant(QSettings &settings);
static void store_variantbase(QSettings &settings, Glib::VariantBase v);
-
static Glib::VariantBase restore_variantbase(QSettings &settings);
+ static void store_timestamp(QSettings &settings, const char *name, const pv::util::Timestamp &ts);
+ static pv::util::Timestamp restore_timestamp(QSettings &settings, const char *name);
+
private:
static vector<GlobalSettingsInterface*> callbacks_;
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include <QDebug>
-#include <QFileInfo>
-
#include <cassert>
#include <memory>
#include <mutex>
#include <sys/stat.h>
+#include <QDebug>
+#include <QFileInfo>
+
#include "devicemanager.hpp"
#include "mainwindow.hpp"
#include "session.hpp"
+#include "util.hpp"
#include "data/analog.hpp"
#include "data/analogsegment.hpp"
using Gst::Pipeline;
#endif
+using pv::util::Timestamp;
using pv::views::trace::Signal;
using pv::views::trace::AnalogSignal;
using pv::views::trace::LogicSignal;
void Session::save_setup(QSettings &settings) const
{
- int decode_signals = 0, views = 0;
+ int i = 0;
// Save channels and decoders
for (const shared_ptr<data::SignalBase>& base : signalbases_) {
#ifdef ENABLE_DECODE
if (base->is_decode_signal()) {
- settings.beginGroup("decode_signal" + QString::number(decode_signals++));
+ settings.beginGroup("decode_signal" + QString::number(i++));
base->save_settings(settings);
settings.endGroup();
} else
}
}
- settings.setValue("decode_signals", decode_signals);
+ settings.setValue("decode_signals", i);
// Save view states and their signal settings
// Note: main_view must be saved as view0
- settings.beginGroup("view" + QString::number(views++));
+ i = 0;
+ settings.beginGroup("view" + QString::number(i++));
main_view_->save_settings(settings);
settings.endGroup();
for (const shared_ptr<views::ViewBase>& view : views_) {
if (view != main_view_) {
- settings.beginGroup("view" + QString::number(views++));
+ settings.beginGroup("view" + QString::number(i++));
settings.setValue("type", view->get_type());
view->save_settings(settings);
settings.endGroup();
}
}
- settings.setValue("views", views);
+ settings.setValue("views", i);
+
+ i = 0;
+ shared_ptr<views::trace::View> tv = dynamic_pointer_cast<views::trace::View>(main_view_);
+ for (const shared_ptr<views::trace::TimeItem>& time_item : tv->time_items()) {
+
+ const shared_ptr<views::trace::Flag> flag =
+ dynamic_pointer_cast<views::trace::Flag>(time_item);
+ if (flag) {
+ if (!flag->enabled())
+ continue;
+
+ settings.beginGroup("meta_obj" + QString::number(i++));
+ settings.setValue("type", "time_marker");
+ GlobalSettings::store_timestamp(settings, "time", flag->time());
+ settings.setValue("text", flag->get_text());
+ settings.endGroup();
+ }
+ }
+
+ if (tv->cursors_shown()) {
+ settings.beginGroup("meta_obj" + QString::number(i++));
+ settings.setValue("type", "selection");
+ const shared_ptr<views::trace::CursorPair> cp = tv->cursors();
+ GlobalSettings::store_timestamp(settings, "start_time", cp->first()->time());
+ GlobalSettings::store_timestamp(settings, "end_time", cp->second()->time());
+ settings.endGroup();
+ }
+
+ settings.setValue("meta_objs", i);
}
void Session::save_settings(QSettings &settings) const
settings.endGroup();
}
+
+ // Restore meta objects like markers and cursors
+ int meta_objs = settings.value("meta_objs").toInt();
+
+ shared_ptr<views::trace::View> tv = dynamic_pointer_cast<views::trace::View>(main_view_);
+ for (int i = 0; i < meta_objs; i++) {
+ settings.beginGroup("meta_obj" + QString::number(i));
+ const QString type = settings.value("type").toString();
+
+ if (type == "time_marker") {
+ Timestamp ts = GlobalSettings::restore_timestamp(settings, "time");
+ shared_ptr<views::trace::Flag> flag = tv->add_flag(ts);
+ flag->set_text(settings.value("text").toString());
+ }
+
+ if (type == "selection") {
+ Timestamp start = GlobalSettings::restore_timestamp(settings, "start_time");
+ Timestamp end = GlobalSettings::restore_timestamp(settings, "end_time");
+ tv->set_cursors(start, end);
+ tv->show_cursors();
+ }
+
+ settings.endGroup();
+ }
}
void Session::restore_settings(QSettings &settings)
{
shared_ptr<devices::Device> device;
- QString device_type = settings.value("device_type").toString();
+ const QString device_type = settings.value("device_type").toString();
if (device_type == "hardware") {
map<string, string> dev_info;
if ((device_type == "sessionfile") || (device_type == "inputfile")) {
if (device_type == "sessionfile") {
settings.beginGroup("device");
- QString filename = settings.value("filename").toString();
+ const QString filename = settings.value("filename").toString();
settings.endGroup();
if (QFileInfo(filename).isReadable()) {
return s;
}
+void Flag::set_text(const QString &text)
+{
+ text_ = text;
+ view_.time_item_appearance_changed(true, false);
+}
+
QRectF Flag::label_rect(const QRectF &rect) const
{
QRectF r;
void Flag::on_text_changed(const QString &text)
{
- text_ = text;
- view_.time_item_appearance_changed(true, false);
+ set_text(text);
}
} // namespace trace
*/
virtual QString get_text() const override;
+ /**
+ * Sets the text to show in the marker.
+ */
+ virtual void set_text(const QString &text) override;
+
virtual pv::widgets::Popup* create_popup(QWidget *parent) override;
virtual QMenu* create_header_context_menu(QWidget *parent) override;
connect(set_zero_position, SIGNAL(triggered()), this, SLOT(on_setZeroPosition()));
menu->addAction(set_zero_position);
+ if (view_.zero_offset().convert_to<double>() != 0) {
+ QAction *const reset_zero_position = new QAction(tr("Reset zero point"), this);
+ connect(reset_zero_position, SIGNAL(triggered()), this, SLOT(on_resetZeroPosition()));
+ menu->addAction(reset_zero_position);
+ }
+
QAction *const toggle_hover_marker = new QAction(this);
connect(toggle_hover_marker, SIGNAL(triggered()), this, SLOT(on_toggleHoverMarker()));
menu->addAction(toggle_hover_marker);
view_.set_zero_position(get_absolute_time_from_x_pos(mouse_down_point_.x()));
}
+void Ruler::on_resetZeroPosition()
+{
+ view_.reset_zero_position();
+}
+
void Ruler::on_toggleHoverMarker()
{
GlobalSettings settings;
void on_createMarker();
void on_setZeroPosition();
+ void on_resetZeroPosition();
void on_toggleHoverMarker();
private:
return QRectF(x - h / 2.0f, pp.top(), h, pp.height());
}
+void TimeMarker::set_text(const QString &text)
+{
+ (void)text;
+}
+
void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover)
{
if (!enabled())
*/
virtual QString get_text() const = 0;
+ /**
+ * Sets the text to show in the marker.
+ */
+ virtual void set_text(const QString &text);
+
/**
* Paints the marker's label to the ruler.
* @param p The painter to draw with.
#include <iterator>
#include <unordered_set>
-#include <boost/archive/text_iarchive.hpp>
-#include <boost/archive/text_oarchive.hpp>
-#include <boost/serialization/serialization.hpp>
-
#include <QApplication>
+#include <QDebug>
#include <QEvent>
#include <QFontMetrics>
#include <QMenu>
using std::set;
using std::set_difference;
using std::shared_ptr;
-using std::stringstream;
using std::unordered_map;
using std::unordered_set;
using std::vector;
scale_ = 1e-3;
offset_ = 0;
ruler_offset_ = 0;
+ zero_offset_ = 0;
+ custom_zero_offset_set_ = false;
updating_scroll_ = false;
settings_restored_ = false;
always_zoom_to_fit_ = false;
settings.setValue("splitter_state", splitter_->saveState());
settings.setValue("segment_display_mode", segment_display_mode_);
- {
- stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << boost::serialization::make_nvp("offset", offset_);
- settings.setValue("offset", QString::fromStdString(ss.str()));
- }
+ GlobalSettings::store_timestamp(settings, "offset", offset_);
+
+ if (custom_zero_offset_set_)
+ GlobalSettings::store_timestamp(settings, "zero_offset", -zero_offset_);
+ else
+ settings.remove("zero_offset");
for (const shared_ptr<Signal>& signal : signals_) {
settings.beginGroup(signal->base()->internal_name());
set_scale(settings.value("scale").toDouble());
if (settings.contains("offset")) {
- util::Timestamp offset;
- stringstream ss;
- ss << settings.value("offset").toString().toStdString();
-
- try {
- boost::archive::text_iarchive ia(ss);
- ia >> boost::serialization::make_nvp("offset", offset);
- // This also updates ruler_offset_
- set_offset(offset);
- } catch (boost::archive::archive_exception&) {
- qDebug() << "Could not restore the view offset";
- }
+ // This also updates ruler_offset_
+ set_offset(GlobalSettings::restore_timestamp(settings, "offset"));
}
+ if (settings.contains("zero_offset"))
+ set_zero_position(GlobalSettings::restore_timestamp(settings, "zero_offset"));
+
if (settings.contains("splitter_state"))
splitter_->restoreState(settings.value("splitter_state").toByteArray());
void View::set_zero_position(const pv::util::Timestamp& position)
{
zero_offset_ = -position;
+ custom_zero_offset_set_ = true;
// Force an immediate update of the offsets
set_offset(offset_, true);
{
zero_offset_ = 0;
+ // When enabled, the first trigger for this segment is used as the zero position
+ GlobalSettings settings;
+ bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool();
+
+ if (trigger_is_zero_time) {
+ vector<util::Timestamp> triggers = session_.get_triggers(current_segment_);
+
+ if (triggers.size() > 0)
+ zero_offset_ = triggers.front();
+ }
+
+ custom_zero_offset_set_ = false;
+
// Force an immediate update of the offsets
set_offset(offset_, true);
ruler_->update();
for (util::Timestamp timestamp : triggers)
trigger_markers_.push_back(make_shared<TriggerMarker>(*this, timestamp));
- // When enabled, the first trigger for this segment is used as the zero position
- GlobalSettings settings;
- bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool();
-
- if (trigger_is_zero_time && (triggers.size() > 0))
- set_zero_position(triggers.front());
+ if (!custom_zero_offset_set_)
+ reset_zero_position();
viewport_->update();
if ((uint32_t)segment_id != current_segment_)
return;
- // Set zero location if the Key_View_TriggerIsZeroTime setting is set and
- // if this is the first trigger for this segment.
- GlobalSettings settings;
- bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool();
-
- size_t trigger_count = session_.get_triggers(current_segment_).size();
-
- if (trigger_is_zero_time && trigger_count == 1)
- set_zero_position(location);
+ if (!custom_zero_offset_set_)
+ reset_zero_position();
trigger_markers_.push_back(make_shared<TriggerMarker>(*this, location));
}
set_time_unit(util::TimeUnit::Samples);
trigger_markers_.clear();
- set_zero_position(0);
+ if (!custom_zero_offset_set_)
+ set_zero_position(0);
scale_at_acq_start_ = scale_;
offset_at_acq_start_ = offset_;
void View::on_settingViewTriggerIsZeroTime_changed(const QVariant new_value)
{
- if (new_value.toBool()) {
- // The first trigger for this segment is used as the zero position
- vector<util::Timestamp> triggers = session_.get_triggers(current_segment_);
- if (triggers.size() > 0)
- set_zero_position(triggers.front());
- } else
+ if (!custom_zero_offset_set_)
reset_zero_position();
}
pv::util::Timestamp ruler_offset_;
/// The offset of the zero point in seconds.
pv::util::Timestamp zero_offset_;
+ /// Shows whether the user set a custom zero offset that we should keep
+ bool custom_zero_offset_set_;
bool updating_scroll_;
bool settings_restored_;