1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-17 23:28:50 -05:00

Added button and logic to update an existing preset with the current configuration

This commit is contained in:
f4exb 2015-05-09 10:51:02 +02:00
parent 31fb81c66a
commit f07934cc80
10 changed files with 136 additions and 31 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
CMakeLists.txt.user*
build/*
LOCAL/*
.cproject
.project

View File

@ -16,6 +16,8 @@ public:
QString group() const;
QString description() const;
void setGroup(QString& group);
void setDescription(QString& description);
private:
enum Audio {

View File

@ -48,7 +48,7 @@ class SDRANGELOVE_API MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget* parent = NULL);
explicit MainWindow(QWidget* parent = 0);
~MainWindow();
MessageQueue* getMessageQueue() { return m_messageQueue; }
@ -121,6 +121,7 @@ private slots:
void on_iqImbalance_toggled(bool checked);
void on_action_View_Fullscreen_toggled(bool checked);
void on_presetSave_clicked();
void on_presetUpdate_clicked();
void on_presetLoad_clicked();
void on_presetDelete_clicked();
void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);

View File

@ -93,6 +93,7 @@ protected:
QByteArray m_layout;
};
Q_DECLARE_METATYPE(const Preset*)
Q_DECLARE_METATYPE(const Preset*);
Q_DECLARE_METATYPE(Preset*);
#endif // INCLUDE_PRESET_H

View File

@ -24,3 +24,13 @@ QString AddPresetDialog::description() const
{
return ui->description->text();
}
void AddPresetDialog::setGroup(QString& group)
{
ui->group->lineEdit()->setText(group);
}
void AddPresetDialog::setDescription(QString& description)
{
ui->description->setText(description);
}

View File

@ -45,8 +45,8 @@ MainWindow::MainWindow(QWidget* parent) :
m_dspEngine(new DSPEngine(m_messageQueue)),
m_lastEngineState((DSPEngine::State)-1),
m_startOsmoSDRUpdateAfterStop(false),
m_scopeWindow(NULL),
m_inputGUI(NULL),
m_scopeWindow(0),
m_inputGUI(0),
m_sampleRate(0),
m_centerFrequency(0),
m_pluginManager(new PluginManager(this, m_dspEngine))
@ -122,9 +122,9 @@ MainWindow::~MainWindow()
m_dspEngine->removeSink(m_spectrumVis);
delete m_spectrumVis;
if(m_scopeWindow != NULL) {
if(m_scopeWindow != 0) {
delete m_scopeWindow;
m_scopeWindow = NULL;
m_scopeWindow = 0;
}
delete m_pluginManager;
@ -165,9 +165,9 @@ void MainWindow::removeChannelMarker(ChannelMarker* channelMarker)
void MainWindow::setInputGUI(QWidget* gui)
{
if(m_inputGUI != NULL)
if(m_inputGUI != 0)
ui->inputDock->widget()->layout()->removeWidget(m_inputGUI);
if(gui != NULL)
if(gui != 0)
ui->inputDock->widget()->layout()->addWidget(gui);
m_inputGUI = gui;
}
@ -251,14 +251,14 @@ void MainWindow::updateSampleRate()
{
ui->glSpectrum->setSampleRate(m_sampleRate);
m_sampleRateWidget->setText(tr("Rate: %1 kHz").arg((float)m_sampleRate / 1000));
if(m_scopeWindow != NULL)
if(m_scopeWindow != 0)
m_scopeWindow->setSampleRate(m_sampleRate);
}
void MainWindow::updatePresets()
{
ui->presetTree->resizeColumnToContents(0);
if(ui->presetTree->currentItem() != NULL) {
if(ui->presetTree->currentItem() != 0) {
ui->presetDelete->setEnabled(true);
ui->presetLoad->setEnabled(true);
} else {
@ -269,14 +269,14 @@ void MainWindow::updatePresets()
QTreeWidgetItem* MainWindow::addPresetToTree(const Preset* preset)
{
QTreeWidgetItem* group = NULL;
QTreeWidgetItem* group = 0;
for(int i = 0; i < ui->presetTree->topLevelItemCount(); i++) {
if(ui->presetTree->topLevelItem(i)->text(0) == preset->getGroup()) {
group = ui->presetTree->topLevelItem(i);
break;
}
}
if(group == NULL) {
if(group == 0) {
QStringList sl;
sl.append(preset->getGroup());
group = new QTreeWidgetItem(ui->presetTree, sl, PGroup);
@ -305,7 +305,7 @@ void MainWindow::applySettings()
void MainWindow::handleMessages()
{
Message* message;
while((message = m_messageQueue->accept()) != NULL) {
while((message = m_messageQueue->accept()) != 0) {
qDebug("Message: %s", message->getIdentifier());
if(DSPEngineReport::match(message)) {
DSPEngineReport* rep = (DSPEngineReport*)message;
@ -363,7 +363,7 @@ void MainWindow::scopeWindowDestroyed()
{
ui->action_Oscilloscope->setChecked(false);
m_settings.getCurrent()->setShowScope(false);
m_scopeWindow = NULL;
m_scopeWindow = 0;
}
void MainWindow::on_action_Start_triggered()
@ -399,19 +399,26 @@ void MainWindow::on_presetSave_clicked()
{
QStringList groups;
QString group;
QString description = "";
for(int i = 0; i < ui->presetTree->topLevelItemCount(); i++)
groups.append(ui->presetTree->topLevelItem(i)->text(0));
QTreeWidgetItem* item = ui->presetTree->currentItem();
if(item != NULL) {
if(item != 0) {
if(item->type() == PGroup)
group = item->text(0);
else if(item->type() == PItem)
else if(item->type() == PItem) {
group = item->parent()->text(0);
description = item->text(0);
}
}
AddPresetDialog dlg(groups, group, this);
if (description.length() > 0) {
dlg.setDescription(description);
}
if(dlg.exec() == QDialog::Accepted) {
Preset* preset = m_settings.newPreset(dlg.group(), dlg.description());
saveSettings(preset);
@ -420,16 +427,32 @@ void MainWindow::on_presetSave_clicked()
}
}
void MainWindow::on_presetUpdate_clicked()
{
QTreeWidgetItem* item = ui->presetTree->currentItem();
if(item != 0) {
if(item->type() == PItem) {
const Preset* preset = qvariant_cast<const Preset*>(item->data(0, Qt::UserRole));
if (preset != 0) {
Preset* preset_mod = const_cast<Preset*>(preset);
saveSettings(preset_mod);
}
}
}
}
void MainWindow::on_presetLoad_clicked()
{
QTreeWidgetItem* item = ui->presetTree->currentItem();
if(item == NULL) {
if(item == 0) {
updatePresets();
return;
}
const Preset* preset = qvariant_cast<const Preset*>(item->data(0, Qt::UserRole));
if(preset == NULL)
if(preset == 0) {
return;
}
loadSettings(preset);
applySettings();
@ -438,12 +461,12 @@ void MainWindow::on_presetLoad_clicked()
void MainWindow::on_presetDelete_clicked()
{
QTreeWidgetItem* item = ui->presetTree->currentItem();
if(item == NULL) {
if(item == 0) {
updatePresets();
return;
}
const Preset* preset = qvariant_cast<const Preset*>(item->data(0, Qt::UserRole));
if(preset == NULL)
if(preset == 0)
return;
if(QMessageBox::question(this, tr("Delete Preset"), tr("Do you want to delete preset '%1'?").arg(preset->getDescription()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
@ -464,7 +487,7 @@ void MainWindow::on_presetTree_itemActivated(QTreeWidgetItem *item, int column)
void MainWindow::on_action_Oscilloscope_triggered()
{
if(m_scopeWindow != NULL) {
if(m_scopeWindow != 0) {
((QWidget*)m_scopeWindow->parent())->raise();
return;
}

View File

@ -22,7 +22,16 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -112,7 +121,16 @@
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout_6">
<property name="margin">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<property name="spacing">
@ -121,7 +139,7 @@
<item row="5" column="1">
<widget class="QToolButton" name="presetSave">
<property name="toolTip">
<string>Save current settings as preset</string>
<string>Save current settings as new preset</string>
</property>
<property name="text">
<string>...</string>
@ -138,7 +156,7 @@
</property>
</widget>
</item>
<item row="5" column="5">
<item row="5" column="6">
<widget class="QToolButton" name="presetLoad">
<property name="toolTip">
<string>Load selected preset</string>
@ -158,7 +176,7 @@
</property>
</widget>
</item>
<item row="5" column="3" colspan="2">
<item row="5" column="4" colspan="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -171,7 +189,7 @@
</property>
</spacer>
</item>
<item row="5" column="2">
<item row="5" column="3">
<widget class="QToolButton" name="presetDelete">
<property name="toolTip">
<string>Delete selected preset</string>
@ -191,7 +209,7 @@
</property>
</widget>
</item>
<item row="1" column="1" rowspan="4" colspan="5">
<item row="1" column="1" rowspan="4" colspan="6">
<widget class="QTreeWidget" name="presetTree">
<property name="allColumnsShowFocus">
<bool>true</bool>
@ -208,6 +226,26 @@
</column>
</widget>
</item>
<item row="5" column="2">
<widget class="QToolButton" name="presetUpdate">
<property name="toolTip">
<string>Update selected preset with current settings</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources/res.qrc">
<normaloff>:/preset-update.png</normaloff>:/preset-update.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -229,7 +267,16 @@
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
@ -295,7 +342,16 @@
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
@ -320,7 +376,16 @@
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
</layout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 996 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -5,6 +5,7 @@
<file>waterfall.png</file>
<file>preset-load.png</file>
<file>preset-save.png</file>
<file>preset-update.png</file>
<file>preset-delete.png</file>
<file>horizontal.png</file>
<file>vertical.png</file>