Skip to content

Commit

Permalink
Remember camera visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeyers314 committed Dec 12, 2024
1 parent 79b3c2d commit f335c21
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions plugins/MosaicCamera/src/MosaicCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MosaicCamera::MosaicCamera()
setObjectName("MosaicCamera");
configDialog = new MosaicCameraDialog();
tcpServer = new MosaicTcpServer();
conf = StelApp::getInstance().getSettings();
}

/*************************************************************************
Expand All @@ -78,6 +79,36 @@ MosaicCamera::~MosaicCamera()
delete tcpServer;
}

void MosaicCamera::loadSettings()
{
conf->beginGroup("MosaicCamera");
int size = conf->beginReadArray("cameraVisibility");
for (int i = 0; i < size; ++i) {
conf->setArrayIndex(i);
QString name = conf->value("name").toString();
bool visible = conf->value("visible").toBool();
if (cameras.contains(name)) {
cameras[name].visible = visible;
}
}
conf->endArray();
conf->endGroup();
}

void MosaicCamera::saveSettings() const
{
conf->beginGroup("MosaicCamera");
conf->beginWriteArray("cameraVisibility");
int i = 0;
for (auto it = cameras.constBegin(); it != cameras.constEnd(); ++it) {
conf->setArrayIndex(i++);
conf->setValue("name", it.key());
conf->setValue("visible", it.value().visible);
}
conf->endArray();
conf->endGroup();
}

/*************************************************************************
Reimplementation of the getCallOrder method
*************************************************************************/
Expand All @@ -104,6 +135,8 @@ void MosaicCamera::init()

qDebug() << "[MosaicCamera] Loading built-in cameras";
loadBuiltInCameras();

loadSettings();
}

void MosaicCamera::initializeUserData()
Expand Down Expand Up @@ -277,6 +310,7 @@ void MosaicCamera::setVisibility(const QString& cameraName, bool visible)
if (cameras.contains(cameraName))
{
cameras[cameraName].visible = visible;
saveSettings();
if(configDialog->visible()) {
if (configDialog->getCurrentCameraName() == cameraName) {
configDialog->setVisibility(visible);
Expand Down
5 changes: 5 additions & 0 deletions plugins/MosaicCamera/src/MosaicCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QVector>
#include <QObject>
#include <QPointF>
#include <QSettings>
#include <QString>

class MosaicCameraDialog;
Expand Down Expand Up @@ -69,6 +70,9 @@ class MosaicCamera : public StelModule
double getRotation(const QString& cameraName) const;
bool getVisibility(const QString& cameraName) const;

void loadSettings();
void saveSettings() const;

QStringList getCameraNames() const;
void readPolygonSetsFromJson(const QString& cameraName, const QString& filename);

Expand All @@ -80,6 +84,7 @@ public slots:
QStringList cameraOrder;
QString currentCamera;
QString userDirectory;
QSettings* conf;

void loadBuiltInCameras();
void loadCameraOrder();
Expand Down

0 comments on commit f335c21

Please sign in to comment.