Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferences Feature added #489

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ jobs:
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647

- name: Filter out MISRA
# Filter out MISRA and potentially reduce the number of runs in the SARIF output
- name: Filter and Reduce SARIF
run: |
pip install globber
python3 scripts/filter_sarif.py --input results.sarif --output filtered.sarif --split-lines -- "-**/*.*:cppcheck_misra*"
python3 scripts/filter_and_reduce_sarif.py --input results.sarif --output filtered_and_reduced.sarif
env:
PYTHONUNBUFFERED: 1

# Upload the SARIF file generated in the previous step

# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: filtered.sarif
sarif_file: filtered_and_reduced.sarif
21 changes: 19 additions & 2 deletions avogadro/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
******************************************************************************/

#include "mainwindow.h"

#include "aboutdialog.h"
#include "avogadroappconfig.h"
#include "backgroundfileformat.h"
#include "menubuilder.h"
#include "preferencesdialog.h"
#include "renderingdialog.h"
#include "tdxcontroller.h"
#include "tooltipfilter.h"
Expand Down Expand Up @@ -300,7 +300,7 @@ MainWindow::MainWindow(const QStringList& fileNames, bool disableSettings)

// Now set up the interface.
setupInterface();

initializeActions();
// Build up the standard menus, incorporate dynamic menus.
buildMenu();
updateRecentFiles();
Expand Down Expand Up @@ -356,7 +356,24 @@ MainWindow::~MainWindow()
delete m_menuBuilder;
delete m_viewFactory;
}
void MainWindow::initializeActions()
{
// Example initialization, adjust according to your needs
m_actionPreferences = new QAction(tr("&Preferences"), this);
connect(m_actionPreferences, &QAction::triggered, this,
&MainWindow::showPreferencesDialog);
// Add m_actionPreferences to the appropriate menu or toolbar
}

void MainWindow::showPreferencesDialog()
{
PreferencesDialog dialog(this);
dialog.loadSettings();

if (dialog.exec() == QDialog::Accepted) {
dialog.applySettings(); // Apply and save settings
}
}
void MainWindow::setupInterface()
{
// We take care of setting up the main interface here, along with any custom
Expand Down
9 changes: 5 additions & 4 deletions avogadro/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#ifndef AVOGADRO_MAINWINDOW_H
#define AVOGADRO_MAINWINDOW_H

#include "preferencesdialog.h"
#include <QtCore/QStringList>
#include <QtCore/QVariantMap>
#include <QtWidgets/QMainWindow>

#ifdef QTTESTING
class pqTestUtility;
#endif
Expand All @@ -19,7 +19,7 @@ class QThread;
class QTreeView;
class QNetworkAccessManager;
class QNetworkReply;

class QAction;
namespace Ui {
class AboutDialog;
}
Expand Down Expand Up @@ -74,7 +74,8 @@ public slots:
* Update internal state to reflect that the molecule has been modified.
*/
void markMoleculeDirty();

void showPreferencesDialog();
void initializeActions();
/**
* Update internal state to reflect that the molecule is not modified.
*/
Expand Down Expand Up @@ -442,7 +443,7 @@ private slots:
QAction* m_copyImage;
QAction* m_viewPerspective;
QAction* m_viewOrthographic;

QAction* m_actionPreferences;
ViewFactory* m_viewFactory;

QNetworkAccessManager* m_network = nullptr;
Expand Down
59 changes: 48 additions & 11 deletions avogadro/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@
<addaction name="actionCopy"/>
<addaction name="actionPaste"/>
<addaction name="actionClear"/>
</widget>
<widget class="QMenu" name="menuSelect">
<property name="title">
<string>&amp;Select</string>
</property>
</widget>
<addaction name="menuFile"/>

<addaction name="separator"/>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
<addaction name="menuBuild"/>
<addaction name="menuSelect"/>
<addaction name="actionPreferences"/>
</widget>
<action name="actionOpen">
<property name="text">
Expand Down Expand Up @@ -323,6 +320,35 @@
<string>&amp;Import</string>
</property>
</action>
<action name="actionPreferences">
<property name="text">
<string>Preferences…</string>
</property>
<property name="icon">
<iconset>
<normaloff>:icons/preferences-icon.png</normaloff>:icons/preferences-icon.png
</iconset>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>




<property name="text">
<string>Preferences…</string>
</property>
<property name="icon">
<iconset>
<normaloff>:icons/preferences-icon.png</normaloff>:icons/preferences-icon.png</iconset>
</property>
-->
</action>
<string>Preferences…</string>
</property>
</action>
<action name="actionExport">
<property name="text">
<string>&amp;Export</string>
Expand All @@ -337,6 +363,7 @@
<sender>actionClose</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>showPreferencesDialog()</slot>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
Expand All @@ -350,10 +377,20 @@
</hints>
</connection>
<connection>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
</connection>

<connection>
<sender>actionPreferences</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>showPreferencesDialog()</slot>
</connection>
</connections>

<hints>
<hint type="sourcelabel">
<x>-1</x>
Expand Down
84 changes: 34 additions & 50 deletions scripts/filter_sarif.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,58 +64,42 @@ def parse_pattern(line):


def filter_sarif(args):
if args.split_lines:
tmp = []
for pattern in args.patterns:
tmp = tmp + re.split("\r?\n", pattern)
args.patterns = tmp

args.patterns = [parse_pattern(pattern) for pattern in args.patterns if pattern]

print("Given patterns:")
for sign, file_pattern, rule_pattern in args.patterns:
sign_text = "positive" if sign else "negative"
print(f"files: {file_pattern} rules: {rule_pattern} ({sign_text})")

with open(args.input, "r", encoding="UTF-8") as file:
sarif = json.load(file)

for run in sarif.get("runs", []):
if run.get("results", []):
new_results = []
for result in run["results"]:
if result.get("locations", []):
new_locations = []
for location in result["locations"]:
# TODO: The uri field is optional. We might have to fetch the
# actual uri from "artifacts" via "index"
# (https://github.com/microsoft/sarif-tutorials/blob/main/docs/2-Basics.md)
uri = (
location.get("physicalLocation", {})
.get("artifactLocation", {})
.get("uri", None)
)
# TODO: The ruleId field is optional and potentially ambiguous.
# We might have to fetch the actual ruleId from the rule metadata
# via the ruleIndex field.
# (https://github.com/microsoft/sarif-tutorials/blob/main/docs/2-Basics.md)
rule_id = result["ruleId"]
if uri is None or match_path_and_rule(
uri, rule_id, args.patterns
):
new_locations.append(location)
result["locations"] = new_locations
if new_locations:
try:
with open(args.input, "r", encoding="UTF-8") as file:
sarif = json.load(file)
except Exception as e:
print(f"Error reading SARIF file: {e}")
return

try:
for run in sarif.get("runs", []):
if run.get("results", []):
new_results = []
for result in run["results"]:
if result.get("locations", []):
new_locations = []
for location in result["locations"]:
uri = (
location.get("physicalLocation", {})
.get("artifactLocation", {})
.get("uri", None)
)
rule_id = result["ruleId"]
if uri is None or match_path_and_rule(
uri, rule_id, args.patterns
):
new_locations.append(location)
result["locations"] = new_locations
if new_locations:
new_results.append(result)
else:
new_results.append(result)
else:
# locations array doesn't exist or is empty, so we can't match on anything
# therefore, we include the result in the output
new_results.append(result)
run["results"] = new_results

with open(args.output, "w", encoding="UTF-8") as file:
json.dump(sarif, file, indent=args.indent)
run["results"] = new_results

with open(args.output, "w", encoding="UTF-8") as file:
json.dump(sarif, file, indent=args.indent)
except Exception as e:
print(f"Error processing SARIF file: {e}")

def main():
parser = argparse.ArgumentParser(prog="filter-sarif")
Expand Down