Began reworking lc::SessionStarter' on base of prior Labcontrol 3

remotes/origin/HEAD
markuspg 8 years ago
parent e1561ece2c
commit f24532a95a

@ -170,9 +170,9 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
ui->CBClientNames->setEnabled( false );
ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false );
ui->PBStartSession->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false );
ui->PBStartzTree->setEnabled( false );
}
// Disable 'PBOpenTerminal' if 'terminal_emulator_command' was not set
@ -202,9 +202,9 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
ui->CBClientNames->setEnabled( false );
ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false );
ui->PBStartSession->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false );
ui->PBStartzTree->setEnabled( false );
}
// Disable the disable screensaver function if the 'xset_command' was not set
@ -216,9 +216,9 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
ui->CBClientNames->setEnabled( false );
ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false );
ui->PBStartSession->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false );
ui->PBStartzTree->setEnabled( false );
}
}
@ -511,32 +511,12 @@ void lc::MainWindow::on_PBStartLocalzLeaf_clicked() {
localzLeafStarter, SLOT( deleteLater() ) );
}
void lc::MainWindow::on_PBStartzLeaf_clicked() {
// Show an error message, if no z-Leaf version was chosen yet
if ( ui->CBzLeafVersion->currentIndex() == 0 ) {
QMessageBox messageBox{ QMessageBox::Warning, tr( "Unset z-Leaf version" ), tr( "There is no z-Leaf version chosen yet. Please choose one." ), QMessageBox::Ok, this };
messageBox.exec();
return;
}
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
const QString * const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(),
nullptr );
}
}
delete zLeafVersion;
}
void lc::MainWindow::on_PBStartzTree_clicked() {
void lc::MainWindow::on_PBStartSession_clicked() {
SessionStarter *sessionStarter = new SessionStarter{ this };
sessionStarter->setWindowFlags( Qt::Window );
sessionStarter->show();
connect( sessionStarter, &SessionStarter::SessionRequested,
lablib, &Lablib::StartNewZTreeInstance );
// connect( sessionStarter, &SessionStarter::SessionRequested,
// lablib, &Lablib::StartNewZTreeInstance );
connect( sessionStarter, &SessionStarter::destroyed,
sessionStarter, &SessionStarter::deleteLater );
// // Show an error message, if no zTree version was chosen yet
@ -580,6 +560,26 @@ void lc::MainWindow::on_PBStartzTree_clicked() {
// lablib->StartNewZTreeInstance();
}
void lc::MainWindow::on_PBStartzLeaf_clicked() {
// Show an error message, if no z-Leaf version was chosen yet
if ( ui->CBzLeafVersion->currentIndex() == 0 ) {
QMessageBox messageBox{ QMessageBox::Warning, tr( "Unset z-Leaf version" ), tr( "There is no z-Leaf version chosen yet. Please choose one." ), QMessageBox::Ok, this };
messageBox.exec();
return;
}
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
const QString * const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(),
nullptr );
}
}
delete zLeafVersion;
}
void lc::MainWindow::on_PBViewDesktop_clicked() {
QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {

@ -74,8 +74,8 @@ private slots:
void on_PBShowSessions_clicked();
void on_PBShutdown_clicked();
void on_PBStartLocalzLeaf_clicked();
void on_PBStartSession_clicked();
void on_PBStartzLeaf_clicked();
void on_PBStartzTree_clicked();
void on_PBViewDesktop_clicked();
void on_RBUseLocalUser_toggled(bool checked);
void StartLocalzLeaf( QString argzLeafName, QString argzLeafVersion, int argzTreePort );

@ -50,12 +50,12 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="PBStartzTree">
<widget class="QPushButton" name="PBStartSession">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Start zTree with the set parameters.&lt;br/&gt;&lt;br/&gt;Take care, that all options in the 'z-Tree' and the 'Receipts' boxes must be set BEFORE starting the accordant z-Tree, since they cannot be changed anymore after the start.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Start a new session. A new window will be opened to enter all required parameters.</string>
</property>
<property name="text">
<string>Start z-Tree</string>
<string>Start Session</string>
</property>
</widget>
</item>

@ -19,132 +19,23 @@
#include <memory>
#include <QDebug>
#include "sessionstarter.h"
#include "ui_sessionstarter.h"
#include "Lib/settings.h"
extern std::unique_ptr< lc::Settings > settings;
lc::SessionStarter::SessionStarter( QWidget *parent ) :
QWidget{ parent },
lc::SessionStarter::SessionStarter( QWidget *argParent ) :
QWidget{ argParent },
ui{ new Ui::SessionStarter }
{
ui->setupUi( this );
this->SetupWidgets();
}
lc::SessionStarter::~SessionStarter() {
delete ui;
}
void lc::SessionStarter::GetNewDataTargetPath() {
QFileDialog *file_dialog = new QFileDialog{ this };
file_dialog->setFileMode( QFileDialog::Directory );
file_dialog->setDirectory( QDir::homePath() );
file_dialog->setOption( QFileDialog::ShowDirsOnly, true );
file_dialog->setOption( QFileDialog::DontUseNativeDialog, true );
if( file_dialog->exec() ) {
QString file_name = file_dialog->selectedFiles().at( 0 );
ui->CBDataTargetPath->addItem( file_name );
ui->CBDataTargetPath->setCurrentText( file_name );
ui->CBDataTargetPath->activated( file_name );
}
delete file_dialog;
}
void lc::SessionStarter::on_CBDataTargetPath_activated(const QString &arg1) {
Q_UNUSED( arg1 );
if ( ui->CBDataTargetPath->currentIndex() == 0 ) {
emit NewDataTargetPathRequested();
return;
}
ui->CBDataTargetPath->setStyleSheet( "" );
}
void lc::SessionStarter::on_CBReceiptsHeader_activated( const QString &argHeader ) {
Q_UNUSED( argHeader );
ui->CBReceiptsHeader->setStyleSheet( "" );
}
void lc::SessionStarter::on_CBzTreeVersion_activated( const QString &argVersion ) {
Q_UNUSED( argVersion );
ui->CBzTreeVersion->setStyleSheet( "" );
}
void lc::SessionStarter::on_ChBPrintanonymousreceipts_clicked( bool checked ) {
// Enable or disable the corresponding widgets
if ( checked ) {
ui->LReplaceParticipantName->setEnabled( true );
ui->CBReplaceParticipantName->setEnabled( true );
ui->CBReplaceParticipantName->setStyleSheet( "background: cyan" );
} else {
ui->LReplaceParticipantName->setEnabled( false );
ui->CBReplaceParticipantName->setEnabled( false );
ui->CBReplaceParticipantName->setStyleSheet( "" );
}
ui->ChBPrintanonymousreceipts->setStyleSheet( "" );
}
void lc::SessionStarter::on_ChBReceiptsforLocalClients_clicked( bool argChecked ) {
Q_UNUSED( argChecked );
ui->ChBReceiptsforLocalClients->setStyleSheet( "" );
}
void lc::SessionStarter::on_PBStartzTree_clicked() {
emit SessionRequested( ui->CBDataTargetPath->currentText(), ui->SBPort->value(),
ui->CBzTreeVersion->currentText(),
ui->ChBReceiptsforLocalClients->isChecked(),
ui->CBReplaceParticipantName->currentText(),
ui->CBReceiptsHeader->currentText() );
close();
}
void lc::SessionStarter::on_SBPort_editingFinished() {
ui->SBPort->setStyleSheet( "" );
settings->SetChosenZTreePort( ui->SBPort->value() );
}
void lc::SessionStarter::SetupWidgets() {
if ( settings->GetChosenZTreePort() ) {
ui->SBPort->setValue( settings->GetChosenZTreePort() );
// Fill the 'CBzTreeVersion' combobox with known entries from the lablib class
ui->CBzTreeVersion->addItem( "NONE" );
const QStringList &zTreeEntries = settings->installedZTreeVersions;
if ( !zTreeEntries.isEmpty() ) {
for ( const auto &zTreeVersionString : zTreeEntries ) {
ui->CBzTreeVersion->addItem( zTreeVersionString );
}
ui->CBzTreeVersion->setCurrentIndex( 0 );
} else {
throw lcForbiddenCall{};
}
// Fill the 'CBReceipts' combobox with successfully detected LaTeX receipt headers
if ( !settings->installedLaTeXHeaders.isEmpty() ) {
if ( ( settings->installedLaTeXHeaders.count() == 1 )
&& ( settings->installedLaTeXHeaders.at(0) == "None found" ) ) {
ui->GBReceipts->setEnabled( false );
}
ui->CBReceiptsHeader->addItems( settings->installedLaTeXHeaders );
if ( settings->installedLaTeXHeaders.length() - 1 < settings->defaultReceiptIndex ) {
QMessageBox::information( this, tr( "'default_receipt_index' to high" ),
tr( "'default_receipt_index' was set to big. The combo box containing the receipt templates will default to the first entry." ) );
qDebug() << "'default_receipt_index' was set to big."
" The combo box containing the receipt templates will default to the first entry.";
ui->CBReceiptsHeader->setCurrentIndex( 0 );
} else {
ui->CBReceiptsHeader->setCurrentIndex( settings->defaultReceiptIndex );
}
}
}
// Fill the 'CBDataTargetPath' combobox with some data target path examples
ui->CBDataTargetPath->addItem( tr( "Set new path" ) );
ui->CBDataTargetPath->addItem( QDir::homePath() );
ui->CBDataTargetPath->addItem( QString{ QDir::homePath() + "/zTreeData" } );
ui->CBDataTargetPath->setCurrentIndex( 2 );
connect( this, &SessionStarter::NewDataTargetPathRequested,
this, &SessionStarter::GetNewDataTargetPath );
lc::SessionStarter::~SessionStarter() {
delete ui;
}

@ -20,9 +20,6 @@
#ifndef SESSIONSTARTER_H
#define SESSIONSTARTER_H
#include "src/Lib/lablib.h"
#include <QFileDialog>
#include <QWidget>
namespace lc {
@ -35,37 +32,11 @@ class SessionStarter : public QWidget {
Q_OBJECT
public:
explicit SessionStarter( QWidget *parent = nullptr );
explicit SessionStarter( QWidget *argParent = nullptr );
~SessionStarter();
//! This gets thrown as an exception if this class is created even if it shouldn't
//! (because no installed z-Tree instances could be detected).
class lcForbiddenCall {};
signals:
void SessionRequested( QString argDataTargetPath, int argPort, QString argzTreeVersion,
bool argReceiptsForLocalClients, QString argAnonReceiptPlaceholder,
QString argChosenLatexHeader );
private:
Ui::SessionStarter *ui = nullptr;
void SetupWidgets();
private slots:
//! Opens a 'QFileDialog' and tries to choose a new zTree data target path
void GetNewDataTargetPath();
void on_CBDataTargetPath_activated(const QString &arg1);
void on_CBReceiptsHeader_activated( const QString &argHeader );
void on_CBzTreeVersion_activated( const QString &argVersion );
void on_ChBPrintanonymousreceipts_clicked( bool checked );
void on_ChBReceiptsforLocalClients_clicked( bool argChecked );
void on_PBStartzTree_clicked();
void on_SBPort_editingFinished();
signals:
//! This signal becomes emitted if "Set new path" was chosen in the 'CBDataTargetPath'
void NewDataTargetPathRequested();
};
}

@ -6,32 +6,26 @@
<rect>
<x>0</x>
<y>0</y>
<width>512</width>
<height>256</height>
<width>640</width>
<height>576</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>512</width>
<height>256</height>
</size>
</property>
<property name="windowTitle">
<string>Session Starter</string>
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="VLSessionStarter">
<item>
<layout class="QHBoxLayout" name="HLForBothGroupBoxes">
<layout class="QHBoxLayout" name="HLGroupBoxes">
<item>
<widget class="QGroupBox" name="GBzTree">
<property name="title">
<string>z-Tree</string>
</property>
<layout class="QVBoxLayout" name="VLzTreeGroupBox">
<layout class="QVBoxLayout" name="VLzTree">
<item>
<widget class="QLabel" name="LzTreeVersion">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>The zTree version which shall be used for the experiment.</string>
<string>The z-Tree version which shall be used for the experiment.</string>
</property>
<property name="text">
<string>z-Tree version:</string>
@ -41,17 +35,20 @@
<item>
<widget class="QComboBox" name="CBzTreeVersion">
<property name="toolTip">
<string>The zTree version which shall be used for the experiment.</string>
<string>The z-Tree version which shall be used for the experiment.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan</string>
<string notr="true">background: cyan;</string>
</property>
<property name="maxVisibleItems">
<number>32</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="LDataTargetPath">
<property name="toolTip">
<string>The path where zTree shall store its data.
<string>The path where z-Tree shall store its data.
Please take care that it does not contain any spaces or other special characters.</string>
</property>
@ -63,25 +60,12 @@ Please take care that it does not contain any spaces or other special characters
<item>
<widget class="QComboBox" name="CBDataTargetPath">
<property name="toolTip">
<string>The path where zTree shall store its data.
<string>The path where z-Tree shall store its data.
Please take care that it does not contain any spaces or other special characters.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ChBRamdiskForGamesafeFile">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>This function is not implemented yet.</string>
</property>
<property name="text">
<string>Use ramdisk for gamesafe file</string>
<string notr="true">background: cyan;</string>
</property>
</widget>
</item>
@ -90,7 +74,7 @@ Please take care that it does not contain any spaces or other special characters
<item>
<widget class="QLabel" name="LPort">
<property name="toolTip">
<string>The port which will be used by started zTree and zLeaf instances. Only matters if multiple experiments shall be run in parallel.</string>
<string>The port which will be used by started z-Tree and z-Leaf instances. This only matters if multiple experiments shall be run in parallel.</string>
</property>
<property name="text">
<string>Port:</string>
@ -99,11 +83,14 @@ Please take care that it does not contain any spaces or other special characters
</item>
<item>
<widget class="QSpinBox" name="SBPort">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>The port which will be used by started zTree and zLeaf instances. Only matters if multiple experiments shall be run in parallel.</string>
<string>The port which will be used by started z-Tree and z-Leaf instances. This only matters if multiple experiments shall be run in parallel.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan</string>
<string notr="true">background: cyan;</string>
</property>
<property name="minimum">
<number>7000</number>
@ -115,6 +102,19 @@ Please take care that it does not contain any spaces or other special characters
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="ChBRamdiskForGamesafeFile">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>This function is not implemented, yet.</string>
</property>
<property name="text">
<string>Use ramdisk for gamesafe file</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -123,9 +123,12 @@ Please take care that it does not contain any spaces or other special characters
<property name="title">
<string>Receipts</string>
</property>
<layout class="QVBoxLayout" name="VLReceiptsGroupBox">
<layout class="QVBoxLayout" name="VLReceipts">
<item>
<widget class="QLabel" name="LReceiptsLabel">
<widget class="QLabel" name="LReceiptsHeader">
<property name="toolTip">
<string>Choose the LaTeX template which shall be used for receipts creation.</string>
</property>
<property name="text">
<string>Template for receipts:</string>
</property>
@ -133,15 +136,21 @@ Please take care that it does not contain any spaces or other special characters
</item>
<item>
<widget class="QComboBox" name="CBReceiptsHeader">
<property name="toolTip">
<string>Choose the LaTeX template which shall be used for receipts creation.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan</string>
<string notr="true">background: cyan;</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ChBPrintanonymousreceipts">
<widget class="QCheckBox" name="ChBPrintAnonymousReceipts">
<property name="toolTip">
<string>Check this if you want the created receipts to be anonymous.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan</string>
<string notr="true">background: cyan;</string>
</property>
<property name="text">
<string>Print anonymous receipts</string>
@ -149,23 +158,32 @@ Please take care that it does not contain any spaces or other special characters
</widget>
</item>
<item>
<widget class="QLabel" name="LReplaceParticipantName">
<widget class="QLabel" name="LReplaceParticipantNames">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Choose a string which shall replace the participant name on the anonymous receipts.</string>
</property>
<property name="text">
<string>Substitute participant names with:</string>
<string>Substitute participants' names with:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="CBReplaceParticipantName">
<widget class="QComboBox" name="CBReplaceParticipantNames">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Choose a string which shall replace the participant name on the anonymous receipts.</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="currentText">
<string>\hspace{5cm}</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
@ -191,30 +209,61 @@ Please take care that it does not contain any spaces or other special characters
</item>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="ChBReceiptsforLocalClients">
<widget class="QLabel" name="LClientSelection">
<property name="toolTip">
<string>Select the clients which shall be attached to this session:</string>
</property>
<property name="text">
<string>Print receipts for local clients</string>
<string>Select the clients which shall be attached to this session:</string>
</property>
<property name="checked">
<bool>true</bool>
</widget>
</item>
<item>
<widget class="QTableView" name="TVClients">
<property name="toolTip">
<string>Select the clients which shall be attached to this session.</string>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
<item>
<widget class="QCheckBox" name="ChBSessionWithoutClients">
<property name="toolTip">
<string>This allows an experimenter to override the normally hard requirement of choosing clients to be attached to the started session and start a session without attached clients.</string>
</property>
<property name="text">
<string>Allow session without attached clients</string>
</property>
</widget>
</item>
</layout>
<item>
<widget class="QPushButton" name="PBStartSession">
<property name="toolTip">
<string>Start a new session according to the above made settings.</string>
</property>
<property name="text">
<string>Start session</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="PBStartzTree">
<widget class="QPushButton" name="PBCancel">
<property name="toolTip">
<string>Start zTree with the set parameters.
Take care, that all options in the 'z-Tree' and the 'Receipts' boxes must be set BEFORE starting the accordant z-Tree, since they cannot be changed anymore after the start.</string>
<string>Cancel the creation of a new session.</string>
</property>
<property name="text">
<string>Start z-Tree</string>
<string>Cancel</string>
</property>
</widget>
</item>

Loading…
Cancel
Save