9 #include <QDragMoveEvent>
14 #include <QInputDialog>
21 :
QTreeView(parent), mWaveDataList(wdList), mWaveItemHash(wHash)
52 wd = mWaveDataList->
at(iwave);
69 void WaveTreeView::editWaveData(
WaveData *wd)
110 void WaveTreeView::handleContextMenuRequested(
const QPoint& pos)
112 mContextIndexList = sortedSelection();
113 if (mContextIndexList.isEmpty())
117 mContextIndexList.append(inx);
119 bool singleSelection = mContextIndexList.size() == 1;
121 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
128 QString selName = wtm->netName(mContextIndexList.at(0));
130 act = menu->
addAction(
"Insert new group");
133 act = menu->
addAction(
"Insert new boolean expression");
136 act = menu->
addAction(
"Insert new trigger based on selection");
139 act = menu->
addAction(
"Rename '" + selName +
"'");
142 if (wtm->isLeaveItem(mContextIndexList.at(0)))
144 act = menu->
addAction(
"Edit net wave " + selName);
147 act = menu->
addAction(
"Remove net wave " + selName);
152 act = menu->
addAction(
"View group data " + selName);
155 act = menu->
addAction(
"Remove group " + selName);
158 QMenu* menuBase = menu->
addMenu(
"Value format for " + selName);
162 act = menuBase->
addAction(
"Decimal (signed)");
165 act = menuBase->
addAction(
"Decimal (unsigned)");
177 act = menu->
addAction(
QString(
"Boolean expression based on %1 selected items").arg(mContextIndexList.size()));
179 act = menu->
addAction(
QString(
"Trigger time set based on %1 selected items").arg(mContextIndexList.size()));
182 act = menu->
addAction(
QString(
"Remove %1 selected items").arg(mContextIndexList.size()));
188 act = menu->
addAction(
"Collapse all groups");
190 act = menu->
addAction(
"Expand all groups");
196 void WaveTreeView::handleSetValueFormat()
198 if (mContextIndexList.size() != 1)
return;
200 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
201 int grpId = wtm->groupId(inx);
203 WaveDataGroup* grp = mWaveDataList->
mDataGroups.value(grpId);
208 wtm->handleUpdateValueColumn();
217 void WaveTreeView::handleRenameItem()
219 if (mContextIndexList.size() != 1)
return;
221 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
222 WaveData* wd = wtm->item(inx);
227 wd->name(), &confirm);
228 if (confirm && !newName.
isEmpty())
230 if (wd->rename(newName))
250 void WaveTreeView::handleEditOrBrowseItem()
252 if (mContextIndexList.size()!=1)
return;
254 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
255 WaveData* wd = wtm->item(inx);
260 void WaveTreeView::handleRemoveItem()
262 if (mContextIndexList.size()!=1)
return;
264 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
265 WaveTreeModel::ReorderRequest req(wtm);
269 void WaveTreeView::handleRemoveGroup()
271 if (mContextIndexList.size()!=1)
return;
273 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
274 WaveTreeModel::ReorderRequest req(wtm);
275 wtm->removeGroup(inx);
279 void WaveTreeView::handleRemoveMulti()
281 if (mContextIndexList.isEmpty())
return;
282 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
283 WaveTreeModel::ReorderRequest req(wtm);
287 if (wtm->isLeaveItem(inx))
293 wtm->removeGroup(inx);
299 void WaveTreeView::handleInsertGroup()
301 if (mContextIndexList.size() != 1)
return;
302 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
303 wtm->insertGroup(mContextIndexList.at(0));
306 void WaveTreeView::handleInsertBoolean()
308 if (mContextIndexList.empty())
return;
309 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
313 WaveData* wd = wtm->item(inx);
314 if (wd) selectedWaves.
append(wd);
316 BooleanDialog bd(selectedWaves,
this);
319 if (bd.hasExpression())
321 QString boolExpr = bd.expression();
324 wtm->insertBoolean(mContextIndexList.last(),boolExpr);
330 wtm->insertBoolean(mContextIndexList.last(),selectedWaves,bd.tableValues());
336 void WaveTreeView::handleInsertTrigger()
338 if (mContextIndexList.empty())
return;
339 WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
343 WaveData* wd = wtm->item(inx);
344 if (wd) trigList.
append(wd);
346 QModelIndex insertInx = wtm->index(mContextIndexList.first().row()+1,0);
348 for (WaveDataBoolean* wdb : mWaveDataList->
mDataBooleans.values())
354 int iwave = it.key().index();
355 if (iwave < 0 || iwaveAdded.
contains(iwave))
continue;
356 filterList.
append(mWaveDataList->
at(iwave));
359 TriggerDialog td(trigList,filterList,
this);
362 wtm->insertTrigger(insertInx,trigList,td.transitionToValue(),td.filterWave());
366 QModelIndexList WaveTreeView::sortedSelection()
const
371 if (inx.
column())
continue;
372 int sortCode = 2000000000;
376 sortCode -= (p.
row()+1) * 200000;
377 sortCode -= (inx.
row()+1);
378 sortInx.
insert(sortCode,inx);
385 QModelIndexList sel = sortedSelection();
386 if (sel.isEmpty())
return;
395 if (grpId >= 0) mExpandedGroups.
insert(grpId);
402 const WaveTreeModel* wtm =
static_cast<WaveTreeModel*
>(
model());
404 if (grpId >= 0) mExpandedGroups.
remove(grpId);
427 int nVisible = mItemOrder.
size();
439 for (
int i=0; i<nVisible; i++)
452 else if (iwave == -2)
457 else if (iwave == -3)
468 mWaveItemHash->
dump(
"Crash");
469 qDebug() <<
"group/boolean wii not found" <<
id << tp;
474 auto it = notPlaced.
find(wii);
475 if (it != notPlaced.
end()) notPlaced.
erase(it);
481 if (groupId < 0) groupId = 0;
486 mWaveItemHash->
dump(
"Crash");
487 qDebug() <<
"wire wii not found" << iwave << groupId;
492 auto it = notPlaced.
find(wii);
493 if (it != notPlaced.
end()) notPlaced.
erase(it);
500 if (mExpandedGroups.
contains(grpId))
508 wi->setWaveVisible(
false);
520 wi->setWaveSelected(
false);
522 std::vector<u32> netIds;
536 netIds.push_back(wd->
id());
542 void WaveTreeView::orderRecursion(
const QModelIndex &parent)
545 for (
int i=0; i<n; i++)
597 QPen textPen =
QPen(option.palette.text(),0);
600 painter->
fillRect(option.rect, option.palette.highlight());
601 textPen =
QPen(option.palette.highlightedText(),0);
604 QRect rectTxt = option.rect;
605 int w = rectTxt.
width()-22;
610 QRect rectCol(rectTxt.
left()+w+3,rectTxt.
top()+3,16,16);
void selectNet(u32 netId, bool clear_current_selection=true, bool navigate_to_selection=true)
void rename_net(uint32_t id, const std::string &nam)
Change waveform name entry for net identified by id.
void add_or_replace_composed(SaleaeDirectoryComposedEntry sdce)
Add composed waveform entry (Group, Boolean, Trigger)
SaleaeDirectoryComposedEntry get_composed(uint32_t id, SaleaeDirectoryNetEntry::Type tp) const
Getter for pointer to composed waveform entry allowing modifications.
void rename(const std::string nam)
Rename waveform.
void setData(const QMap< u64, int > &dat)
QMap< u32, WaveDataGroup * > mDataGroups
QMap< u32, WaveDataBoolean * > mDataBooleans
int waveIndexByNetId(u32 id) const
SaleaeDirectory & saleaeDirectory()
void updateWaveData(int inx)
void setSelected(WaveItem *wi=nullptr)
int visibleEntries() const
void setVisibleEntries(int ve)
void dump(const char *stub)
WaveItem * firstSelected() const
void dispose(WaveItem *wi)
const WaveData * wavedata() const
void setWaveVisible(bool vis)
void setYposition(int pos)
void setWaveSelected(bool sel)
int triggerId(const QModelIndex &trigIndex) const
QModelIndexList indexes(const WaveData *wd) const
int waveIndex(const QModelIndex &index) const
bool onlyRootItemsSelected(const QModelIndexList &selectList) const
int groupId(const QModelIndex &grpIndex) const
int booleanId(const QModelIndex &boolIndex) const
WaveItemIndex hashIndex(const QModelIndex &index) const
void viewportHeightChanged(int height)
void mouseDoubleClickEvent(QMouseEvent *event) override
void handleInserted(const QModelIndex &index)
void sizeChanged(int viewportHeight, int scrollbarMax, int scrollbarPos)
WaveTreeView(WaveDataList *wdList, WaveItemHash *wHash, QWidget *parent=nullptr)
bool viewportEvent(QEvent *event) override
void scrollContentsBy(int dx, int dy) override
void setWaveSelection(const QSet< u32 > &netIds)
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
void resizeEvent(QResizeEvent *event) override
void triggerUpdateWaveItems()
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override
void startDrag(Qt::DropActions supportedActions) override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
bool save(std::filesystem::path file_path, GateLibrary *gate_lib, bool overwrite=false)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual int rowCount(const QModelIndex &parent) const const=0
QModelIndex currentIndex() const const
void setDragDropMode(QAbstractItemView::DragDropMode behavior)
void setDragEnabled(bool enable)
virtual bool event(QEvent *event) override
QAbstractItemModel * model() const const
virtual void mouseDoubleClickEvent(QMouseEvent *event) override
virtual void resizeEvent(QResizeEvent *event) override
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QItemSelectionModel * selectionModel() const const
void setCurrentIndex(const QModelIndex &index)
void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate)
void setDropIndicatorShown(bool enable)
virtual void startDrag(Qt::DropActions supportedActions)
virtual bool viewportEvent(QEvent *event) override
QVariant data() const const
void setData(const QVariant &userData)
void triggered(bool checked)
QEvent::Type type() const const
void setBold(bool enable)
void setPixelSize(int pixelSize)
QHash::const_iterator constBegin() const const
QHash::const_iterator constEnd() const const
QHash::iterator erase(QHash::iterator pos)
QHash::iterator find(const Key &key)
const T value(const Key &key) const const
QList< T > values() const const
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
void append(const T &value)
const T & at(int i) const const
QMap::iterator insert(const Key &key, const T &value)
QList< T > values() const const
void * internalPointer() const const
bool isValid() const const
QModelIndex parent() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QObject * sender() const const
void drawEllipse(const QRectF &rectangle)
void drawText(const QPointF &position, const QString &text)
void fillRect(const QRectF &rectangle, const QBrush &brush)
const QFont & font() const const
void setBrush(const QBrush &brush)
void setFont(const QFont &font)
void setPen(const QColor &color)
bool contains(const T &value) const const
QSet::iterator insert(const T &value)
bool remove(const T &value)
bool isEmpty() const const
QString & replace(int position, int n, QChar after)
std::string toStdString() const const
void collapse(const QModelIndex &index)
void collapsed(const QModelIndex &index)
void expand(const QModelIndex &index)
void expanded(const QModelIndex &index)
virtual QModelIndex indexAt(const QPoint &point) const const override
bool isExpanded(const QModelIndex &index) const const
virtual void scrollContentsBy(int dx, int dy) override
virtual QModelIndexList selectedIndexes() const const override
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
int toInt(bool *ok) const const