double click doesn't need a delegate
This commit is contained in:
parent
f6a50926c3
commit
42368ea01f
|
@ -30,8 +30,6 @@ target_sources(${PROJECT_NAME}
|
|||
universeview.h
|
||||
universeview.cpp
|
||||
universeview.ui
|
||||
universeviewdelegate.h
|
||||
universeviewdelegate.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "multiverseview.h"
|
||||
#include "multiversemodel.h"
|
||||
#include "ui_multiverseview.h"
|
||||
#include "universeviewdelegate.h"
|
||||
#include "universeview.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -13,14 +13,27 @@
|
|||
MultiverseView::MultiverseView(QWidget *parent, QSacnNode *node)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MultiverseView)
|
||||
, node(node)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->actionTerminate->setEnabled(false);
|
||||
ui->actionUnsubscribe->setEnabled(false);
|
||||
ui->actionInspect->setEnabled(false);
|
||||
|
||||
ui->multiverseView->setModel(new MultiverseModel(this, node));
|
||||
ui->multiverseView->setItemDelegate(new UniverseViewDelegate(this, node));
|
||||
ui->multiverseView->expandAll();
|
||||
ui->multiverseView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->multiverseView, &QTreeView::customContextMenuRequested,
|
||||
this, &MultiverseView::multiverseContextMenu);
|
||||
|
||||
connect(ui->multiverseView, &QTreeView::doubleClicked,
|
||||
this, &MultiverseView::createEditor);
|
||||
|
||||
connect(ui->actionInspect, &QAction::triggered,
|
||||
this, [this]() {
|
||||
auto selected = ui->multiverseView->currentIndex();
|
||||
createEditor(selected);
|
||||
});
|
||||
|
||||
connect(ui->actionCreate, &QAction::triggered,
|
||||
this, [this, node]() {
|
||||
|
@ -30,6 +43,18 @@ MultiverseView::MultiverseView(QWidget *parent, QSacnNode *node)
|
|||
dialog->exec();
|
||||
});
|
||||
|
||||
connect(ui->actionTerminate, &QAction::triggered,
|
||||
this, [&, node](){
|
||||
auto item = static_cast<MultiverseItem*>(ui->multiverseView->currentIndex().internalPointer());
|
||||
auto data = item->data(0, Qt::EditRole);
|
||||
if (data.metaType().id() == qMetaTypeId<QSacnUniverse*>())
|
||||
{
|
||||
auto univ = data.value<QSacnUniverse*>();
|
||||
if (univ->isEditable())
|
||||
node->terminate(univ->number());
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->actionSubscribe, &QAction::triggered,
|
||||
this, [this, node]() {
|
||||
auto dialog = new AddUniverseDialog(this, 1, tr("Subscribe to Universe"));
|
||||
|
@ -38,6 +63,18 @@ MultiverseView::MultiverseView(QWidget *parent, QSacnNode *node)
|
|||
dialog->exec();
|
||||
});
|
||||
|
||||
connect(ui->actionUnsubscribe, &QAction::triggered,
|
||||
this, [&, node](){
|
||||
auto item = static_cast<MultiverseItem*>(ui->multiverseView->currentIndex().internalPointer());
|
||||
auto data = item->data(0, Qt::EditRole);
|
||||
if (data.metaType().id() == qMetaTypeId<QSacnUniverse*>())
|
||||
{
|
||||
auto univ = data.value<QSacnUniverse*>();
|
||||
if (!univ->isEditable())
|
||||
node->unsubscribe(univ->number());
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->multiverseView->selectionModel(),
|
||||
&QItemSelectionModel::currentChanged,
|
||||
this, &MultiverseView::selectionChanged);
|
||||
|
@ -65,6 +102,7 @@ void MultiverseView::selectionChanged(const QModelIndex ¤t,
|
|||
|
||||
ui->actionTerminate->setEnabled(false);
|
||||
ui->actionUnsubscribe->setEnabled(false);
|
||||
ui->actionInspect->setEnabled(false);
|
||||
|
||||
auto item = static_cast<MultiverseItem*>(current.internalPointer());
|
||||
auto data = item->data(0, Qt::EditRole);
|
||||
|
@ -72,6 +110,7 @@ void MultiverseView::selectionChanged(const QModelIndex ¤t,
|
|||
return;
|
||||
if (data.metaType().id() == qMetaTypeId<QSacnUniverse*>())
|
||||
{
|
||||
ui->actionInspect->setEnabled(true);
|
||||
auto univ = data.value<QSacnUniverse*>();
|
||||
if (univ->isEditable())
|
||||
ui->actionTerminate->setEnabled(true);
|
||||
|
@ -80,3 +119,79 @@ void MultiverseView::selectionChanged(const QModelIndex ¤t,
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief MultiverseView::multiverseContextMenu
|
||||
* @param pos
|
||||
*/
|
||||
void MultiverseView::multiverseContextMenu(const QPoint &pos)
|
||||
{
|
||||
QMenu menu(ui->multiverseView);
|
||||
auto globalpos = ui->multiverseView->mapToGlobal(pos);
|
||||
|
||||
auto index = ui->multiverseView->indexAt(pos);
|
||||
auto flags = ui->multiverseView->model()->flags(index);
|
||||
if (!(flags & Qt::ItemIsSelectable))
|
||||
{
|
||||
// top level item
|
||||
return;
|
||||
}
|
||||
|
||||
auto item = static_cast<MultiverseItem*>(index.internalPointer());
|
||||
auto data = item->data(0, Qt::EditRole);
|
||||
if (!data.isValid())
|
||||
return;
|
||||
if (data.metaType().id() == qMetaTypeId<QSacnUniverse*>())
|
||||
{
|
||||
if (flags & Qt::ItemIsEditable)
|
||||
{
|
||||
// all universes
|
||||
menu.addAction(ui->actionInspect);
|
||||
menu.addSeparator();
|
||||
}
|
||||
auto univ = data.value<QSacnUniverse*>();
|
||||
if (univ->isEditable())
|
||||
menu.addAction(ui->actionTerminate);
|
||||
else
|
||||
menu.addAction(ui->actionUnsubscribe);
|
||||
menu.exec(globalpos);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.metaType().id() == qMetaTypeId<sACN::EXTENDED::DISCOVERY::discoveredUniverse*>())
|
||||
{
|
||||
auto univ = data.value<sACN::EXTENDED::DISCOVERY::discoveredUniverse*>();
|
||||
(void)univ;
|
||||
// discovered
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief MultiverseView::createEditor
|
||||
* @param index
|
||||
*/
|
||||
void MultiverseView::createEditor(const QModelIndex &index)
|
||||
{
|
||||
QVariant data = index.data(Qt::EditRole);
|
||||
|
||||
if (data.metaType().id() == qMetaTypeId<QSacnUniverse*>())
|
||||
{
|
||||
auto univ = data.value<QSacnUniverse*>();
|
||||
auto universeView = new UniverseView(this, univ);
|
||||
universeView->show();
|
||||
}
|
||||
|
||||
if (data.metaType().id() ==
|
||||
qMetaTypeId<sACN::EXTENDED::DISCOVERY::discoveredUniverse*>())
|
||||
{
|
||||
auto disc = data.value<sACN::EXTENDED::DISCOVERY::discoveredUniverse*>();
|
||||
auto subscribe = new AddUniverseDialog(this, disc->universe,
|
||||
tr("Subscribe to Universe"));
|
||||
connect(subscribe, &AddUniverseDialog::additionRequested,
|
||||
node, &QSacnNode::subscribe);
|
||||
subscribe->exec();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,10 @@ public:
|
|||
|
||||
public slots:
|
||||
void selectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void multiverseContextMenu(const QPoint &pos);
|
||||
void createEditor(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
Ui::MultiverseView *ui;
|
||||
QSacnNode * node;
|
||||
};
|
||||
|
|
|
@ -75,6 +75,8 @@
|
|||
<addaction name="separator"/>
|
||||
<addaction name="actionSubscribe"/>
|
||||
<addaction name="actionUnsubscribe"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionInspect"/>
|
||||
</widget>
|
||||
<action name="actionSubscribe">
|
||||
<property name="text">
|
||||
|
@ -128,6 +130,20 @@
|
|||
<string>Set this Component's UACN</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionInspect">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Inspect</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>View data</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Space</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
#include "adduniversedialog.h"
|
||||
#include "qsacnuniverse.h"
|
||||
#include "sacn/extended.h"
|
||||
#include "universeview.h"
|
||||
#include "universeviewdelegate.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseViewDelegate::UniverseViewDelegate
|
||||
* @param parent
|
||||
* @param node
|
||||
*/
|
||||
UniverseViewDelegate::UniverseViewDelegate(QObject * parent, QSacnNode * node)
|
||||
: QStyledItemDelegate(parent)
|
||||
, node_(node)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseViewDelegate::createEditor
|
||||
* @param parent
|
||||
* @param option
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
QWidget * UniverseViewDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QVariant data = index.data(Qt::EditRole);
|
||||
|
||||
if (data.metaType().id() == qMetaTypeId<QSacnUniverse*>())
|
||||
{
|
||||
auto univ = data.value<QSacnUniverse*>();
|
||||
auto universeView = new UniverseView(parent, univ);
|
||||
universeView->show();
|
||||
|
||||
return new QWidget(parent);
|
||||
}
|
||||
|
||||
if (index.data().canConvert<sACN::EXTENDED::DISCOVERY::discoveredUniverse*>())
|
||||
{
|
||||
auto disc = data.value<sACN::EXTENDED::DISCOVERY::discoveredUniverse*>();
|
||||
auto subscribe = new AddUniverseDialog(parent, disc->universe,
|
||||
tr("Subscribe to Universe"));
|
||||
connect(subscribe, &AddUniverseDialog::additionRequested,
|
||||
node_, &QSacnNode::subscribe);
|
||||
subscribe->exec();
|
||||
|
||||
return new QWidget(parent);
|
||||
}
|
||||
|
||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "qsacnnode.h"
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class UniverseViewDelegate
|
||||
: public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UniverseViewDelegate(QObject *parent = nullptr,
|
||||
QSacnNode *node = nullptr);
|
||||
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
QSacnNode * node_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue