From a60abf17073455870eb59d9ab45e76f79c4991f9 Mon Sep 17 00:00:00 2001 From: Braden McDorman Date: Thu, 24 Jan 2013 01:01:28 -0600 Subject: [PATCH] If adding channel for the first time, select and set as default --- src/ChannelConfigurationsWidget.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ChannelConfigurationsWidget.cpp b/src/ChannelConfigurationsWidget.cpp index 9240d97b..b5b76957 100644 --- a/src/ChannelConfigurationsWidget.cpp +++ b/src/ChannelConfigurationsWidget.cpp @@ -131,10 +131,21 @@ void ChannelConfigurationsWidget::add() RootController::ref().presentDialog(&keyboard); Config blank; std::string savePath = Camera::ConfigPath::path(keyboard.input().toStdString()); + QString qSavePath = QString::fromStdString(savePath); if(!blank.save(savePath)) { - qWarning() << "Error saving" << QString::fromStdString(savePath); + qWarning() << "Error saving" << qSavePath; return; } + + // Select it and set as default if it's the first one + QDir saves = QDir(QFileInfo(qSavePath).path(), "*." + QString::fromStdString( + Camera::ConfigPath::extension())); + if(saves.entryList(QDir::Files).size() == 1) { + QModelIndex index = m_model->index(qSavePath); + ui->configs->selectionModel()->select(index, QItemSelectionModel::Select); + default_(); + currentChanged(index); + } } void ChannelConfigurationsWidget::remove() @@ -142,6 +153,7 @@ void ChannelConfigurationsWidget::remove() QItemSelection selection = ui->configs->selectionModel()->selection(); if(selection.indexes().size() != 1) return; QFile::remove(m_model->filePath(selection.indexes()[0])); + currentChanged(QModelIndex()); } void ChannelConfigurationsWidget::currentChanged(const QModelIndex &index)