From 8d551ed344a9bfa7f0b96a8677aca570d8c7c407 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 20 May 2018 14:26:43 +0200 Subject: Implement remove functionality for instruments and channels. --- src/mainwindow.cc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/mainwindow.cc') diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 6238a18..61ea9bb 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -98,7 +98,7 @@ MainWindow::MainWindow(Settings& settings) tools->addWidget(rem); instrument_list = new QListWidget(); connect(instrument_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), - this, SLOT(itemDoubleClicked(QListWidgetItem*))); + this, SLOT(instrumentDoubleClicked(QListWidgetItem*))); l->addWidget(tools); l->addWidget(instrument_list); @@ -125,6 +125,8 @@ MainWindow::MainWindow(Settings& settings) tools->addWidget(add); tools->addWidget(rem); channel_list = new QListWidget(); + connect(channel_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), + this, SLOT(channelDoubleClicked(QListWidgetItem*))); channel_list->addItems({"AmbL", "AmbR", "Kdrum_back", "Kdrum_front", "Hihat", "OHL", "OHR", "Ride","Snare_bottom", "Snare_top", "Tom1", "Tom2", "Tom3"}); @@ -167,9 +169,25 @@ void MainWindow::addInstrument() void MainWindow::removeInstrument() { + auto items = instrument_list->selectedItems(); + for(auto item : items) + { + auto id = item->data(Qt::UserRole).toInt(); + + for(int i = 0; i < tab_widget->count(); ++i) + { + if(tab_widget->widget(i)->property("id").toInt() == id) + { + tab_widget->removeTab(i); + } + } + + project.deleteInstrument(id); + delete item; + } } -void MainWindow::itemDoubleClicked(QListWidgetItem *item) +void MainWindow::instrumentDoubleClicked(QListWidgetItem *item) { int id = item->data(Qt::UserRole).toInt(); auto& instr = project.getInstrument(id); @@ -196,10 +214,20 @@ void MainWindow::addChannel() auto item = new QListWidgetItem(); item->setIcon(QPixmap(":icons/channel.png")); item->setText("New Channel"); + //item->setData(Qt::UserRole, id); channel_list->addItem(item); } void MainWindow::removeChannel() +{ + auto items = channel_list->selectedItems(); + for(auto item : items) + { + delete item; + } +} + +void MainWindow::channelDoubleClicked(QListWidgetItem *item) { } -- cgit v1.2.3