* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "analog.hpp"
+#include "logic.hpp"
#include "signalbase.hpp"
+#include "signaldata.hpp"
+using std::dynamic_pointer_cast;
using std::shared_ptr;
using sigrok::Channel;
return bgcolour_;
}
+void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
+{
+ data_ = data;
+}
+
+shared_ptr<data::Analog> SignalBase::analog_data() const
+{
+ if (type() == ChannelType::ANALOG)
+ return dynamic_pointer_cast<data::Analog>(data_);
+ else
+ return shared_ptr<data::Analog>();
+}
+
+shared_ptr<data::Logic> SignalBase::logic_data() const
+{
+ if (type() == ChannelType::LOGIC)
+ return dynamic_pointer_cast<data::Logic>(data_);
+ else
+ return shared_ptr<data::Logic>();
+}
+
+
} // namespace data
} // namespace pv
namespace pv {
namespace data {
+class Analog;
+class Logic;
+class SignalData;
+
class SignalBase : public QObject
{
Q_OBJECT
*/
QColor bgcolour() const;
+ /**
+ * Sets the internal data object.
+ */
+ void set_data(std::shared_ptr<pv::data::SignalData> data);
+
+ /**
+ * Get the internal data as analog data object in case of analog type.
+ */
+ std::shared_ptr<pv::data::Analog> analog_data() const;
+
+ /**
+ * Get the internal data as logic data object in case of logic type.
+ */
+ std::shared_ptr<pv::data::Logic> logic_data() const;
+
+
Q_SIGNALS:
void enabled_changed(const bool &value);
private:
std::shared_ptr<sigrok::Channel> channel_;
+ std::shared_ptr<pv::data::SignalData> data_;
+
QString name_;
QColor colour_, bgcolour_;
};
case SR_CHANNEL_ANALOG:
{
- shared_ptr<data::Analog> data(
- new data::Analog());
+ shared_ptr<data::Analog> data(new data::Analog());
+ signalbase->set_data(data);
signal = shared_ptr<view::Signal>(
new view::AnalogSignal(
- *this, signalbase, data));
+ *this, signalbase));
all_signal_data_.insert(data);
signalbases_.insert(signalbase);
break;
signals_changed();
}
-shared_ptr<data::SignalBase> Session::signal_from_channel(
+shared_ptr<data::SignalBase> Session::signalbase_from_channel(
shared_ptr<sigrok::Channel> channel) const
{
for (shared_ptr<data::SignalBase> sig : signalbases_) {
cur_analog_segments_[channel] = segment;
// Find the analog data associated with the channel
- shared_ptr<view::AnalogSignal> sig =
- dynamic_pointer_cast<view::AnalogSignal>(
- signal_from_channel(channel));
- assert(sig);
+ shared_ptr<data::SignalBase> base = signalbase_from_channel(channel);
+ assert(base);
- shared_ptr<data::Analog> data(sig->analog_data());
+ shared_ptr<data::Analog> data(base->analog_data());
assert(data);
// Push the segment into the analog data.
void update_signals();
- std::shared_ptr<data::SignalBase> signal_from_channel(
+ std::shared_ptr<data::SignalBase> signalbase_from_channel(
std::shared_ptr<sigrok::Channel> channel) const;
private:
AnalogSignal::AnalogSignal(
pv::Session &session,
- shared_ptr<data::SignalBase> base,
- shared_ptr<data::Analog> data) :
+ shared_ptr<data::SignalBase> base) :
Signal(session, base),
- data_(data),
scale_index_(4), // 20 per div
scale_index_drag_offset_(0),
div_height_(3 * QFontMetrics(QApplication::font()).height()),
shared_ptr<pv::data::SignalData> AnalogSignal::data() const
{
- return data_;
-}
-
-shared_ptr<pv::data::Analog> AnalogSignal::analog_data() const
-{
- return data_;
+ return base_->analog_data();
}
std::pair<int, int> AnalogSignal::v_extents() const
void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
{
- assert(data_);
+ assert(base_->analog_data());
assert(owner_);
const int y = get_visual_y();
paint_grid(p, y, pp.left(), pp.right());
const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
- data_->analog_segments();
+ base_->analog_data()->analog_segments();
if (segments.empty())
return;
public:
AnalogSignal(pv::Session &session,
- std::shared_ptr<data::SignalBase> base,
- std::shared_ptr<pv::data::Analog> data);
+ std::shared_ptr<data::SignalBase> base);
virtual ~AnalogSignal() = default;
std::shared_ptr<pv::data::SignalData> data() const;
- std::shared_ptr<pv::data::Analog> analog_data() const;
-
/**
* Computes the vertical extents of the contents of this row item.
* @return A pair containing the minimum and maximum y-values.
void on_resolution_changed(int index);
private:
- std::shared_ptr<pv::data::Analog> data_;
-
QComboBox *resolution_cb_;
float scale_;