Skip to content

Commit

Permalink
Refactor our Configuration Dialog and Implement the Remote Object Cac…
Browse files Browse the repository at this point in the history
…he Setting
  • Loading branch information
Fishwaldo committed Jun 15, 2020
1 parent 1ed65a7 commit e06f64e
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 119 deletions.
165 changes: 76 additions & 89 deletions ozwadmin-main/configuration.cpp

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions ozwadmin-main/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ class Configuration : public QDialog
private:
Ui::Configuration *ui;
QSettings settings;
QtTreePropertyBrowser *m_OZWEditor;
QtVariantPropertyManager *m_OZWvariantManager;
QtEnumPropertyManager *m_OZWenumManager;
QtVariantPropertyManager *m_variantManager;
QtEnumPropertyManager *m_enumManager;

QtTreePropertyBrowser *m_OZWEditor;
QtTreePropertyBrowser *m_NetworkEditor;
QtVariantPropertyManager *m_NetvariantManager;
QtEnumPropertyManager *m_NetenumManager;


QMap<QString, QtProperty *> m_variantToProperty;
Expand Down
3 changes: 2 additions & 1 deletion ozwadmin-main/logwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void LogWindow::init() {

void LogWindow::logsReady(bool ready) {
if (ready) {
this->m_log->syncroniseLogs();
if (OZWCore::get()->settings.retriveLogBuffer() == true)
this->m_log->syncroniseLogs();
}
}
36 changes: 24 additions & 12 deletions ozwadmin-main/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,40 @@ void MainWindow::QTOZW_Ready(bool ready) {
qCDebug(ozwadmin) << "QTOZW Ready";

/* apply our Local Configuration Options to the OZW Options Class */
OZWCore::get()->settings.beginGroup("openzwave");
QStringList optionlist = OZWCore::get()->settings.allKeys();

QSettings().beginGroup("openzwave");
QStringList optionlist = QSettings().allKeys();
for (int i = 0; i < optionlist.size(); i++) {
qCDebug(ozwadmin) << "Updating Option " << optionlist.at(i) << " to " << OZWCore::get()->settings.value(optionlist.at(i));
qCDebug(ozwadmin) << "Updating Option " << optionlist.at(i) << " to " << QSettings().value(optionlist.at(i));
QTOZWOptions *ozwoptions = OZWCore::get()->getQTOZWManager()->getOptions();
QStringList listtypes;
listtypes << "SaveLogLevel" << "QueueLogLevel" << "DumpLogLevel";
if (listtypes.contains(optionlist.at(i))) {
OptionList list = ozwoptions->property(optionlist.at(i).toLocal8Bit()).value<OptionList>();
if (list.getEnums().size() > 0)
list.setSelected(OZWCore::get()->settings.value(optionlist.at(i)).toString());
list.setSelected(QSettings().value(optionlist.at(i)).toString());
}
else
{
ozwoptions->setProperty(optionlist.at(i).toLocal8Bit(), OZWCore::get()->settings.value(optionlist.at(i)));
ozwoptions->setProperty(optionlist.at(i).toLocal8Bit(), QSettings().value(optionlist.at(i)));
}
}
OZWCore::get()->settings.endGroup();
QSettings().endGroup();
openDefaultWindows();
}
void MainWindow::openDefaultWindows() {

if ((OZWCore::get()->getQTOZWManager()->getNodeModel()->rowCount() > (int)OZWCore::get()->settings.networkCache()) ||
(OZWCore::get()->getQTOZWManager()->getValueModel()->rowCount() > (int)OZWCore::get()->settings.networkCache()) ||
(OZWCore::get()->getQTOZWManager()->getAssociationModel()->rowCount() > (int)OZWCore::get()->settings.networkCache())) {
quint32 size = OZWCore::get()->getQTOZWManager()->getNodeModel()->rowCount();
size = qMax<int>(size, OZWCore::get()->getQTOZWManager()->getValueModel()->rowCount());
size = qMax<int>(size, OZWCore::get()->getQTOZWManager()->getAssociationModel()->rowCount());
QString msg("Please Increase the Network Cache Size in the Configuration. Current Setting: %1 Remote Max Records: %2");
this->openCriticalDialog("Network Cache Size Insufficent", msg.arg(OZWCore::get()->settings.networkCache()).arg(size));
QCoreApplication::exit(-1);
}

this->ntw = new nodeTableWidget(this);
DeviceInfo *di = new DeviceInfo(this);
NodeStatus *ni = new NodeStatus(this);
Expand Down Expand Up @@ -214,7 +226,7 @@ void MainWindow::OpenConnection() {
}
else
{
OZWCore::get()->settings.setValue("connection/startserver", su.getstartServer());
QSettings().setValue("connection/startserver", su.getstartServer());
connectToLocal(su.getserialPort());
return;
}
Expand All @@ -227,18 +239,18 @@ void MainWindow::OpenConnection() {

void MainWindow::connectToLocal(QString serial) {
this->connected(true);
OZWCore::get()->settings.setValue("connection/serialport", serial);
qCDebug(ozwadmin) << "Doing Local Connection: " << serial << OZWCore::get()->settings.value("StartServer").toBool();
QSettings().setValue("connection/serialport", serial);
qCDebug(ozwadmin) << "Doing Local Connection: " << serial << QSettings().value("StartServer").toBool();
startupprogress *sup = new startupprogress(false, this);
sup->show();
OZWCore::get()->getQTOZWManager()->initilizeSource(OZWCore::get()->settings.value("connection/startserver").toBool());
OZWCore::get()->getQTOZWManager()->initilizeSource(QSettings().value("connection/startserver").toBool());
OZWCore::get()->getQTOZWManager()->open(serial);
}

void MainWindow::connectToRemote(QUrl server, QString key) {
this->connected(true);
OZWCore::get()->settings.setValue("connection/remotehost", server);
OZWCore::get()->settings.setValue("connection/authKey", key);
QSettings().setValue("connection/remotehost", server);
QSettings().setValue("connection/authKey", key);
qCDebug(ozwadmin) << "Doing Remote Connection:" << server;
startupprogress *sup = new startupprogress(true, this);
sup->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
Expand Down
84 changes: 82 additions & 2 deletions ozwadmin-main/ozwcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ OZWCore *OZWCore::get() {


void OZWCore::initilize() {
m_configpath = QFileInfo(settings.value("openzwave/ConfigPath").toString()).absoluteFilePath();
m_userpath = QFileInfo(settings.value("openzwave/UserPath").toString()).absoluteFilePath();
m_configpath = QFileInfo(QSettings().value("openzwave/ConfigPath").toString()).absoluteFilePath();
m_userpath = QFileInfo(QSettings().value("openzwave/UserPath").toString()).absoluteFilePath();
this->m_openzwave = new QTOpenZwave(this, m_configpath, m_userpath);
this->m_qtozwmanager = this->m_openzwave->GetManager();
qCInfo(ozwadmin) << "OZWCore Initilized" << this->m_openzwave << this->m_qtozwmanager;
Expand All @@ -39,3 +39,83 @@ QTOZWManager *OZWCore::getQTOZWManager() {
qCWarning(ozwadmin) << "QTOZWManager is not created!";
return this->m_qtozwmanager;
}

SettingsManager::SettingsManager(QObject *parent) :
QObject(parent)
{
bool ok;
int size = qEnvironmentVariableIntValue("QTRO_NODES_CACHE_SIZE", &ok);
if (!ok) {
qCDebug(ozwadmin) << "Using Saved Network Cache Size:" << networkCache();
setNetworkCache(networkCache());
} else {
qCDebug(ozwadmin) << "Using Enviroment Network Cache:" << size;
setNetworkCache(size);
}
setLogBufferSize(logBufferSize());
setRetriveLogBuffer(retriveLogBuffer());

}
SettingsManager::~SettingsManager()
{

}

quint32 SettingsManager::networkCache()
{
return m_settings.value("network/cachesize", 1000).toInt();
}

void SettingsManager::setNetworkCache(QVariant size)
{
qCInfo(ozwadmin) << "setNetworkCache Variant Called";
setNetworkCache(size.toInt());
}

void SettingsManager::setNetworkCache(quint32 size)
{
if (size != networkCache()) {
m_settings.setValue("network/cachesize", size);
emit networkCacheChanged(size);
qputenv("QTRO_NODES_CACHE_SIZE", QString::number(size).toLocal8Bit());
}
}

quint32 SettingsManager::logBufferSize()
{
return m_settings.value("network/logbuffersize", 10000).toInt();
}

void SettingsManager::setLogBufferSize(QVariant size)
{
qCInfo(ozwadmin) << "setLogBufferSize Variant Called";
setLogBufferSize(size.toInt());
}

void SettingsManager::setLogBufferSize(quint32 size)
{
if (size != logBufferSize()) {
m_settings.setValue("network/logbuffersize", size);
emit logBufferSizeChanged(size);
}
}

bool SettingsManager::retriveLogBuffer()
{
return m_settings.value("network/retrivelogbuffer", true).toBool();
}

void SettingsManager::setRetriveLogBuffer(QVariant value)
{
qCInfo(ozwadmin) << "setRetriveLogBuffer Variant Called" << value;
setRetriveLogBuffer(value.toBool());
}

void SettingsManager::setRetriveLogBuffer(bool value)
{
if (value != retriveLogBuffer()) {
m_settings.setValue("network/retrivelogbuffer", value);
emit retriveLogBufferChanged(value);
}
}

34 changes: 32 additions & 2 deletions ozwadmin-main/ozwcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@

class ControllerCommands;

class SettingsManager : public QObject
{
Q_OBJECT
public:
SettingsManager(QObject *parent = nullptr);
~SettingsManager();
Q_PROPERTY(quint32 networkCache READ networkCache WRITE setNetworkCache NOTIFY networkCacheChanged);
Q_PROPERTY(quint32 logBufferSize READ logBufferSize WRITE setLogBufferSize NOTIFY logBufferSizeChanged);
Q_PROPERTY(bool retriveLogBuffer READ retriveLogBuffer WRITE setRetriveLogBuffer NOTIFY retriveLogBufferChanged);
quint32 networkCache();
quint32 logBufferSize();
bool retriveLogBuffer();

public Q_SLOTS:
void setNetworkCache(QVariant size);
void setNetworkCache(quint32 size);
void setLogBufferSize(QVariant size);
void setLogBufferSize(quint32 size);
void setRetriveLogBuffer(QVariant value);
void setRetriveLogBuffer(bool value);

Q_SIGNALS:
void networkCacheChanged(int size);
void logBufferSizeChanged(quint32 size);
void retriveLogBufferChanged(bool value);

private:

QSettings m_settings;
};

class OZWCore : public QObject
{
Q_OBJECT
Expand All @@ -19,8 +50,7 @@ class OZWCore : public QObject
void initilize();
QTOpenZwave *getQTOZW();
QTOZWManager *getQTOZWManager();
QSettings settings;

SettingsManager settings;
signals:
QMessageBox::StandardButton raiseCriticalError(QString title, QString message);
public slots:
Expand Down
12 changes: 6 additions & 6 deletions ozwadmin-main/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ Startup::Startup(QWidget *parent) :
QObject::connect(ui->startlocal, &QPushButton::clicked, this, &Startup::localPressed);
QObject::connect(ui->startremote, &QPushButton::clicked, this, &Startup::remotePressed);
#if defined(Q_OS_MACOS)
ui->serialport->setText(OZWCore::get()->settings.value("connection/serialport", "/dev/cu.SLAB_USBtoUART").toString());
ui->serialport->setText(QSettings().value("connection/serialport", "/dev/cu.SLAB_USBtoUART").toString());
#elif defined(Q_OS_WIN)
ui->serialport->setText(OZWCore::get()->settings.value("connection/serialport", "COM1").toString());
ui->serialport->setText(QSettings().value("connection/serialport", "COM1").toString());
#else
ui->serialport->setText(OZWCore::get()->settings.value("connection/serialport", "/dev/ttyUSB0").toString());
ui->serialport->setText(QSettings().value("connection/serialport", "/dev/ttyUSB0").toString());
#endif
ui->enableserver->setChecked(OZWCore::get()->settings.value("connection/startserver", true).toBool());
QUrl server = QUrl::fromUserInput(OZWCore::get()->settings.value("connection/remotehost", "ws://localhost:1983").toString());
ui->enableserver->setChecked(QSettings().value("connection/startserver", true).toBool());
QUrl server = QUrl::fromUserInput(QSettings().value("connection/remotehost", "ws://localhost:1983").toString());
qDebug() << server;
ui->remotehost->setText(server.host());
ui->remoteport->setText(QString::number(server.port()));
ui->authKey->setText(OZWCore::get()->settings.value("connection/authKey", "").toString());
ui->authKey->setText(QSettings().value("connection/authKey", "").toString());
}

Startup::~Startup()
Expand Down
3 changes: 2 additions & 1 deletion ozwadmin-widgets/propertybrowser/qtpropertybrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ typedef QLineEdit::EchoMode EchoMode;
class QtAbstractPropertyManager;
class QtPropertyPrivate;

class QT_QTPROPERTYBROWSER_EXPORT QtProperty
class QT_QTPROPERTYBROWSER_EXPORT QtProperty : public QObject
{
Q_OBJECT
public:
virtual ~QtProperty();

Expand Down
1 change: 1 addition & 0 deletions ozwadmin-widgets/propertybrowser/qtvariantproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ void QtVariantPropertyManagerPrivate::valueChanged(QtProperty *property, const Q
return;
emit q_ptr->valueChanged(varProp, val);
emit q_ptr->propertyChanged(varProp);
emit varProp->valueChanged(val);
}

void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, int val)
Expand Down
5 changes: 4 additions & 1 deletion ozwadmin-widgets/propertybrowser/qtvariantproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ class QtVariantPropertyPrivate;

class QT_QTPROPERTYBROWSER_EXPORT QtVariantProperty : public QtProperty
{
Q_OBJECT
public:
~QtVariantProperty();
QVariant value() const;
QVariant attributeValue(const QString &attribute) const;
int valueType() const;
int propertyType() const;

Q_SIGNALS:
void valueChanged(const QVariant value);
public Q_SLOTS:
void setValue(const QVariant &value);
void setAttribute(const QString &attribute, const QVariant &value);
protected:
Expand Down

0 comments on commit e06f64e

Please sign in to comment.