It probably is not appropriate to do the configuration in the Airspace constructor, but in an Airspace::onConfigureAirspace( const AirspaceConfiguration & ) slot. In the MainWindow, in the slot that handles the triggered() signal from the QAction attached to the "Load Configuration" menu item, you retrieve the name of the configuration file, pass it to the bool AirspaceConfiguration::load( const QString & fileName ) method, and then emit an airspaceConfigurationChanged( const AirspaceConfiguration & ) signal:
// MainWindow.h:
{
O_OBJECT;
// usual constructor stuff, etc.
signals:
void airspaceConfigurationChanged( const AirspaceConfiguration & config );
protected slots:
void onLoadConfigurationTriggered();
protected:
Airspace airspace;
AirspaceConfiguration currentConfig;
};
// MainWindow.cpp:
MainWindow
::MainWindow( QWidget * parent
){
// set up menus, actions, etc
// ...
connect( this, SIGNAL( airspaceConfigurationChanged( const AirspaceConfiguration & ) ), &airspace, SLOT( onConfigureAirspace( const AirspaceConfiguration & ) ) );
// more setup if needed
}
void MainWindow::onLoadConfigurationTriggered()
{
if ( !fileName.isEmpty() )
{
if ( currentConfig.load( fileName ) )
emit airspaceConfigurationChanged( currentConfig );
}
}
// MainWindow.h:
class MainWindow :: public QMainWindow
{
O_OBJECT;
// usual constructor stuff, etc.
signals:
void airspaceConfigurationChanged( const AirspaceConfiguration & config );
protected slots:
void onLoadConfigurationTriggered();
protected:
Airspace airspace;
AirspaceConfiguration currentConfig;
};
// MainWindow.cpp:
MainWindow::MainWindow( QWidget * parent )
: QMainWindow( parent )
{
// set up menus, actions, etc
// ...
connect( this, SIGNAL( airspaceConfigurationChanged( const AirspaceConfiguration & ) ), &airspace, SLOT( onConfigureAirspace( const AirspaceConfiguration & ) ) );
// more setup if needed
}
void MainWindow::onLoadConfigurationTriggered()
{
QString fileName = QFileDialog::getOpenFileName();
if ( !fileName.isEmpty() )
{
if ( currentConfig.load( fileName ) )
emit airspaceConfigurationChanged( currentConfig );
}
}
To copy to clipboard, switch view to plain text mode
This way, all of the different parts of the program are separated, each with a well-defined function, and with minimal inter-dependence on other parts of the program. Communicating by signals and slots (in the Qt way) means that the two partners on each end don't need to know anything about each other, only that they share the connection with its well-defined protocol.
By making an AirspaceConfiguration class, you now have a way to change the configuration independently of other parts of the game. Presumably, the Airspace class itself is responsible for implementing all the rules (like, two planes can't be at the same place at the same time, on the same runway headed towards each other, etc.). You could then create a GUI for designing a new AirspaceConfiguration independently of the rest of the program, so instead of only being able to load a configuration from a file, you could change it interactively and emit the same signal.
Likewise, I presume you would implement a series of other classes to represent Aircraft, Gate, Runway, Taxiway, Terminal, or whatever else makes sense in the context of the game.
Bookmarks