Skip to content

Commit

Permalink
Added functionality to set sim frequency and save it to project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjell Morgenstern authored and KjellMorgenstern committed Dec 29, 2023
1 parent dbdbe34 commit 38e4fb6
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 3 deletions.
38 changes: 37 additions & 1 deletion src/dialogs/prefsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#include <QSpinBox>
#include <QSettings>
#include <QLineEdit>
#include <QString>

#define MARGIN 5
#define FORMLABELWIDTH 195
Expand Down Expand Up @@ -64,8 +65,10 @@ void PrefsDialog::initViewInfo(int index, const QString & viewName, const QStrin
m_viewInfoThings[index].curvy = curvy;
}

void PrefsDialog::initLayout(QFileInfoList & languages, QList<Platform *> platforms)
void PrefsDialog::initLayout(QFileInfoList & languages, QList<Platform *> platforms, MainWindow * mainWindow)
{
m_mainWindow = mainWindow;
m_projectProperties = mainWindow->getProjectProperties();
m_tabWidget = new QTabWidget();
m_general = new QWidget();
m_breadboard = new QWidget();
Expand Down Expand Up @@ -166,6 +169,7 @@ void PrefsDialog::initBetaFeatures(QWidget * widget)
QVBoxLayout * vLayout = new QVBoxLayout();
vLayout->addWidget(createSimulatorBetaFeaturesForm());
vLayout->addWidget(createGerberBetaFeaturesForm());
vLayout->addWidget(createProjectPropertiesForm());
vLayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Preferred, QSizePolicy::Expanding));
widget->setLayout(vLayout);
}
Expand Down Expand Up @@ -491,6 +495,38 @@ QWidget * PrefsDialog::createSimulatorBetaFeaturesForm() {
return simulator;
}

QWidget *PrefsDialog::createProjectPropertiesForm() {
QGroupBox * projectPropertiesBox = new QGroupBox(tr("Project properties"), this );

QVBoxLayout * layout = new QVBoxLayout();
layout->setSpacing(SPACING);

QLabel * label = new QLabel(tr("Here you can set some settings that will be saved with the project"));
label->setWordWrap(true);
layout->addWidget(label);
layout->addSpacing(10);

QLabel *simFrequencyLabel = new QLabel(tr("Simulation Frequency (Hz):"));
layout->addWidget(simFrequencyLabel);

QLineEdit *simFrequencyEdit = new QLineEdit();

simFrequencyEdit->setText(m_projectProperties->getProjectProperty(ProjectPropertyKeySimulatorFrequencyHz));
simFrequencyEdit->setFixedWidth(FORMLABELWIDTH * 2);
layout->addWidget(simFrequencyEdit);

projectPropertiesBox->setLayout(layout);

connect(simFrequencyEdit, SIGNAL(textChanged(QString)), this, SLOT(setSimulationFrequency(QString)));

return projectPropertiesBox;

}

void PrefsDialog::setSimulationFrequency(const QString &frequency) {
m_projectProperties->setProjectProperty(ProjectPropertyKeySimulatorFrequencyHz, frequency);
}

void PrefsDialog::clear() {
m_cleared = true;
accept();
Expand Down
8 changes: 7 additions & 1 deletion src/dialogs/prefsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#include <QPointer>

#include "../program/platform.h"
#include "../mainwindow/mainwindow.h"
#include "../project_properties.h"

struct ViewInfoThing
{
Expand All @@ -54,7 +56,7 @@ class PrefsDialog : public QDialog
bool cleared();
QHash<QString, QString> & settings();
QHash<QString, QString> & tempSettings();
void initLayout(QFileInfoList & languages, QList<Platform *> platforms);
void initLayout(QFileInfoList & languages, QList<Platform *> platforms, MainWindow * mainWindow);
void initViewInfo(int index, const QString & viewName, const QString & shortName, bool curvy);

protected:
Expand All @@ -66,6 +68,7 @@ class PrefsDialog : public QDialog
QWidget *createProgrammerForm(QList<Platform *> platforms);
QWidget *createSimulatorBetaFeaturesForm();
QWidget *createGerberBetaFeaturesForm();
QWidget *createProjectPropertiesForm();
void updateWheelText();
void initGeneral(QWidget * general, QFileInfoList & languages);
void initBreadboard(QWidget *, ViewInfoThing *);
Expand All @@ -85,6 +88,7 @@ protected Q_SLOTS:
void changeAutosavePeriod(int);
void curvyChanged();
void chooseProgrammer();
void setSimulationFrequency(const QString &frequency);

protected:
QPointer<QTabWidget> m_tabWidget;
Expand All @@ -106,6 +110,8 @@ protected Q_SLOTS:
bool m_cleared = false;
int m_wheelMapping = 0;
ViewInfoThing m_viewInfoThings[3];
MainWindow * m_mainWindow;
QSharedPointer<ProjectProperties> m_projectProperties;
};

#endif
2 changes: 1 addition & 1 deletion src/fapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ void FApplication::preferencesAfter()

QList<Platform *> platforms = mainWindow->programmingWidget()->getAvailablePlatforms();

prefsDialog.initLayout(languages, platforms);
prefsDialog.initLayout(languages, platforms, mainWindow);
if (QDialog::Accepted == prefsDialog.exec()) {
updatePrefs(prefsDialog);
}
Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,10 @@ void MainWindow::triggerSimulator() {
m_simulator->triggerSimulation();
}

QSharedPointer<ProjectProperties> MainWindow::getProjectProperties() {
return m_projectProperties;
}

bool MainWindow::isSimulatorEnabled() {
return m_simulator->isEnabled();
}
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class MainWindow : public FritzingWindow
bool isSimulatorEnabled();
void enableSimulator(bool);
void triggerSimulator();
QSharedPointer<ProjectProperties> getProjectProperties();

public:
static void initNames();
Expand Down
2 changes: 2 additions & 0 deletions src/model/modelbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ bool ModelBase::loadFromFile(const QString & fileName, ModelBase * referenceMode
}
ModelPartSharedRoot * modelPartSharedRoot = this->rootModelPartShared();

Q_EMIT loadedProjectProperties(root.firstChildElement("project_properties"));

QDomElement title = root.firstChildElement("title");
if (!title.isNull()) {
if (modelPartSharedRoot != nullptr) {
Expand Down
4 changes: 4 additions & 0 deletions src/project_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#include <utility>

ProjectProperties::ProjectProperties() {
m_propertiesMap[ProjectPropertyKeySimulatorFrequencyHz] = "400";
m_keys = QStringList(m_propertiesMap.keys());
}

Expand Down Expand Up @@ -66,3 +67,6 @@ QString ProjectProperties::getProjectProperty(const QString & key) {
return m_propertiesMap[key];
}

void ProjectProperties::setProjectProperty(const QString & key, QString value) {
m_propertiesMap[key] = value;
}
3 changes: 3 additions & 0 deletions src/project_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#include <QXmlStreamWriter>
#include <QDomElement>

const QString ProjectPropertyKeySimulatorFrequencyHz = "simulator_frequency_hz";

class ProjectProperties {
public:
ProjectProperties();
Expand All @@ -35,6 +37,7 @@ class ProjectProperties {
void saveProperties(QXmlStreamWriter & streamWriter);
void load(const QDomElement & projectProperties);
QString getProjectProperty(const QString & key);
void setProjectProperty(const QString & key, QString value);

private:
QMap<QString, QString> m_propertiesMap;
Expand Down

0 comments on commit 38e4fb6

Please sign in to comment.