Opensim Control Panel BRIGADOON-0013
This program provides a control panel for an Open Simulator Instance
Loading...
Searching...
No Matches
mainwindow.cpp
Go to the documentation of this file.
1#include "mainwindow.h"
2#include "logger.h"
3#include "dirclass.h"
4
5MainWindow::MainWindow(QWidget *parent)
6 : QMainWindow(parent)
7 , ui(new Ui::MainWindow)
8{
9 ui->setupUi(this);
10
11 // Setup the Setting Parameters for the Program
12 QCoreApplication::setOrganizationName("Brigadoon");
13 QCoreApplication::setOrganizationDomain("little-sense.au");
14 QCoreApplication::setApplicationName("Terrain Editor");
15
16
17 // Load the Log
18 qRegisterMetaType<REMOTE_LOG_ENTRY>("REMOTE_LOG_ENTRY"); // Register Custom Meta Types for the "QObject::connect" Definitions
19 log = new Logger(ui);
20 log->Add(LOG_DEBUG, MODE_CONFIG, "Logger \"log\" has been opened.");
21
22 // Load the Default Directories from Setup
23 QSettings settings;
24 ui->SourceDirectory->setText( settings.value( "Directories/InputDir").toString());
25 ui->DestinationDirectory->setText(settings.value( "Directories/OutputDir").toString());
26
27 // Create the Database Control Class
29 QObject::connect(db_manager, SIGNAL(SendLogEntry(REMOTE_LOG_ENTRY)), log, SLOT(RemoteLog(REMOTE_LOG_ENTRY)));
30 db_manager->ReconnectDatabase();
31
32 // Create the Directory Class
33 dir_manager = new DirClass();
34 QObject::connect(dir_manager, SIGNAL(SendLogEntry(REMOTE_LOG_ENTRY)), log, SLOT(RemoteLog(REMOTE_LOG_ENTRY)));
35 dir_manager->SetInputDirectory(ui->SourceDirectory->text());
36 dir_manager->SetInputTable(ui->InputRegionTable);
37 dir_manager->SetOutputTable(ui->OutputRegionTable);
38 log->Add(LOG_DEBUG, MODE_CONFIG, "Directory Class has been opened.");
39
40 // Load the Area Calculator
42 QObject::connect(area_calc, SIGNAL(SendLogEntry(REMOTE_LOG_ENTRY)), log, SLOT(RemoteLog(REMOTE_LOG_ENTRY)));
43 log->Add(LOG_DEBUG, MODE_CONFIG, "AreaCalculator Class has been opened.");
44
45 // Load up the Connection Links
46 QObject::connect(ui->SourceSelect, SIGNAL(released()), this, SLOT(GetInputDir()));
47 QObject::connect(ui->DestinationSelect, SIGNAL(released()), this, SLOT(GetOutputDir()));
48
49 QObject::connect(ui->DestinationSelect, SIGNAL(released()), this, SLOT(GetOutputDir()));
50
51 qRegisterMetaType<REMOTE_WORLD_SIZE>("REMOTE_WORLD_SIZE"); // Register Custom Meta Types for the "QObject::connect" Definitions
52 qRegisterMetaType<REMOTE_WORLD_SIDES>("REMOTE_WORLD_SIDES");
53 qRegisterMetaType<REMOTE_REGION_ADDRESS>("REMOTE_REGION_ADDRESS");
54 QObject::connect(ui->WorldXSize, SIGNAL(valueChanged(int)), area_calc, SLOT(WorldXChanged(int)));
55 QObject::connect(ui->WorldYSize, SIGNAL(valueChanged(int)), area_calc, SLOT(WorldYChanged(int)));
56 QObject::connect(dir_manager, SIGNAL(SendRegionLocation(REMOTE_REGION_ADDRESS)),this, SLOT(UpdateLocation(REMOTE_REGION_ADDRESS)));
57 QObject::connect(area_calc, SIGNAL(SendWorldArea(REMOTE_WORLD_SIZE)), this, SLOT(WorldAreaChanged(REMOTE_WORLD_SIZE)));
58 QObject::connect(area_calc, SIGNAL(SendWorldSides(REMOTE_WORLD_SIDES)), this, SLOT(WorldSidesChanged(REMOTE_WORLD_SIDES)));
59
60 QObject::connect(area_calc, SIGNAL(IncludeNewRegion(REMOTE_REGION_ADDRESS)), this, SLOT(UpdateLocation(REMOTE_REGION_ADDRESS)));
61
62 QObject::connect(ui->LowerXLocation, SIGNAL(valueChanged(int)), area_calc, SLOT(LowerXChanged(int)));
63 QObject::connect(ui->UpperXLocation, SIGNAL(valueChanged(int)), area_calc, SLOT(UpperXChanged(int)));
64 QObject::connect(ui->LowerYLocation, SIGNAL(valueChanged(int)), area_calc, SLOT(LowerYChanged(int)));
65 QObject::connect(ui->UpperYLocation, SIGNAL(valueChanged(int)), area_calc, SLOT(UpperYChanged(int)));
66
67 QObject::connect(ui->Region_x1, SIGNAL(pressed()), area_calc, SLOT(Regionx1Pressed()));
68 QObject::connect(ui->Region_x4, SIGNAL(pressed()), area_calc, SLOT(Regionx4Pressed()));
69 QObject::connect(ui->Region_x16, SIGNAL(pressed()), area_calc, SLOT(Regionx16Pressed()));
70
71 QObject::connect(ui->AutoCalcSize, SIGNAL(checkStateChanged(Qt::CheckState) ), area_calc, SLOT(AutoCalcChanged(Qt::CheckState)));
72 QObject::connect(ui->AutoCalcSize, SIGNAL(checkStateChanged(Qt::CheckState) ), area_calc, SLOT(AutoCalcChanged(Qt::CheckState)));
73 QObject::connect(ui->AutoCalcSize, SIGNAL(checkStateChanged(Qt::CheckState) ), this, SLOT(DisableXYSize(Qt::CheckState)));
74
75 qRegisterMetaType<QList<DIR_INFO>>("REMOTE_DIR_INFO");
76 QObject::connect(ui->ProcessInputDirectory, SIGNAL(pressed()), dir_manager, SLOT(ListInputDirectory(void)));
77 QObject::connect(ui->ProcessInputDirectory, SIGNAL(pressed()), this, SLOT(EnableAutoCalc(void)));
78}
79
81{
82 // Save the Data Directories if required
83 if (ui->SaveDirectoriesOnExit->isChecked())
84 {
85 QSettings settings;
86 settings.setValue( "Directories/InputDir", ui->SourceDirectory->text());
87 settings.setValue( "Directories/OutputDir", ui->DestinationDirectory->text());
88 }
89
90 // Close Down the Classes, as required
91 delete db_manager; // Save Database Parameters, If Required
92 delete log; // Save Log Parameters, If Required
93
94 delete ui;
95}
96
98{
99 ui->WorldXSize->setValue(WorldSides.WorldXSize);
100 ui->WorldYSize->setValue(WorldSides.WorldYSize);
101}
102
104{
105 float world_area_formatted;
106 QString world_area_string;
107
108 // Show the World's Land Area
109 if (WorldSize.WorldArea >= 1E06)
110 {
111 world_area_formatted = WorldSize.WorldArea / 1E06;
112 ui->WorldSize->setText( QString::number(world_area_formatted));
113 ui->WorldAreaLabel->setText("sq. km");
114 }
115 else
116 {
117 ui->WorldSize->setText( QString::number(WorldSize.WorldArea));
118 ui->WorldAreaLabel->setText("sq. m");
119 }
120
121 ui->MaxRegions->setText( QString::number(WorldSize.WorldRegionCount));
122}
123
125{
126 QString selected_directory = GetDirectoryName(ui->SourceDirectory->text());
127 if (selected_directory != "") ui->SourceDirectory->setText(selected_directory);
128}
129
131{
132 QString selected_directory = GetDirectoryName(ui->DestinationDirectory->text());
133 if (selected_directory != "") ui->DestinationDirectory->setText(selected_directory);
134}
135
136void MainWindow::DisableXYSize(Qt::CheckState State)
137{
138 bool enable_state = (bool)State;
139
140 ui->WorldXSize->setReadOnly(enable_state);
141 ui->WorldYSize->setReadOnly(enable_state);
142 if (!enable_state)
143 {
144 ui->WorldXSize->setValue(0);
145 ui->WorldYSize->setValue(0);
146 ui->LowerXLocation->setValue(0);
147 ui->LowerYLocation->setValue(0);
148 ui->UpperXLocation->setValue(0);
149 ui->UpperYLocation->setValue(0);
150 }
151}
152
153QString MainWindow::GetDirectoryName(QString DefaultDirectory)
154{
155 return(QFileDialog::getExistingDirectory(this, "Select Directory", DefaultDirectory, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
156}
157
159{
160 ui->AutoCalcSize->setCheckState(Qt::Checked);
161}
162
164{
165 if ((ui->LowerXLocation->value() == 0) || ( ui->LowerXLocation->value() > RegionAddress.RegionXLocation)) ui->LowerXLocation->setValue(RegionAddress.RegionXLocation);
166 if (ui->UpperXLocation->value() < RegionAddress.RegionXLocation) ui->UpperXLocation->setValue(RegionAddress.RegionXLocation);
167
168 if ((ui->LowerYLocation->value() == 0) || ( ui->LowerYLocation->value() > RegionAddress.RegionYLocation)) ui->LowerYLocation->setValue(RegionAddress.RegionYLocation);
169 if (ui->UpperYLocation->value() < RegionAddress.RegionYLocation) ui->UpperYLocation->setValue(RegionAddress.RegionYLocation);
170}
Class to control the opening of the Database.
AreaCalculator * area_calc
Definition mainwindow.h:47
void GetInputDir(void)
void EnableAutoCalc(void)
Ui::MainWindow * ui
Definition mainwindow.h:37
void WorldAreaChanged(REMOTE_WORLD_SIZE WorldSize)
void ListInputDirectory(void)
void WorldSidesChanged(REMOTE_WORLD_SIDES WorldSides)
Logger * log
Pointer to the Log Class.
Definition mainwindow.h:30
QString GetDirectoryName(QString DefaultDirectory)
MainWindow(QWidget *parent=nullptr)
Definition mainwindow.cpp:5
void DisableXYSize(Qt::CheckState)
void UpdateLocation(REMOTE_REGION_ADDRESS RegionAddress)
void GetOutputDir(void)
DatabaseManager * db_manager
Pointer to the Database Class.
Definition mainwindow.h:43
DirClass * dir_manager
Definition mainwindow.h:45
@ LOG_DEBUG
Definition logger.h:56
@ MODE_CONFIG
Definition logger.h:26
Definition logger.h:60