Commit 1f6918e7 authored by Matthias Möller's avatar Matthias Möller

- filters not supported extensions per type

- use user defined default extensions per type

refs #1770


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17725 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b1f4b320
...@@ -54,8 +54,10 @@ ...@@ -54,8 +54,10 @@
#include <QFileDialog> #include <QFileDialog>
#include <QGroupBox> #include <QGroupBox>
#include <QBoxLayout> #include <QBoxLayout>
#include <QMultiMap>
#include <set> #include <set>
#include <map>
/// Save Settings (slot is called from CoreWidget's File-Menu) /// Save Settings (slot is called from CoreWidget's File-Menu)
void Core::saveSettings(){ void Core::saveSettings(){
...@@ -194,11 +196,11 @@ void Core::saveSettings(QString complete_name, bool is_saveObjectInfo, bool is_t ...@@ -194,11 +196,11 @@ void Core::saveSettings(QString complete_name, bool is_saveObjectInfo, bool is_t
// Store saved file's original names (in order to get number of duplicates) // Store saved file's original names (in order to get number of duplicates)
std::multiset<QString> originalFiles; std::multiset<QString> originalFiles;
QString extension(""); // Store default extensions per type
bool applyToAll = false; std::map<DataType,QString> defaultExtensions;
// get the supported extensions for when no extension is given // get the supported extensions for when no extension is given
QStringList allFilters; QMultiMap<DataType,QString> allFilters; // type -> supported extension
std::vector<fileTypes> types = supportedTypes(); const std::vector<fileTypes>& types = supportedTypes();
for (int i=0; i < (int)types.size(); i++) { for (int i=0; i < (int)types.size(); i++) {
QString filters = types[i].saveFilters; QString filters = types[i].saveFilters;
...@@ -214,24 +216,22 @@ void Core::saveSettings(QString complete_name, bool is_saveObjectInfo, bool is_t ...@@ -214,24 +216,22 @@ void Core::saveSettings(QString complete_name, bool is_saveObjectInfo, bool is_t
continue; continue;
found = true; found = true;
allFilters.append(separateFilters[filterId]); allFilters.insert(types[i].type,separateFilters[filterId]);
} }
if (!found) if (!found)
allFilters.append( filters ); allFilters.insert(types[i].type,filters);
} }
allFilters.removeDuplicates();
allFilters.sort();
// create a dialog to set extensions if none are given once // create a dialog to set extensions if none are given once
QDialog extensionDialog(coreWidget_, Qt::Dialog); QDialog extensionDialog(coreWidget_, Qt::Dialog);
QGridLayout extensionLayout; QGridLayout extensionLayout;
QCheckBox extensionCheckBox("Apply extension to all Objects without preset extensions"); const QString extensionCheckBoxPrefixString = "Apply extension to all Objects without preset extensions with DataType: ";
QCheckBox extensionCheckBox;
QComboBox extensionComboBox; QComboBox extensionComboBox;
QDialogButtonBox extensionButtons(QDialogButtonBox::Ok); QDialogButtonBox extensionButtons(QDialogButtonBox::Ok);
QDialogButtonBox::connect(&extensionButtons, SIGNAL(accepted()), &extensionDialog, SLOT(accept())); QDialogButtonBox::connect(&extensionButtons, SIGNAL(accepted()), &extensionDialog, SLOT(accept()));
extensionComboBox.addItems(allFilters); //extensionComboBox.addItems(allFilters);
extensionLayout.addWidget(&extensionComboBox); extensionLayout.addWidget(&extensionComboBox);
extensionLayout.addWidget(&extensionCheckBox); extensionLayout.addWidget(&extensionCheckBox);
extensionLayout.addWidget(&extensionButtons); extensionLayout.addWidget(&extensionButtons);
...@@ -294,33 +294,61 @@ void Core::saveSettings(QString complete_name, bool is_saveObjectInfo, bool is_t ...@@ -294,33 +294,61 @@ void Core::saveSettings(QString complete_name, bool is_saveObjectInfo, bool is_t
filename += finfo.completeSuffix(); filename += finfo.completeSuffix();
} }
// check if the name of the object specifies already the extension
bool extInName = false;
for (QMultiMap<DataType,QString>::const_iterator e_it = allFilters.begin(); e_it != allFilters.end(); ++e_it)
{
// suffix is the same as one extension and
extInName = e_it.key().contains(o_it->dataType()) && e_it.value() == QString("*.")+QFileInfo(filename).suffix();
if (extInName)
break;
}
// check if we have an extension for the object if (!extInName)
const QString suffix = QFileInfo(filename).suffix(); {
if (suffix == "" || !allFilters.contains(suffix)) { // search for the default data type
std::map<DataType,QString>::const_iterator defaultExtIt = defaultExtensions.find(o_it->dataType());
if (!applyToAll) { bool useDefault = defaultExtIt != defaultExtensions.end();
QString extension = (useDefault) ? defaultExtIt->second : "";
extensionDialog.move(coreWidget_->width()/2 - extensionDialog.width(), // if no default extension for the datatype was given, request one
coreWidget_->height()/2 - extensionDialog.height()); if (!useDefault)
{
// present only those filters, which support the type
QStringList supportedFilters;
for (QMultiMap<DataType,QString>::const_iterator it = allFilters.begin(); it != allFilters.end() ; ++it)
{
if (it.key().contains(o_it->dataType()))
supportedFilters.append(it.value());
}
extensionComboBox.clear();
extensionComboBox.addItems(supportedFilters);
extensionDialog.setWindowTitle("Please specify a file extension for " + o_it->name()); extensionDialog.setWindowTitle("Please specify a file extension for " + o_it->name());
extensionCheckBox.setText(extensionCheckBoxPrefixString + typeName(o_it->dataType()));
extensionDialog.move(coreWidget_->width()/2 - extensionDialog.width(),
coreWidget_->height()/2 - extensionDialog.height());
if (extensionDialog.exec() && !allFilters.isEmpty()) { if (extensionDialog.exec() && !supportedFilters.isEmpty())
if (extensionCheckBox.isChecked()) {
applyToAll = true;
extension = extensionComboBox.currentText(); extension = extensionComboBox.currentText();
extension = QFileInfo(extension).suffix(); extension = QFileInfo(extension).suffix();
filename += "." + extension; filename += "." + extension;
} else { if (extensionCheckBox.isChecked())
defaultExtensions[o_it->dataType()] = extension;
} else
{
emit log(LOGERR, tr("Unabel to save %1. No extension specified.").arg(o_it->name())); emit log(LOGERR, tr("Unabel to save %1. No extension specified.").arg(o_it->name()));
continue; continue;
} }
} else { } else
{
filename += "." + extension; filename += "." + extension;
} }
} }
// decide whether to use saveObject or saveObjectTo // decide whether to use saveObject or saveObjectTo
if ( !QFile(filename).exists() || !is_askOverwrite ) if ( !QFile(filename).exists() || !is_askOverwrite )
saveObject( o_it->id(), filename); saveObject( o_it->id(), filename);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment