From 5388e4edf88f82b89b053048bba310174e58ffdf Mon Sep 17 00:00:00 2001 From: Alexander Diamadis Date: Sat, 30 Oct 2021 10:39:42 +0200 Subject: [PATCH] Added Library with Amps --- PA_Calculator.pro | 7 + PA_Calculator.pro.user | 265 +++++++++++++++++++++++++++++++++++++ camp.cpp | 169 ++++++++++++++++++++++++ camp.h | 40 ++++++ campmode.cpp | 55 ++++++++ campmode.h | 25 ++++ library.cpp | 292 +++++++++++++++++++++++++++++++++++++++++ library.h | 67 ++++++++++ library.ui | 262 ++++++++++++++++++++++++++++++++++++ mainwindow.cpp | 128 ++++++++++++++++++ mainwindow.h | 20 +++ mainwindow.ui | 86 +++++++++++- 12 files changed, 1412 insertions(+), 4 deletions(-) create mode 100644 PA_Calculator.pro.user create mode 100644 camp.cpp create mode 100644 camp.h create mode 100644 campmode.cpp create mode 100644 campmode.h create mode 100644 library.cpp create mode 100644 library.h create mode 100644 library.ui diff --git a/PA_Calculator.pro b/PA_Calculator.pro index ba6785a..c0751cb 100644 --- a/PA_Calculator.pro +++ b/PA_Calculator.pro @@ -9,13 +9,20 @@ CONFIG += c++11 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + camp.cpp \ + campmode.cpp \ + library.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ + camp.h \ + campmode.h \ + library.h \ mainwindow.h FORMS += \ + library.ui \ mainwindow.ui TRANSLATIONS += \ diff --git a/PA_Calculator.pro.user b/PA_Calculator.pro.user new file mode 100644 index 0000000..50078a5 --- /dev/null +++ b/PA_Calculator.pro.user @@ -0,0 +1,265 @@ + + + + + + EnvironmentId + {359d7bfd-1567-4775-8a40-a2007ce8d5cf} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop (x86-darwin-generic-mach_o-64bit) + Desktop (x86-darwin-generic-mach_o-64bit) + {d8252245-f945-4509-808c-c5c3d78024ca} + 0 + 0 + 0 + + 0 + /Users/alexanderdiamadis/build-PA_Calculator-Desktop_x86_darwin_generic_mach_o_64bit-Debug + /Users/alexanderdiamadis/build-PA_Calculator-Desktop_x86_darwin_generic_mach_o_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /Users/alexanderdiamadis/build-PA_Calculator-Desktop_x86_darwin_generic_mach_o_64bit-Release + /Users/alexanderdiamadis/build-PA_Calculator-Desktop_x86_darwin_generic_mach_o_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /Users/alexanderdiamadis/build-PA_Calculator-Desktop_x86_darwin_generic_mach_o_64bit-Profile + /Users/alexanderdiamadis/build-PA_Calculator-Desktop_x86_darwin_generic_mach_o_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deployment + Deployment + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/Users/alexanderdiamadis/PA_Calculator/PA_Calculator.pro + /Users/alexanderdiamadis/PA_Calculator/PA_Calculator.pro + false + true + true + false + true + /Users/alexanderdiamadis/build-PA_Calculator-Desktop_x86_darwin_generic_mach_o_64bit-Debug/PA_Calculator.app/Contents/MacOS + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/camp.cpp b/camp.cpp new file mode 100644 index 0000000..c2d5c2a --- /dev/null +++ b/camp.cpp @@ -0,0 +1,169 @@ +#include "camp.h" +#include + +cAmp::cAmp() +{ + m_numAmpModes=0; + m_name="untitled"; + m_sensitvity=1; + m_sensivityUnit=volt; + m_numAmpModes=0; + m_pAmpModes = nullptr; +} + +cAmp::~cAmp() +{ + delete [] m_pAmpModes; +} + +cAmp::cAmp(std::string name, double sensitivity, sensitivityUnit sensUnit) +{ + m_name=name; + m_sensitvity=sensitivity; + m_sensivityUnit=sensUnit; + m_numAmpModes=0; + m_pAmpModes = nullptr; +} + +std::string cAmp::getName() +{ + return m_name; +} + +void cAmp::setName(std::string name) +{ + m_name=name; +} + +void cAmp::setName(QString name) +{ + m_name=name.toStdString(); +} + +void cAmp::setSensivity(double sens) +{ + m_sensitvity=sens; +} + + +void cAmp::setSensUnit(sensitivityUnit unit) +{ + m_sensivityUnit=unit; +} + + +double cAmp::getSensitivity() +{ + return m_sensitvity; +} + +sensitivityUnit cAmp::getSensivityUnit() +{ + return m_sensivityUnit; +} + +cAmpMode *cAmp::getAmpModes() +{ + return m_pAmpModes; +} + +cAmpMode cAmp::getAmpMode(unsigned int idx) +{ + return m_pAmpModes[idx]; +} + +unsigned int cAmp::getAmpModesCount() +{ + return m_numAmpModes; +} + +void cAmp::addAmpMode(cAmpMode mode) +{ + m_numAmpModes+=1; + cAmpMode* tempAmpModes = new cAmpMode[m_numAmpModes]; + for (unsigned int i=0;i=m_numAmpModes){ + return false; + }else{ + m_pAmpModes[idx]=mode; + return true; + } +} + +void cAmp::deleteAmpMode(unsigned int idx) +{ + if (m_numAmpModes>=1){ + m_numAmpModes-=1; + cAmpMode* tempAmpModes = new cAmpMode[m_numAmpModes]; + for (unsigned int i=0;i>(QDataStream& in, cAmp& amp){ + //quint64 size; + //in >> size; + QString name; + in >> name; + amp.setName(name); + + qreal sensitiviy; + in >>sensitiviy; + amp.setSensivity((double)sensitiviy); + + qint32 unit; + in >> unit; + amp.setSensUnit(sensitivityUnit(unit)); + + uint numAmpModes; + in >> numAmpModes; + + for (uint i=0;i> Mode; + amp.addAmpMode(Mode); + } + return in; +} diff --git a/camp.h b/camp.h new file mode 100644 index 0000000..10f211b --- /dev/null +++ b/camp.h @@ -0,0 +1,40 @@ +#ifndef CAMP_H +#define CAMP_H +#include "campmode.h" + +enum sensitivityUnit { volt, dBu }; + +class cAmp +{ +public: + cAmp(); + ~cAmp(); + cAmp(std::string name, double sensitivity, sensitivityUnit sensUnit); + std::string getName(); + void setName(std::string name); + void setName(QString name); + void setSensivity(double sens); + void setSensUnit(sensitivityUnit unit); + double getSensitivity(); + sensitivityUnit getSensivityUnit(); + cAmpMode* getAmpModes(); + cAmpMode getAmpMode(unsigned int idx); + unsigned int getAmpModesCount(); + void addAmpMode(cAmpMode mode); + bool modifyAmpMode(unsigned int idx, cAmpMode mode); + void deleteAmpMode(unsigned int idx); + void setAmpMode(unsigned int idx, cAmpMode mode); + void print(); + + friend QDataStream& operator <<(QDataStream& out, cAmp& amp); + friend QDataStream& operator >>(QDataStream& in, cAmp& amp); +private: + std::string m_name; + double m_sensitvity; + sensitivityUnit m_sensivityUnit; + + cAmpMode* m_pAmpModes; + unsigned int m_numAmpModes; +}; + +#endif // CAMP_H diff --git a/campmode.cpp b/campmode.cpp new file mode 100644 index 0000000..c42c901 --- /dev/null +++ b/campmode.cpp @@ -0,0 +1,55 @@ +#include "campmode.h" +#include +cAmpMode::cAmpMode() +{ + +} + +cAmpMode::cAmpMode(std::string name, unsigned int ratedImp, unsigned int ratedPower){ + m_name=name; + m_ratedImp=ratedImp; + m_ratedPower=ratedPower; +} + +std::string cAmpMode::getName() +{ + return m_name; +} + +unsigned int cAmpMode::getRatedImp() +{ + return m_ratedImp; +} + +unsigned int cAmpMode::getRatedPower() +{ + return m_ratedPower; +} + +void cAmpMode::print() +{ + std::cout << "Mode: "<< m_name<<" ("<>(QDataStream& in, cAmpMode& mode){ + QString name; + in >> name; + mode.m_name=name.toStdString(); + + uint imp; + in >> imp; + mode.m_ratedImp=(unsigned int)imp; + + uint power; + in >> power; + mode.m_ratedPower=(unsigned int)power; + + return in; +} diff --git a/campmode.h b/campmode.h new file mode 100644 index 0000000..87cb2e7 --- /dev/null +++ b/campmode.h @@ -0,0 +1,25 @@ +#ifndef CAMPMODE_H +#define CAMPMODE_H + +#include +#include +#include +class cAmpMode +{ +public: + cAmpMode(); + cAmpMode(std::string name, unsigned int ratedImp, unsigned int ratedPower); + std::string getName(); + unsigned int getRatedImp(); + unsigned int getRatedPower(); + void print(); + + friend QDataStream& operator <<(QDataStream& out, cAmpMode& mode); + friend QDataStream& operator >>(QDataStream& in, cAmpMode& mode); +private: + std::string m_name; + unsigned int m_ratedImp; + unsigned int m_ratedPower; +}; + +#endif // CAMPMODE_H diff --git a/library.cpp b/library.cpp new file mode 100644 index 0000000..b0cd632 --- /dev/null +++ b/library.cpp @@ -0,0 +1,292 @@ +#include "library.h" +#include "ui_library.h" +#include +#include +#include +#include +#include + +library::library(QWidget *parent) : + QDialog(parent), + ui(new Ui::library) +{ + ui->setupUi(this); + unsaved=false; +} + +library::~library() +{ + delete ui; +} + +void library::setAmpPointer(cAmp *pAmp, unsigned int ampCount){ + m_pCamp=pAmp; + m_cAmpCount=ampCount; +} + +unsigned int library::getAmpCount() +{ + return m_cAmpCount; +} + +cAmp *library::getAmps() +{ + return m_pCamp; +} + +void library::open() +{ + + ui->listWidget_ampView->setCurrentRow(0); + QSettings settings("DKM-Tech","Pa-Calculator"); + if (settings.value("library/path","")==""){ + settings.setValue("library/path",QFileDialog::getSaveFileName(this,"Select Library Storage File","","Pa Calculator Library File (*.palib)")); + } + //qDebug() << settings.value("library/path","none").toString(); + refreshAmpView(); + this->exec(); + saveLibraryToFile(); +} + + + +void library::on_pushButton_addAmp_clicked() +{ + m_cAmpCount+=1; + cAmp* tempAmps=new cAmp[m_cAmpCount]; + for (unsigned int i=0;ilistWidget_ampView->setCurrentRow(m_cAmpCount-1); + ui->lineEdit_ampName->setFocus(); + ui->lineEdit_ampName->selectAll(); +} + +void library::refreshAmpView() +{ + ui->listWidget_ampView->clear(); + for (unsigned int i=0;ilistWidget_ampView->addItem(QString::fromStdString(m_pCamp[i].getName())); + } + //std::cerr<<"refreshAmpView started"<listWidget_modeSelector->clear(); + if (m_cAmpCount>0){ + if (m_pCamp[getCurrentAmpIndex()].getAmpModesCount()>0){ + for (unsigned int i=0;ilistWidget_modeSelector->addItem(QString::fromStdString(m_pCamp[getCurrentAmpIndex()].getAmpMode(i).getName())); + //std::cout <<"mode "<listWidget_ampView->currentRow(); +} + +int library::getCurrentAmpModeIndex() +{ + return ui->listWidget_modeSelector->currentRow(); +} + +void library::printAllAmps() +{ + std::cout << "Number of Amps: "<=0){ + ui->lineEdit_ampName->setText(QString::fromStdString(m_pCamp[currentRow].getName())); + ui->comboBox_sensUnit->setCurrentIndex(m_pCamp[currentRow].getSensivityUnit()); + ui->doubleSpinBox_inputSensitivity->setValue(m_pCamp[currentRow].getSensitivity()); + refreshModeOverview(); + ui->listWidget_modeSelector->setCurrentRow(0); + ui->lineEdit_ampName->setEnabled(true); + ui->doubleSpinBox_inputSensitivity->setEnabled(true); + }else + { + ui->lineEdit_ampName->setEnabled(false); + ui->doubleSpinBox_inputSensitivity->setEnabled(false); + } +} + + + +void library::on_pushButton_applyChanges_clicked() +{ + if (getCurrentAmpIndex()>=0){ + m_pCamp[getCurrentAmpIndex()].setName(ui->lineEdit_ampName->text().toStdString()); + m_pCamp[getCurrentAmpIndex()].setSensivity(ui->doubleSpinBox_inputSensitivity->value()); + sensitivityUnit currentSens; + if (ui->comboBox_sensUnit->currentIndex()==0){ + currentSens=volt; + }else{ + currentSens=dBu; + } + m_pCamp[getCurrentAmpIndex()].setSensUnit(currentSens); + int selectedRow=getCurrentAmpIndex(); + refreshAmpView(); + ui->listWidget_ampView->setCurrentRow(selectedRow); + } + +} + + +void library::on_comboBox_sensUnit_currentIndexChanged(int index) +{ + double oldValue=ui->doubleSpinBox_inputSensitivity->value(); + if (index==0){ + ui->doubleSpinBox_inputSensitivity->setSuffix(QString(" V")); + ui->doubleSpinBox_inputSensitivity->setDecimals(2); + ui->doubleSpinBox_inputSensitivity->setValue(0.7746*qPow(10,oldValue/20)); + }else{ + ui->doubleSpinBox_inputSensitivity->setSuffix(QString(" dBu")); + ui->doubleSpinBox_inputSensitivity->setDecimals(1); + ui->doubleSpinBox_inputSensitivity->setValue(20*std::log10(oldValue/0.7746)); + } + +} + + +void library::on_pushButton_deleteAmp_clicked() +{ + if (getCurrentAmpIndex()>=0){ + m_cAmpCount-=1; + cAmp* tempAmps=new cAmp[m_cAmpCount]; + unsigned int selectedRow=getCurrentAmpIndex(); + for (unsigned int i=0;i0){ + ui->listWidget_ampView->setCurrentRow(0); + }else + { + ui->listWidget_ampView->setCurrentRow(selectedRow-1); + } + } + + +} + +void library::on_pushButton_addMode_clicked() +{ + if (getCurrentAmpIndex()>=0) + { + if (ui->lineEdit_modeName->text()==""){ + QMessageBox msgBox(QMessageBox::Warning,"No mode name","Mode name can't be empty. Please enter a name."); + msgBox.exec(); + }else{ + cAmpMode mode(ui->lineEdit_modeName->text().toStdString(),ui->spinBox_ratedImp->value(),ui->spinBox_ratedPower->value()); + m_pCamp[getCurrentAmpIndex()].addAmpMode(mode); + } + } + refreshModeOverview(); +} + + +void library::on_listWidget_modeSelector_currentRowChanged(int currentRow) +{ + if (getCurrentAmpIndex()>=0){ + if (currentRow >=0){ + ui->lineEdit_modeName->setText(QString::fromStdString(m_pCamp[getCurrentAmpIndex()].getAmpMode(getCurrentAmpModeIndex()).getName())); + ui->spinBox_ratedImp->setValue(m_pCamp[getCurrentAmpIndex()].getAmpMode(getCurrentAmpModeIndex()).getRatedImp()); + ui->spinBox_ratedPower->setValue(m_pCamp[getCurrentAmpIndex()].getAmpMode(getCurrentAmpModeIndex()).getRatedPower()); + } + } + +} + + +void library::on_pushButton_deleteMode_clicked() +{ + int selectedRow=getCurrentAmpModeIndex(); + m_pCamp[getCurrentAmpIndex()].deleteAmpMode(getCurrentAmpModeIndex()); + refreshModeOverview(); + if (selectedRow-1<0 && m_pCamp[getCurrentAmpIndex()].getAmpModesCount()){ + ui->listWidget_modeSelector->setCurrentRow(0); + }else + { + ui->listWidget_modeSelector->setCurrentRow(selectedRow-1); + } +} + + +void library::on_pushButton_applyMode_clicked() +{ + unsaved =false; + if (ui->lineEdit_modeName->text()==""){ + QMessageBox msgBox(QMessageBox::Warning,"No mode name","Mode name can't be empty. Please enter a name."); + msgBox.exec(); + }else{ + cAmpMode mode(ui->lineEdit_modeName->text().toStdString(),ui->spinBox_ratedImp->value(),ui->spinBox_ratedPower->value()); + m_pCamp[getCurrentAmpIndex()].setAmpMode(getCurrentAmpModeIndex(),mode); + } + int selectedMode=getCurrentAmpModeIndex(); + refreshModeOverview(); + ui->listWidget_modeSelector->setCurrentRow(selectedMode); +} + + +void library::on_lineEdit_ampName_textEdited(const QString &arg1) +{ + if (unsaved==false){ + ui->listWidget_ampView->currentItem()->setText(ui->listWidget_ampView->currentItem()->text()+QString::fromStdString("*")); + unsaved =true; + } +} + diff --git a/library.h b/library.h new file mode 100644 index 0000000..8e69d59 --- /dev/null +++ b/library.h @@ -0,0 +1,67 @@ +#ifndef LIBRARY_H +#define LIBRARY_H + +#include +#include "camp.h" +namespace Ui { +class library; +} + +class library : public QDialog +{ + Q_OBJECT + +public: + explicit library(QWidget *parent = nullptr); + void setAmpPointer(cAmp* pAmp,unsigned int ampCount); + unsigned int getAmpCount(); + cAmp* getAmps(); + void open(); + ~library(); + + +private slots: + + void on_pushButton_addAmp_clicked(); + + void on_listWidget_ampView_currentRowChanged(int currentRow); + + + void on_pushButton_applyChanges_clicked(); + + void on_comboBox_sensUnit_currentIndexChanged(int index); + + void on_pushButton_deleteAmp_clicked(); + + void on_pushButton_addMode_clicked(); + + + void on_listWidget_modeSelector_currentRowChanged(int currentRow); + + + void on_pushButton_deleteMode_clicked(); + + void on_pushButton_applyMode_clicked(); + + void on_lineEdit_ampName_textEdited(const QString &arg1); + + +private: + Ui::library *ui; + cAmp* m_pCamp; + unsigned int m_cAmpCount; + + void refreshAmpView(); + void refreshAmpOverview(); + void refreshModeOverview(); + + int getCurrentAmpIndex(); + int getCurrentAmpModeIndex(); + + void printAllAmps(); + bool unsaved; + + void saveLibraryToFile(); +}; + +#endif // LIBRARY_H diff --git a/library.ui b/library.ui new file mode 100644 index 0000000..6086736 --- /dev/null +++ b/library.ui @@ -0,0 +1,262 @@ + + + library + + + + 0 + 0 + 913 + 480 + + + + Dialog + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + Amplifiers + + + + + + + + + + + + + Add + + + + + + + Delete + + + + + + + Apply + + + + + + + + + + + + + + + Name + + + + + + + false + + + + + + + Input Sensitivity + + + + + + + false + + + V + + + 0.010000000000000 + + + + + + + + in Volt + + + + + in dBu + + + + + + + + + + Add/Change Mode + + + + + + + + Mode Name + + + + + + + + + + Rated Power + + + + + + + W + + + 1 + + + 10000 + + + + + + + Rated Impedance + + + + + + + Ohm + + + 1 + + + 32 + + + 8 + + + + + + + + + + + + + + Add mode + + + + + + + Delete mode + + + + + + + Apply + + + + + + + + + + + + + + + Tab 2 + + + + + + + + + + buttonBox + accepted() + library + accept() + + + 244 + 444 + + + 157 + 274 + + + + + buttonBox + rejected() + library + reject() + + + 312 + 444 + + + 286 + 274 + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 9b5e41f..b55e3fc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,16 +3,28 @@ #include #include #include +#include "library.h" +#include +#include +#include +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + m_ampCount=0; + m_pCAmp=Q_NULLPTR; + loadLibrary(); + refreshLibraryAmps(); + refreshLibraryAmpModes(); } MainWindow::~MainWindow() { delete ui; + delete [] m_pCAmp; } void MainWindow::on_ComboBox_selectSensUnit_currentIndexChanged(int index) @@ -104,3 +116,119 @@ void MainWindow::on_pushButton_requestLimiter_clicked() } + +void MainWindow::on_actionEditLibrary_triggered() +{ + library* dialog=new library; + dialog->setAmpPointer(m_pCAmp,m_ampCount); + dialog->open(); + m_ampCount=dialog->getAmpCount(); + m_pCAmp=dialog->getAmps(); + refreshLibraryAmps(); + refreshLibraryAmpModes(); + delete dialog; +} + +void MainWindow::refreshLibraryAmps() +{ + ui->comboBox_libraryAmp->clear(); + for (unsigned int i=0;icomboBox_libraryAmp->addItem(QString::fromStdString(m_pCAmp[i].getName())); + } +} + +void MainWindow::refreshLibraryAmpModes() +{ + ui->comboBox_libraryAmoMode->clear(); + if (ui->comboBox_libraryAmp->currentIndex()>=0){ + for (unsigned int i=0;icomboBox_libraryAmp->currentIndex()].getAmpModesCount();i++){ + ui->comboBox_libraryAmoMode->addItem(QString::fromStdString(m_pCAmp[ui->comboBox_libraryAmp->currentIndex()].getAmpMode(i).getName())); + } + } +} + +void MainWindow::loadLibrary() +{ + QSettings settings("DKM-Tech","Pa-Calculator"); + QString fileName = settings.value("library/path",QString::fromStdString("")).toString(); + if (fileName.isEmpty()) + return; + else { + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + QMessageBox::information(this, tr("Unable to open file. Will create a new one."),file.errorString()); + return; + } + QDataStream in(&file); + in.setVersion(QDataStream::Qt_4_5); + uint count; + in >> count; + m_ampCount=count; + if (m_ampCount>0){ + delete[] m_pCAmp; + m_pCAmp=new cAmp[m_ampCount]; + } + for (unsigned int j=0;j> m_pCAmp[j]; + } + } +} + +void MainWindow::saveLibrary() +{ + QSettings settings("DKM-Tech","Pa-Calculator"); + QString fileName = settings.value("library/path",QString::fromStdString("")).toString(); + if (fileName.isEmpty()) + return; + else { + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly)) { + QMessageBox::information(this, tr("Unable to open file"), + file.errorString()); + return; + } + QDataStream out(&file); + out.setVersion(QDataStream::Qt_4_5); + out << (uint)m_ampCount; + for (unsigned int j=0;jcomboBox_libraryAmp->currentIndex()>=0 && ui->comboBox_libraryAmoMode->currentIndex()>=0){ + if (m_pCAmp[ui->comboBox_libraryAmp->currentIndex()].getAmpModesCount()>=1){ + ui->spinBox_AmpPower->setValue(m_pCAmp[ui->comboBox_libraryAmp->currentIndex()].getAmpMode(ui->comboBox_libraryAmoMode->currentIndex()).getRatedPower()); + ui->spinBox_AmpImp->setValue(m_pCAmp[ui->comboBox_libraryAmp->currentIndex()].getAmpMode(ui->comboBox_libraryAmoMode->currentIndex()).getRatedImp()); + ui->ComboBox_selectSensUnit->setCurrentIndex(m_pCAmp[ui->comboBox_libraryAmp->currentIndex()].getSensivityUnit()); + ui->doubleSpinBox_ampInputSens->setValue(m_pCAmp[ui->comboBox_libraryAmp->currentIndex()].getSensitivity()); + } + + } +} + + +void MainWindow::on_actionChange_Library_Location_triggered() +{ + QSettings settings("DKM-Tech","Pa-Calculator"); + settings.setValue("library/path",QFileDialog::getSaveFileName(this,"Where to store the storage file?",settings.value("library/path",QString::fromStdString("")).toString(),"Pa Calculator Library File (*.palib)")); + saveLibrary(); +} + + +void MainWindow::on_actionOpen_Library_triggered() +{ + QSettings settings("DKM-Tech","Pa-Calculator"); + settings.setValue("library/path",QFileDialog::getOpenFileName(this,"Select library storage file",settings.value("library/path",QString::fromStdString("")).toString(),"Pa Calculator Library File (*.palib)")); + loadLibrary(); + refreshLibraryAmps(); +} + diff --git a/mainwindow.h b/mainwindow.h index 9c534f3..8d51270 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include "camp.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -20,7 +21,26 @@ private slots: void on_pushButton_requestLimiter_clicked(); + void on_actionEditLibrary_triggered(); + + void on_comboBox_libraryAmp_currentIndexChanged(int index); + + void on_pushButton_clicked(); + + void on_actionChange_Library_Location_triggered(); + + void on_actionOpen_Library_triggered(); + private: Ui::MainWindow *ui; + cAmp* m_pCAmp; + unsigned int m_ampCount; + + void refreshLibraryAmps(); + void refreshLibraryAmpModes(); + + void loadLibrary(); + void saveLibrary(); + }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 4ae13a0..a7f74a6 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 931 - 460 + 1084 + 608 @@ -113,6 +113,60 @@ + + + + Load amp from library + + + + + + + + 175 + 0 + + + + + + + + select mode + + + + + + + + 175 + 0 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Load Preset + + + @@ -528,12 +582,36 @@ 0 0 - 931 - 22 + 1084 + 24 + + + Library + + + + + + + + + Edit Library + + + + + Save Library As + + + + + Open Library + +