Revise ZTree class

* improve documentation
* move QProcess to heap (for better clean-up through deleteLater)
* reduce and reorder includes
* utilize initializer list and new signal-slot syntax
remotes/origin/HEAD
markuspg 4 years ago
parent 32e6b89679
commit f0019b00ce

@ -22,6 +22,8 @@
#include "session.h"
#include "settings.h"
#include <QDir>
extern std::unique_ptr<lc::Settings> settings;
lc::Session::Session(QVector<Client *> &&argAssocClients,

@ -17,36 +17,59 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "ztree.h"
#include "settings.h"
#include <QDebug>
#include <QDir>
#include "settings.h"
#include "ztree.h"
#include <memory>
extern std::unique_ptr<lc::Settings> settings;
/*!
* Setup and start a new z-Tree instance with the given parameters
*
* \param[in] argZTreeDataTargetPath The path where the new z-Tree instance
* shall write its output to
* \param[in] argZTreePort The port on which the new z-Tree instance shall
* listen
* \param[in] argZTreeVersion The version of z-Tree which shall be
* started
* \param[in] argParent The instance's parent QObject
*/
lc::ZTree::ZTree(const QString &argZTreeDataTargetPath, const int &argZTreePort,
const QString &argZTreeVersionPath, QObject *argParent)
: QObject{argParent} {
QStringList arguments{QStringList{}
<< "-c"
<< "0" << settings->wineCmd
<< QString{settings->zTreeInstDir + "/zTree_" +
argZTreeVersionPath + "/ztree.exe"}
<< "/datadir" << QString{"Z:/" + argZTreeDataTargetPath}
<< "/privdir" << QString{"Z:/" + argZTreeDataTargetPath}
<< "/gsfdir" << QString{"Z:/" + argZTreeDataTargetPath}
<< "/tempdir" << QString{"Z:/" + argZTreeDataTargetPath}
<< "/leafdir" << QString{"Z:/" + argZTreeDataTargetPath}
<< "/channel" << QString::number(argZTreePort - 7000)};
const QString &argZTreeVersion, QObject *const argParent)
: QObject{argParent}, zTreeInstance{new QProcess{this}} {
const QStringList arguments{"-c",
"0",
settings->wineCmd,
QString{settings->zTreeInstDir + "/zTree_" +
argZTreeVersion + "/ztree.exe"},
"/datadir",
QString{"Z:/" + argZTreeDataTargetPath},
"/privdir",
QString{"Z:/" + argZTreeDataTargetPath},
"/gsfdir",
QString{"Z:/" + argZTreeDataTargetPath},
"/tempdir",
QString{"Z:/" + argZTreeDataTargetPath},
"/leafdir",
QString{"Z:/" + argZTreeDataTargetPath},
"/channel",
QString::number(argZTreePort - 7000)};
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
zTreeInstance.setProcessEnvironment(env);
zTreeInstance.setWorkingDirectory(QDir::homePath());
zTreeInstance.start(settings->tasksetCmd, arguments, QIODevice::NotOpen);
connect(&zTreeInstance, SIGNAL(finished(int)), this,
SIGNAL(ZTreeClosed(int)));
zTreeInstance->setProcessEnvironment(env);
zTreeInstance->setWorkingDirectory(QDir::homePath());
zTreeInstance->start(settings->tasksetCmd, arguments, QIODevice::NotOpen);
connect(zTreeInstance,
static_cast<void (QProcess::*)(int)>(&QProcess::finished), this,
&ZTree::ZTreeClosed);
qDebug() << settings->tasksetCmd << arguments.join(" ");
}
/*!
* \brief Destroy the z-Tree instance (closes the running z-Tree instance)
*/
lc::ZTree::~ZTree() { zTreeInstance->deleteLater(); }

@ -20,29 +20,31 @@
#ifndef ZTREE_H
#define ZTREE_H
#include <QDir>
#include <QPlainTextEdit>
#include <QProcess>
#include <QObject>
class QProcess;
namespace lc {
//! A class to contain running zTree instances.
/*!
This class is element of every session and is used to handle all zTree related
data.
*/
* A class to contain running z-Tree instances.
*
* This class is element of every Session instance and is used to handle all
* z-Tree related data as well as the execution of z-Tree itself.
*/
class ZTree : public QObject {
Q_OBJECT
public:
ZTree(const QString &argZTreeDataTargetPath, const int &argZTreePort,
const QString &argZTreeVersionPath, QObject *argParent = nullptr);
const QString &argZTreeVersion, QObject *argParent = nullptr);
~ZTree() override;
signals:
void ZTreeClosed(int argExitCode);
private:
QProcess zTreeInstance;
QProcess *const zTreeInstance = nullptr;
};
} // namespace lc

Loading…
Cancel
Save