Conformed to FreeCAD coding conventions

This commit is contained in:
Chris Hennes
2020-12-24 00:47:21 -06:00
committed by wmayer
parent dc09810e98
commit e3f8847450

View File

@@ -291,6 +291,10 @@ Format options are:
%D - the date and time, in local timezone, ISO 8601
Any other characters are treated literally, though if the filename is illegal
it will be changed on saving.
The format string is stored in two user preferences (not currently exposed in the GUI):
* BaseApp/Preferences/General/ExportDefaultFilenameSingle
* BaseApp/Preferences/General/ExportDefaultFilenameMultiple
*/
QString createDefaultExportBasename()
{
@@ -301,7 +305,7 @@ QString createDefaultExportBasename()
if (selection.size() == 1) {
exportFormatString = QString::fromStdString (App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
GetASCII("ExportDefaultFilenameSingle", "%F-%P-"));
}
}
else {
exportFormatString = QString::fromStdString (App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
GetASCII("ExportDefaultFilenameMultiple", "%F"));
@@ -313,15 +317,13 @@ QString createDefaultExportBasename()
QString docFilename = QString::fromUtf8(App::GetApplication().getActiveDocument()->getFileName());
QFileInfo fi(docFilename);
QString fcstdBasename = fi.completeBaseName();
if (fcstdBasename.isEmpty()) {
if (fcstdBasename.isEmpty())
fcstdBasename = QString::fromStdString(App::GetApplication().getActiveDocument()->Label.getStrValue());
}
// %L - the label of the selected object(s)
QStringList objectLabels;
for (const auto& object : selection) {
for (const auto& object : selection)
objectLabels.push_back(QString::fromStdString(object->Label.getStrValue()));
}
// %P - the label of the selected objects and their first parent
QStringList parentLabels;
@@ -341,16 +343,22 @@ QString createDefaultExportBasename()
QDateTime local = utc.toLocalTime();
QString localISO8601 = local.toString(Qt::ISODate);
// Parse the format string one character at a time:
for (int i = 0; i < exportFormatString.size(); ++i) {
auto c = exportFormatString.at(i);
if (c != QLatin1Char('%')) {
// Anything that's not a format start character is just a literal
defaultFilename.append(c);
}
else {
// The format start character now requires us to look at at least the next single
// character (if there isn't another character, the % just gets eaten)
if (i < exportFormatString.size() - 1) {
++i;
auto formatChar = exportFormatString.at(i);
QChar separatorChar = QLatin1Char('-');
// If this format type requires an additional char, read that now (or default to
// '-' if the format string ends)
if (formatChar == QLatin1Char('L') ||
formatChar == QLatin1Char('P')) {
if (i < exportFormatString.size() - 1) {
@@ -384,7 +392,7 @@ QString createDefaultExportBasename()
}
}
// Finally, clean the string:
// Finally, clean the string so it's valid for all operating systems:
QString invalidCharacters = QLatin1String("/\\?%*:|\"<>");
for (const auto &c : invalidCharacters)
defaultFilename.replace(c,QLatin1String("_"));
@@ -413,17 +421,15 @@ void StdCmdExport::activated(int iMsg)
std::map<std::string, std::string> filterMap = App::GetApplication().getExportFilters();
for (const auto &filter : filterMap) {
// ignore the project file format
if (filter.first.find("(*.FCStd)") == std::string::npos) {
if (filter.first.find("(*.FCStd)") == std::string::npos)
filterList << QString::fromStdString(filter.first);
}
}
QString formatList = filterList.join(QLatin1String(";;"));
Base::Reference<ParameterGrp> hPath =
App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("General");
QString selectedFilter = QString::fromStdString(hPath->GetASCII("FileExportFilter"));
if (!lastExportFilterUsed.isEmpty()) {
if (!lastExportFilterUsed.isEmpty())
selectedFilter = lastExportFilterUsed;
}
// Create a default filename for the export
// * If this is the first export this session default, generate a new default.
@@ -460,9 +466,8 @@ void StdCmdExport::activated(int iMsg)
// Append the last extension used, if there is one.
if (!lastExportFullPath.isEmpty()) {
QFileInfo lastExportFile(lastExportFullPath);
if (!lastExportFile.suffix().isEmpty()) {
if (!lastExportFile.suffix().isEmpty())
defaultFilename += QLatin1String(".") + lastExportFile.suffix();
}
}
filenameWasGenerated = true;
}
@@ -488,12 +493,10 @@ void StdCmdExport::activated(int iMsg)
QFileInfo defaultExportFI(defaultFilename);
QFileInfo thisExportFI(fileName);
if (filenameWasGenerated &&
thisExportFI.completeBaseName() == defaultExportFI.completeBaseName()) {
thisExportFI.completeBaseName() == defaultExportFI.completeBaseName())
lastExportUsedGeneratedFilename = true;
}
else {
else
lastExportUsedGeneratedFilename = false;
}
lastExportFullPath = fileName;
}
}