@@ -793,51 +793,61 @@ void PMbrowserWindow::on_actionExport_All_as_IBW_triggered()
793
793
}
794
794
}
795
795
796
+ class locale_manager {
797
+ std::locale old_locale{};
798
+ public:
799
+ void setLocale (const char * name){
800
+ old_locale = std::locale::global (std::locale (name));
801
+ }
802
+ ~locale_manager () {
803
+ std::locale::global (old_locale);
804
+ }
805
+ };
806
+
796
807
void PMbrowserWindow::on_actionExport_Metadata_as_Table_triggered ()
797
808
{
798
809
if (!assertDatFileOpen ()) {
799
810
return ;
800
811
}
801
812
DlgExportMetadata dlg (this );
802
813
if (dlg.exec ()) {
803
- std::locale old_locale;
804
- if (dlg.useSystemLocale ()) {
805
- std::locale new_locale (" " ); // system default locale
806
- old_locale = std::locale::global (new_locale);
807
- }
808
- auto selected = dlg.getSelection ();
809
- if (selected < 0 )
810
- {
811
- selected = hkTreeNode::LevelTrace;
812
- }
813
- else {
814
- ++selected; // first item in box is level 1
815
- }
816
- if (dlg.doCopy ()) {
817
- std::ostringstream s;
818
- this ->formatStimMetadataAsTableExport (s, selected);
819
- QGuiApplication::clipboard ()->setText (s.str ().c_str ());
820
- }
821
- else {
822
- auto export_file_name = QFileDialog::getSaveFileName (this , " Export Metadata as TXT" ,
823
- lastexportpath, " tab separated file (*.txt *.csv)" );
824
- if (export_file_name.length () > 0 ) {
825
- std::ofstream export_file (export_file_name.toStdString ());
826
- if (!export_file) {
827
- QMessageBox::warning (this , " Error" ,
828
- QString (" Cannot open file '%1'\n for saving" ).arg (export_file_name));
829
- return ;
830
- }
831
- try {
814
+ try {
815
+ locale_manager lm;
816
+ if (dlg.useSystemLocale ()) {
817
+ lm.setLocale (" " ); // set default locale
818
+ }
819
+ else {
820
+ lm.setLocale (" C" );
821
+ }
822
+ auto selected = dlg.getSelection ();
823
+ if (selected < 0 )
824
+ {
825
+ selected = hkTreeNode::LevelTrace;
826
+ }
827
+ else {
828
+ ++selected; // first item in box is level 1
829
+ }
830
+ if (dlg.doCopy ()) {
831
+ std::ostringstream s;
832
+ this ->formatStimMetadataAsTableExport (s, selected);
833
+ QGuiApplication::clipboard ()->setText (s.str ().c_str ());
834
+ }
835
+ else {
836
+ auto export_file_name = QFileDialog::getSaveFileName (this , " Export Metadata as TXT" ,
837
+ lastexportpath, " tab separated file (*.txt *.csv)" );
838
+ if (export_file_name.length () > 0 ) {
839
+ std::ofstream export_file (export_file_name.toStdString ());
840
+ if (!export_file) {
841
+ QMessageBox::warning (this , " Error" ,
842
+ QString (" Cannot open file '%1'\n for saving" ).arg (export_file_name));
843
+ return ;
844
+ }
832
845
this ->formatStimMetadataAsTableExport (export_file, selected);
833
846
}
834
- catch (const std::exception & e) {
835
- QMessageBox::warning (this , " Error while exporting" , e.what ());
836
- }
837
847
}
838
848
}
839
- if (dlg. useSystemLocale () ) {
840
- std::locale::global (old_locale );
849
+ catch ( const std:: exception & e ) {
850
+ QMessageBox::warning ( this , " Error while exporting " , e. what () );
841
851
}
842
852
}
843
853
}
0 commit comments