enable UI actions with appropriate selection
This commit is contained in:
parent
5693689267
commit
c1efa991fb
|
@ -156,7 +156,7 @@ QVariant MultiverseItem::data(int column, int role) const
|
|||
if (universe_)
|
||||
return QVariant(QVariant::fromValue(universe_));
|
||||
if (discovery_)
|
||||
return QVariant(QVariant::fromValue(static_cast<void*>(discovery_)));
|
||||
return QVariant(QVariant::fromValue(discovery_));
|
||||
return data(column, Qt::DisplayRole);
|
||||
default:
|
||||
return QVariant();
|
||||
|
|
|
@ -18,6 +18,10 @@ MultiverseView::MultiverseView(QWidget *parent, QSacnNode *node)
|
|||
ui->multiverseView->setModel(new MultiverseModel(this, node));
|
||||
ui->multiverseView->setItemDelegate(new UniverseViewDelegate(this, node));
|
||||
ui->multiverseView->expandAll();
|
||||
|
||||
connect(ui->multiverseView->selectionModel(),
|
||||
&QItemSelectionModel::currentChanged,
|
||||
this, &MultiverseView::selectionChanged);
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,3 +32,32 @@ MultiverseView::~MultiverseView()
|
|||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief MultiverseView::selectionChanged
|
||||
* @param selected
|
||||
* @param deselected
|
||||
*/
|
||||
void MultiverseView::selectionChanged(const QModelIndex ¤t,
|
||||
const QModelIndex &previous)
|
||||
{
|
||||
Q_UNUSED(previous)
|
||||
|
||||
ui->actionTerminate->setEnabled(false);
|
||||
ui->actionUnsubscribe->setEnabled(false);
|
||||
|
||||
auto item = static_cast<MultiverseItem*>(current.internalPointer());
|
||||
auto data = item->data(0, Qt::EditRole);
|
||||
if (!data.isValid())
|
||||
return;
|
||||
if (data.metaType().id() == qMetaTypeId<QSacnUniverse*>())
|
||||
{
|
||||
auto univ = data.value<QSacnUniverse*>();
|
||||
if (univ->isEditable())
|
||||
ui->actionTerminate->setEnabled(true);
|
||||
else
|
||||
ui->actionUnsubscribe->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,9 @@ public:
|
|||
QSacnNode* node = nullptr);
|
||||
virtual ~MultiverseView();
|
||||
|
||||
public slots:
|
||||
void selectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
||||
private:
|
||||
Ui::MultiverseView *ui;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue