GeezerVison is showing github.com — Gui select bcb6 projects (#1258) · cppcheck-opensource/cppcheck@1af983d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: gui/common.cpp +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 |
| 19 | 19 |
| 20 | 20 | #include "common.h" | | 21 | +#include <QCoreApplication> | 21 | 22 | #include <QSettings> | 22 | 23 | #include <QFileInfo> | 23 | 24 | #include <QDir> | @@ -42,3 +43,26 @@ void setPath(const QString &type, const QString &value) | 42 | 43 | QSettings settings; | 43 | 44 | settings.setValue(type, value); | 44 | 45 | } | | 46 | + | | 47 | +QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupported, bool addAll) | | 48 | +{ | | 49 | + QStringList entries; | | 50 | + | | 51 | + if (addAllSupported) { | | 52 | + entries << QCoreApplication::translate("toFilterString", "All supported files (%1)") | | 53 | + .arg(QStringList(filters.values()).join(" ")); | | 54 | + } | | 55 | + | | 56 | + if (addAll) { | | 57 | + entries << QCoreApplication::translate("toFilterString", "All files (%1)").arg("*.*"); | | 58 | + } | | 59 | + | | 60 | + // We're using the description of the filters as the map keys, the file | | 61 | + // name patterns are our values. The generated filter string list will | | 62 | + // thus be sorted alphabetically over the descriptions. | | 63 | + for (auto k: filters.keys()) { | | 64 | + entries << QString("%1 (%2)").arg(k).arg(filters.value(k)); | | 65 | + } | | 66 | + | | 67 | + return entries.join(";;"); | | 68 | +} |
Collapse file Copy file name to clipboardExpand all lines: gui/common.h +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | #ifndef COMMON_H | 20 | 20 | #define COMMON_H | 21 | 21 |
| | 22 | +#include <QMap> | 22 | 23 | #include <QString> | 23 | 24 |
| 24 | 25 | /// @addtogroup GUI | | 106 | 107 | #define SETTINGS_LAST_INCLUDE_PATH "Last include path" | 107 | 108 | #define SETTINGS_LAST_APP_PATH "Last application path" | 108 | 109 |
| | 110 | +#define SETTINGS_LAST_ANALYZE_FILES_FILTER "Last analyze files filter" | 109 | 111 |
| 110 | 112 | /** | 111 | 113 | * @brief Obtains the path of specified type | @@ -124,5 +126,31 @@ QString getPath(const QString &type); | 124 | 126 | */ | 125 | 127 | void setPath(const QString &type, const QString &value); | 126 | 128 |
| | 129 | +/** | | 130 | + * @brief Creates a string suitable for passing as the filter argument to | | 131 | + * methods like QFileDialog::getOpenFileName. | | 132 | + * @param filters A map of filter descriptions to the associated file name | | 133 | + * patterns. | | 134 | + * @param addAllSupported If set to true (the default), the function will | | 135 | + * include a filter entry containing all the file name patterns found in | | 136 | + * \p filters. This entry will be the first in the resulting filter string. | | 137 | + * @param addAll If set to true (the default), the function will | | 138 | + * include a filter entry displaying all files. This entry will be placed | | 139 | + * after the entry for \p addAllSupported files. | | 140 | + * | | 141 | + * Example usage: | | 142 | + * | | 143 | + * @code | | 144 | + * QMap<QString,QString> filters; | | 145 | + * filters[tr("Supported images")] = "*.bmp *.jpg *.png"; | | 146 | + * filters[tr("Plain text")] = "*.txt"; | | 147 | + * | | 148 | + * const QString filterString = toFilterString(filters); | | 149 | + * | | 150 | + * // filterString contains "All supported files (*.txt *.bmp *.jpg *.png);;All files (*.*);;Plain text (*.txt);;Supported images (*.bmp *.jpg *.png)" | | 151 | + * @endcode | | 152 | + */ | | 153 | +QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupported=true, bool addAll=true); | | 154 | + | 127 | 155 | /// @} | 128 | 156 | #endif |
Collapse file Copy file name to clipboardExpand all lines: gui/mainwindow.cpp +14-5Lines changed: 14 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -574,13 +574,19 @@ QStringList MainWindow::selectFilesToAnalyze(QFileDialog::FileMode mode) | 574 | 574 | // QFileDialog::getExistingDirectory() because they show native Windows | 575 | 575 | // selection dialog which is a lot more usable than Qt:s own dialog. | 576 | 576 | if (mode == QFileDialog::ExistingFiles) { | 577 | | - | | 577 | + QMap<QString,QString> filters; | | 578 | + filters[tr("C/C++ Source")] = FileList::getDefaultFilters().join(" "); | | 579 | + filters[tr("Compile database")] = compile_commands_json; | | 580 | + filters[tr("Visual Studio")] = "*.sln *.vcxproj"; | | 581 | + filters[tr("Borland C++ Builder 6")] = "*.bpr"; | | 582 | + QString lastFilter = mSettings->value(SETTINGS_LAST_ANALYZE_FILES_FILTER).toString(); | 578 | 583 | selected = QFileDialog::getOpenFileNames(this, | 579 | 584 | tr("Select files to analyze"), | 580 | 585 | getPath(SETTINGS_LAST_CHECK_PATH), | 581 | | - tr("C/C++ Source, Compile database, Visual Studio (%1 %2 *.sln *.vcxproj)") | 582 | | - .arg(FileList::getDefaultFilters().join(" ")) | 583 | | - .arg(compile_commands_json)); | | 586 | + toFilterString(filters), | | 587 | + &lastFilter); | | 588 | + mSettings->setValue(SETTINGS_LAST_ANALYZE_FILES_FILTER, lastFilter); | | 589 | + | 584 | 590 | if (selected.isEmpty()) | 585 | 591 | mCurrentDirectory.clear(); | 586 | 592 | else { | @@ -613,7 +619,10 @@ void MainWindow::analyzeFiles() | 613 | 619 | QStringList selected = selectFilesToAnalyze(QFileDialog::ExistingFiles); | 614 | 620 |
| 615 | 621 | const QString file0 = (selected.size() ? selected[0].toLower() : QString()); | 616 | | - if (file0.endsWith(".sln") || file0.endsWith(".vcxproj") || file0.endsWith(compile_commands_json)) { | | 622 | + if (file0.endsWith(".sln") | | 623 | + || file0.endsWith(".vcxproj") | | 624 | + || file0.endsWith(compile_commands_json) | | 625 | + || file0.endsWith(".bpr")) { | 617 | 626 | ImportProject p; | 618 | 627 | p.import(selected[0].toStdString()); | 619 | 628 |
| |
Collapse file Copy file name to clipboardExpand all lines: gui/projectfiledialog.cpp +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -365,9 +365,13 @@ void ProjectFileDialog::browseImportProject() | 365 | 365 | { | 366 | 366 | const QFileInfo inf(mProjectFile->getFilename()); | 367 | 367 | const QDir &dir = inf.absoluteDir(); | | 368 | + QMap<QString,QString> filters; | | 369 | + filters[tr("Visual Studio")] = "*.sln *.vcxproj"; | | 370 | + filters[tr("Compile database")] = "compile_commands.json"; | | 371 | + filters[tr("Borland C++ Builder 6")] = "*.bpr"; | 368 | 372 | QString fileName = QFileDialog::getOpenFileName(this, tr("Import Project"), | 369 | 373 | dir.canonicalPath(), | 370 | | - tr("Visual Studio (*.sln *.vcxproj);;Compile database (compile_commands.json)")); | | 374 | + toFilterString(filters)); | 371 | 375 | if (!fileName.isEmpty()) { | 372 | 376 | mUI.mEditImportProject->setText(dir.relativeFilePath(fileName)); | 373 | 377 | updatePathsAndDefines(); | |
Collapse file Copy file name to clipboardExpand all lines: gui/projectfiledialog.ui +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | <item> | 28 | 28 | <widget class="QGroupBox" name="groupBox_4"> | 29 | 29 | <property name="title"> | 30 | | - <string>Import Project (Visual studio / compile database)</string> | | 30 | + <string>Import Project (Visual studio / compile database/ Borland C++ Builder 6)</string> | 31 | 31 | </property> | 32 | 32 | <layout class="QVBoxLayout" name="verticalLayout_4"> | 33 | 33 | <item> | |
|