Respect build options in export dialogs (#3714)

* Respect build options in ExportProjectDialog

* Use QItem user data instead of hard ordering to identify export format in ExportProjectDialog

* For compatibility with QVariant, ExportFileFormats is now explicitly an int.

* Don't break out of format identifier loop prematurely in Song export.
This commit is contained in:
irrenhaus3
2017-07-26 12:48:25 +02:00
committed by Hyunjin Song
parent 2464a57f3c
commit c8af34af2f
3 changed files with 33 additions and 40 deletions

View File

@@ -35,7 +35,7 @@ class ProjectRenderer : public QThread
{
Q_OBJECT
public:
enum ExportFileFormats
enum ExportFileFormats: int
{
WaveFile,
OggFile,

View File

@@ -1328,10 +1328,11 @@ void Song::exportProject( bool multiExport )
efd.setFileMode( FileDialog::AnyFile );
int idx = 0;
QStringList types;
while( ProjectRenderer::fileEncodeDevices[idx].m_fileFormat != ProjectRenderer::NumFileFormats &&
ProjectRenderer::fileEncodeDevices[idx].isAvailable())
while( ProjectRenderer::fileEncodeDevices[idx].m_fileFormat != ProjectRenderer::NumFileFormats)
{
types << tr( ProjectRenderer::fileEncodeDevices[idx].m_description );
if(ProjectRenderer::fileEncodeDevices[idx].isAvailable()) {
types << tr(ProjectRenderer::fileEncodeDevices[idx].m_description);
}
++idx;
}
efd.setNameFilters( types );

View File

@@ -65,7 +65,9 @@ ExportProjectDialog::ExportProjectDialog( const QString & _file_name,
// add to combo box
fileFormatCB->addItem( ProjectRenderer::tr(
ProjectRenderer::fileEncodeDevices[i].m_description ) );
ProjectRenderer::fileEncodeDevices[i].m_description ),
QVariant(ProjectRenderer::fileEncodeDevices[i].m_fileFormat) // format tag; later used for identification
);
// if this is our extension, select it
if( QString::compare( renderExt, fileExt,
@@ -187,29 +189,16 @@ void ExportProjectDialog::startExport()
}
ProjectRenderer::ExportFileFormats convertIndexToExportFileFormat(int index)
{
switch (index)
{
case 0:
return ProjectRenderer::WaveFile;
case 1:
return ProjectRenderer::OggFile;
case 2:
return ProjectRenderer::MP3File;
default:
Q_ASSERT(false);
break;
}
return ProjectRenderer::NumFileFormats;
}
void ExportProjectDialog::onFileFormatChanged(int index)
{
ProjectRenderer::ExportFileFormats exportFormat =
convertIndexToExportFileFormat(index);
// Extract the format tag from the currently selected item,
// and adjust the UI properly.
QVariant format_tag = fileFormatCB->itemData(index);
bool successful_conversion = false;
auto exportFormat = static_cast<ProjectRenderer::ExportFileFormats>(
format_tag.toInt(&successful_conversion)
);
Q_ASSERT(successful_conversion);
bool stereoModeVisible = exportFormat == ProjectRenderer::MP3File;
@@ -236,28 +225,31 @@ void ExportProjectDialog::startBtnClicked()
{
m_ft = ProjectRenderer::NumFileFormats;
//Get file format from current menu selection.
bool successful_conversion = false;
QVariant tag = fileFormatCB->itemData(fileFormatCB->currentIndex());
m_ft = static_cast<ProjectRenderer::ExportFileFormats>(tag.toInt(&successful_conversion));
if( !successful_conversion )
{
QMessageBox::information( this, tr( "Error" ),
tr( "Error while determining file-encoder device. "
"Please try to choose a different output "
"format." ) );
reject();
return;
}
// Find proper file extension.
for( int i = 0; i < ProjectRenderer::NumFileFormats; ++i )
{
if( fileFormatCB->currentText() ==
ProjectRenderer::tr(
ProjectRenderer::fileEncodeDevices[i].m_description ) )
if (m_ft == ProjectRenderer::fileEncodeDevices[i].m_fileFormat)
{
m_ft = ProjectRenderer::fileEncodeDevices[i].m_fileFormat;
m_fileExtension = QString( QLatin1String( ProjectRenderer::fileEncodeDevices[i].m_extension ) );
break;
}
}
if( m_ft == ProjectRenderer::NumFileFormats )
{
QMessageBox::information( this, tr( "Error" ),
tr( "Error while determining file-encoder device. "
"Please try to choose a different output "
"format." ) );
reject();
return;
}
startButton->setEnabled( false );
progressBar->setEnabled( true );