diff --git a/ui/drivers/qt/playlist.cpp b/ui/drivers/qt/playlist.cpp index 141b3e6fc9..f56751ccb4 100644 --- a/ui/drivers/qt/playlist.cpp +++ b/ui/drivers/qt/playlist.cpp @@ -425,9 +425,7 @@ bool MainWindow::updateCurrentPlaylistEntry(const QHash &conte if (path.isEmpty() || label.isEmpty() || coreName.isEmpty() || - corePath.isEmpty() || - dbName.isEmpty() || - crc32.isEmpty() + corePath.isEmpty() ) return false; @@ -436,16 +434,24 @@ bool MainWindow::updateCurrentPlaylistEntry(const QHash &conte labelArray = label.toUtf8(); coreNameArray = coreName.toUtf8(); corePathArray = QDir::toNativeSeparators(corePath).toUtf8(); - dbNameArray = (dbName + file_path_str(FILE_PATH_LPL_EXTENSION)).toUtf8(); - crc32Array = crc32.toUtf8(); + + if (!dbName.isEmpty()) + { + dbNameArray = (dbName + file_path_str(FILE_PATH_LPL_EXTENSION)).toUtf8(); + dbNameData = dbNameArray.constData(); + } playlistPathData = playlistPathArray.constData(); pathData = pathArray.constData(); labelData = labelArray.constData(); coreNameData = coreNameArray.constData(); corePathData = corePathArray.constData(); - dbNameData = dbNameArray.constData(); - crc32Data = crc32Array.constData(); + + if (!crc32.isEmpty()) + { + crc32Array = crc32.toUtf8(); + crc32Data = crc32Array.constData(); + } if (path_is_compressed_file(pathData)) { @@ -1287,7 +1293,7 @@ void MainWindow::addPlaylistHashToTable(const QVector > labelItem = new QTableWidgetItem(hash.value("label")); labelItem->setData(Qt::UserRole, QVariant::fromValue >(hash)); - labelItem->setFlags(labelItem->flags() & ~Qt::ItemIsEditable); + labelItem->setFlags(labelItem->flags() | Qt::ItemIsEditable); m_tableWidget->setItem(oldRowCount + i, 0, labelItem); } diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index e250734eaf..311a512fa9 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -202,17 +202,11 @@ TableWidget::TableWidget(QWidget *parent) : void TableWidget::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) - { - event->accept(); emit enterPressed(); - } else if (event->key() == Qt::Key_Delete) - { - event->accept(); emit deletePressed(); - } - else - QTableWidget::keyPressEvent(event); + + QTableWidget::keyPressEvent(event); } CoreInfoLabel::CoreInfoLabel(QString text, QWidget *parent) : @@ -1593,6 +1587,9 @@ QTabWidget* MainWindow::browserAndPlaylistTabWidget() void MainWindow::onTableWidgetEnterPressed() { + /* entry is being renamed, ignore this enter press */ + if (m_tableWidget->isPersistentEditorOpen(m_tableWidget->currentIndex())) + return; onRunClicked(); } @@ -2361,6 +2358,29 @@ void MainWindow::onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidg currentItemChanged(hash); } +void MainWindow::onCurrentTableItemDataChanged(QTableWidgetItem *item) +{ + QHash hash; + + if (!item) + return; + + /* block this signal because setData() would trigger an infinite look here */ + disconnect(m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onCurrentTableItemDataChanged(QTableWidgetItem*))); + + hash = item->data(Qt::UserRole).value >(); + hash["label"] = item->text(); + hash["label_noext"] = QFileInfo(item->text()).completeBaseName(); + + item->setData(Qt::UserRole, QVariant::fromValue(hash)); + + updateCurrentPlaylistEntry(hash); + + currentItemChanged(hash); + + connect(m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onCurrentTableItemDataChanged(QTableWidgetItem*))); +} + void MainWindow::currentItemChanged(const QHash &hash) { settings_t *settings = config_get_ptr(); @@ -2955,11 +2975,15 @@ void MainWindow::initContentTableWidget() horizontal_header_labels << msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NAME); + /* block this signal because setData() called in addPlaylistHashToTable() would trigger an infinite loop */ + disconnect(m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onCurrentTableItemDataChanged(QTableWidgetItem*))); + m_tableWidget->clear(); m_tableWidget->setColumnCount(0); m_tableWidget->setRowCount(0); m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); m_tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); + m_tableWidget->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed); m_tableWidget->setSortingEnabled(false); m_tableWidget->setColumnCount(1); m_tableWidget->setRowCount(0); @@ -3005,6 +3029,8 @@ void MainWindow::initContentTableWidget() } onSearchEnterPressed(); + + connect(m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onCurrentTableItemDataChanged(QTableWidgetItem*))); } void MainWindow::keyPressEvent(QKeyEvent *event) diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 2132e452f5..569b549340 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -359,6 +359,7 @@ private slots: void onCoreLoaded(); void onCurrentListItemChanged(QListWidgetItem *current, QListWidgetItem *previous); void onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous); + void onCurrentTableItemDataChanged(QTableWidgetItem *item); void currentItemChanged(const QHash &hash); void onSearchEnterPressed(); void onSearchLineEditEdited(const QString &text);