#include "signal.h"
#include "../sigsession.h"
-#include <assert.h>
+#include <cassert>
+#include <algorithm>
#include <QApplication>
#include <QMenu>
using std::make_pair;
using std::pair;
using std::shared_ptr;
+using std::stable_sort;
using std::vector;
namespace pv {
// left edge of the widget, because then the selection shadow
// would be clipped away.
const int w = width() - BaselineOffset;
- const vector< shared_ptr<RowItem> > row_items(_view.child_items());
+
+ vector< shared_ptr<RowItem> > row_items(_view.child_items());
+ stable_sort(row_items.begin(), row_items.end(),
+ [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
+ return a->v_offset() < b->v_offset(); });
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <cassert>
+
+#include "rowitem.h"
#include "rowitemowner.h"
+
+using std::shared_ptr;
+using std::vector;
+
+namespace pv {
+namespace view {
+
+const vector< shared_ptr<RowItem> >& RowItemOwner::child_items() const
+{
+ return _items;
+}
+
+void RowItemOwner::clear_child_items()
+{
+ for (auto &i : _items) {
+ assert(i->owner() == this);
+ i->set_owner(nullptr);
+ }
+ _items.clear();
+}
+
+void RowItemOwner::add_child_item(std::shared_ptr<RowItem> item)
+{
+ assert(!item->owner());
+ item->set_owner(this);
+ _items.push_back(item);
+}
+
+void RowItemOwner::remove_child_item(std::shared_ptr<RowItem> item)
+{
+ assert(item->owner() == this);
+ item->set_owner(nullptr);
+ auto iter = std::find(_items.begin(), _items.end(), item);
+ assert(iter != _items.end());
+ _items.erase(iter);
+}
+
+} // view
+} // pv
/**
* Returns a list of row items owned by this object.
*/
- virtual std::vector< std::shared_ptr<RowItem> > child_items() const = 0;
+ virtual const std::vector< std::shared_ptr<RowItem> >&
+ child_items() const;
+
+ /**
+ * Clears the list of child items.
+ */
+ void clear_child_items();
+
+ /**
+ * Adds a child item to this object.
+ */
+ void add_child_item(std::shared_ptr<RowItem> item);
+
+ /**
+ * Removes a child item from this object.
+ */
+ void remove_child_item(std::shared_ptr<RowItem> item);
virtual void update_viewport() = 0;
+
+private:
+ std::vector< std::shared_ptr<RowItem> > _items;
};
} // view
scale_offset_changed();
}
-vector< shared_ptr<RowItem> > View::child_items() const
-{
- vector< shared_ptr<RowItem> > row_items;
-
- const vector< shared_ptr<Signal> > sigs(
- session().get_signals());
- copy(sigs.begin(), sigs.end(), back_inserter(row_items));
-
-#ifdef ENABLE_DECODE
- const vector< shared_ptr<DecodeTrace> > decode_sigs(
- session().get_decode_signals());
- copy(decode_sigs.begin(), decode_sigs.end(), back_inserter(row_items));
-#endif
-
- stable_sort(row_items.begin(), row_items.end(),
- [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
- return a->v_offset() < b->v_offset(); });
-
- return row_items;
-}
-
list<weak_ptr<SelectableItem> > View::selected_items() const
{
list<weak_ptr<SelectableItem> > items;
// List the selected signals
const vector< shared_ptr<RowItem> > row_items(child_items());
for (shared_ptr<RowItem> r : row_items) {
- assert(r);
- if (r->selected())
+ if (r && r->selected())
items.push_back(r);
}
void View::signals_changed()
{
+ // Populate the traces
+ clear_child_items();
+
+ const vector< shared_ptr<Signal> > sigs(
+ session().get_signals());
+ for (auto s : sigs)
+ add_child_item(s);
+
+#ifdef ENABLE_DECODE
+ const vector< shared_ptr<DecodeTrace> > decode_sigs(
+ session().get_decode_signals());
+ for (auto s : decode_sigs)
+ add_child_item(s);
+#endif
+
+ // Create the initial layout
int offset = SignalMargin + SignalHeight;
- const vector< shared_ptr<RowItem> > row_items(child_items());
- for (shared_ptr<RowItem> r : row_items) {
- r->set_owner(this);
+ for (shared_ptr<RowItem> r : child_items()) {
r->set_v_offset(offset);
offset += SignalHeight + 2 * SignalMargin;
}
*/
void set_scale_offset(double scale, double offset);
- /**
- * Returns a list of traces owned by this object.
- */
- std::vector< std::shared_ptr<RowItem> > child_items() const;
-
std::list<std::weak_ptr<SelectableItem> > selected_items() const;
std::set< std::shared_ptr<pv::data::SignalData> >
#include <cassert>
#include <cmath>
+#include <algorithm>
#include "view.h"
#include "viewport.h"
using std::max;
using std::min;
using std::shared_ptr;
+using std::stable_sort;
using std::vector;
namespace pv {
void Viewport::paintEvent(QPaintEvent*)
{
- const vector< shared_ptr<RowItem> > row_items(_view.child_items());
+ vector< shared_ptr<RowItem> > row_items(_view.child_items());
+ stable_sort(row_items.begin(), row_items.end(),
+ [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
+ return a->v_offset() < b->v_offset(); });
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);