Added possibility to save and load initial values.

This commit is contained in:
2011-04-08 13:46:38 +00:00
parent d86fdde7b1
commit d14a857d9d
4 changed files with 223 additions and 137 deletions

View File

@ -19,19 +19,69 @@ void QmuSRSim::fileNew()
void QmuSRSim::fileOpen()
{
my $file=Qt::FileDialog::getOpenFileName(
".",
"Initialization file (.* *.*)",
this,
"open file dialog",
"Choose an initialization file");
# If the user gave a valid filename try to read it
if ($file ne "") {
open (INF,q{<},"$file" );
my @lines = <INF>;
close(INF);
my $Attrib="";
foreach my $line (@lines) {
# Remove white spaces
$line =~ s/\s+//g;
my @InitPar = split (/=/,$line);
# Check it is not empty or title line
if ($InitPar[0] ne "" && $InitPar[1] ne "") {
$Attrib = child($InitPar[0]);
$Attrib->setText($InitPar[1]);
}
}
}
}
void QmuSRSim::fileSave()
{
my %All=CreateAllInput();
my $InitFile="";
for my $key (keys %All) {
$InitFile=$InitFile.$key."=".$All{$key}."\n";
}
# Save to default file name "TriumSP.cfg"
my $file = "musrSim.cfg";
open (OUTF,q{>},"$file" );
print OUTF (" $InitFile");
close(OUTF);
}
void QmuSRSim::fileSaveAs()
{
my %All=CreateAllInput();
my $InitFile="";
for my $key (keys %All) {
$InitFile=$InitFile.$key."=".$All{$key}."\n";
}
my $file=Qt::FileDialog::getSaveFileName(
"musrSim cfg",
"musrSim GUI Initialization file (*.cfg)",
this,
"save file dialog",
"Choose a filename to save under");
# if the user gave a filename then sanesave copy to it
if ($file ne "") {
open (OUTF,q{>},"$file" );
print OUTF (" $InitFile");
close(OUTF);
}
}
@ -43,7 +93,12 @@ void QmuSRSim::filePrint()
void QmuSRSim::fileExit()
{
my $Ans = Qt::MessageBox::question( this, "Quit?","Are you sure you want to quit?","&Yes","&No","",0,1);
if ($Ans==0) {
# Then quit
Qt::Application::exit( 0 );
}
# Otherwize go back
}
@ -189,7 +244,7 @@ void QmuSRSim::StartCalc()
}
open(NEWMACF,">1000.mac");
print (NEWMACF "@lines");
print NEWMACF @lines;
close(NEWMACF);
}