shortcut for creating linked markers for all traces

This commit is contained in:
Jan Käberich 2021-12-05 19:28:36 +01:00
parent b2d3c407fc
commit 8246e80d69
3 changed files with 47 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#include <QKeyEvent>
#include <QMenu>
#include <QPainter>
MarkerWidget::MarkerWidget(MarkerModel &model, QWidget *parent) :
QWidget(parent),
@ -12,6 +13,16 @@ MarkerWidget::MarkerWidget(MarkerModel &model, QWidget *parent) :
model(model)
{
ui->setupUi(this);
// some image magic to create a button with three "add" icons (not available as standard icon)
QImage image(44, 44, QImage::Format_ARGB32);
auto origImage = ui->bAddAll->icon().pixmap(22).toImage().convertToFormat(QImage::Format_ARGB32);
QPainter painter(&image);
painter.drawImage(0, 0, origImage);
painter.drawImage(origImage.width(), 0, origImage);
painter.drawImage(origImage.width()/2, origImage.height(), origImage);
ui->bAddAll->setIcon(QIcon(QPixmap::fromImage(image)));
ui->treeView->setModel(&model);
ui->treeView->setItemDelegateForColumn(MarkerModel::ColIndexTrace, new MarkerTraceDelegate);
ui->treeView->setItemDelegateForColumn(MarkerModel::ColIndexType, new MarkerTypeDelegate);
@ -123,6 +134,18 @@ void MarkerWidget::on_bAdd_clicked()
model.addMarker(marker);
}
void MarkerWidget::on_bAddAll_clicked()
{
// add a marker for every trace and link them
auto group = model.createMarkerGroup();
for(auto trace : model.getModel().getTraces()) {
auto m = model.createDefaultMarker();
m->assignTrace(trace);
group->add(m);
model.addMarker(m);
}
}
bool MarkerWidget::eventFilter(QObject *, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
@ -152,4 +175,3 @@ void MarkerWidget::updatePersistentEditors()
}
}
}

View File

@ -22,6 +22,8 @@ private slots:
void on_bAdd_clicked();
void updatePersistentEditors();
void on_bAddAll_clicked();
private:
bool eventFilter(QObject *obj, QEvent *event) override;
Ui::MarkerWidget *ui;

View File

@ -44,7 +44,27 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>Add</string>
<string>Add marker</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="list-add" resource="../../icons.qrc">
<normaloff>:/icons/add.png</normaloff>:/icons/add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="bAddAll">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Add markers to all traces</string>
</property>
<property name="text">
<string/>
@ -64,7 +84,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>Delete</string>
<string>Delete marker</string>
</property>
<property name="text">
<string/>