Skip to content

Implement User Selectable Code Editor Style in cppcheck-gui#1913

Merged
danmar merged 1 commit intocppcheck-opensource:masterfrom
scottfurry:EditStyle
Jun 23, 2019
Merged

Implement User Selectable Code Editor Style in cppcheck-gui#1913
danmar merged 1 commit intocppcheck-opensource:masterfrom
scottfurry:EditStyle

Conversation

@scottfurry
Copy link
Copy Markdown
Contributor

Building on #1874, commit adds user controls to choose
or edit style in cppcheck-gui ONLY. Commit does not
address CodeEditor style usage in triage app at this time.

Code Editor style can be altered from the added "Code Editor"
tab in the user preferences. The user has the option to select
default light, default dark, or to customize.

If user leaves the style set to light or dark defaults, this
will be reflected in the choices shown in the preferences
dialog.

User choice for Code Editor Style is saved in the cppcheck-gui
preferences under the heading "EditorStyle".

@scottfurry
Copy link
Copy Markdown
Contributor Author

CI testing failed - logs indicated left over testing/debug code. Removed.

@scottfurry
Copy link
Copy Markdown
Contributor Author

CI highlighted warnings about variable naming conventions. Updated to correct code to expected style.

Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am eager to get this in. However I have some small nits..

Comment thread gui/codeeditor.cpp Outdated
CodeEditor::~CodeEditor()
{
// NOTE: not a Qt Object - delete manually
if( mWidgetStyle ) delete mWidgetStyle;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip the redundant check.

Comment thread gui/codeeditor.cpp Outdated
else mWidgetStyle = new CodeEditorStyle(defaultStyle);
switch( rule.ruleRole )
{
case( RuleRole::Keyword ):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho the parentheses here does not help

Comment thread gui/codeeditorstyle.cpp Outdated
return !(*this == rhs);
}

CodeEditorStyle CodeEditorStyle::LoadSettings( QSettings *pSettings )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use camelCase for function names.

I would prefer the name settings instead of pSettings.

Comment thread gui/codeeditorstyle.cpp Outdated
CodeEditorStyle CodeEditorStyle::LoadSettings( QSettings *pSettings )
{
CodeEditorStyle theStyle( defaultStyleLight );
if( pSettings) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest a early return here.

Comment thread gui/codeeditorstyle.cpp Outdated
const CodeEditorStyle& theStyle )
{
if( pSettings) {
bool bDefaultLight = ( defaultStyleLight == theStyle );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer that the name bDefaultLight is changed to isDefaultLight

@scottfurry
Copy link
Copy Markdown
Contributor Author

All changes identified above incorporated.

@scottfurry
Copy link
Copy Markdown
Contributor Author

One more...
Change not identified but was similar in nature to change identified above.

Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some more nits.

Comment thread .vscode Outdated
@@ -0,0 +1 @@
/home/scottfurry/FurCaT_Remote/CPPCheck/project/.vscode No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file from the PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. That shouldn't be there!

Comment thread gui/codeeditor.cpp Outdated
case RuleRole::Symbol:
rule.format = mSymbolFormat;
break;
default:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. I have the feeling that it's better to remove the "default". then we'll get compiler warnings if an enum value is missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this not raise another warning about a missing default in switch statement?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.. but I rather suppress that warning and get warnings when I forget enum constants instead.

Comment thread gui/codeeditorstyle.cpp Outdated
CodeEditorStyle theStyle( defaultStyleLight );
if( !settings) return theStyle;

if( settings->childGroups().contains( SETTINGS_STYLE_GROUP ))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you can have an early return here also.

Comment thread gui/codeeditorstyle.cpp Outdated

bool CodeEditorStyle::operator==( const CodeEditorStyle& rhs ) const
{
if( this->widgetFGColor != rhs.widgetFGColor ) return false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you remove "this->" in these conditions.

Comment thread gui/codeeditstylecontrols.cpp Outdated
}

void SelectColorButton::changeColor() {
QColorDialog *pDlg = new QColorDialog( mColor );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know you don't need to use new/delete for QColorDialog in this method.

QColorDialog dlg(mColor);

Comment thread gui/codeeditstylecontrols.cpp Outdated
}

void SelectColorButton::setColor( const QColor& color ) {
this->mColor = color;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "this" here.

Comment thread gui/codeeditor.cpp Outdated
mSymbolFormat.setForeground( newStyle.symbolFGColor );
mSymbolFormat.setBackground( newStyle.symbolBGColor );
mSymbolFormat.setFontWeight( newStyle.symbolWeight );
for( QVector<HighlightingRule>::iterator ruleIT = mHighlightingRules.begin();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you can't use foreach here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that. Qt foreach macro wants to use a const variable in each iteration. That becomes a problem since contents are being altered in the call to apply the style. There is the std::foreach or std::for(auto &: <container) but IIRC that is only available >=c++11.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. please try C++11 range for if you can. We use that throughout the code in cppcheck-core so you can't build the GUI unless the compiler support that anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going to change a couple of things in the .pro and CMakeList.txt files. Are you okay with that?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. let's keep it like this for now.. and then somebody can try to modernize for loops later in a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already had change incorporated and doing a full build for testing. Nothing jumps out in the logging messages. Expect this to be incorporated in final push. Only change was in .pro file where one line for gcc was using c++0x.

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Jun 23, 2019

I really look forward to the day when the full GUI uses a configurable theme! :-)

@scottfurry
Copy link
Copy Markdown
Contributor Author

All identified changes in code made.

Building on #1874, commit adds user controls to choose
or edit style in cppcheck-gui ONLY. Commit does not
address CodeEditor style usage in triage app at this time.

Code Editor style can be altered from the added "Code Editor"
tab in the user preferences. The user has the option to select
default light, default dark, or to customize.

If user leaves the style set to light or dark defaults, this
will be reflected in the choices shown in the preferences
dialog.

User choice for Code Editor Style is saved in the cppcheck-gui
preferences under the heading "EditorStyle".
Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Travis/Appveyor finish happily I think we can merge this.

@scottfurry
Copy link
Copy Markdown
Contributor Author

\o/ All checks passed!

@danmar danmar merged commit 0d76d07 into cppcheck-opensource:master Jun 23, 2019
@scottfurry scottfurry deleted the EditStyle branch June 23, 2019 17:13
danmar pushed a commit that referenced this pull request Jun 25, 2019
jubnzv pushed a commit to jubnzv/cppcheck that referenced this pull request Nov 13, 2019
…-opensource#1913)

Building on cppcheck-opensource#1874, commit adds user controls to choose
or edit style in cppcheck-gui ONLY. Commit does not
address CodeEditor style usage in triage app at this time.

Code Editor style can be altered from the added "Code Editor"
tab in the user preferences. The user has the option to select
default light, default dark, or to customize.

If user leaves the style set to light or dark defaults, this
will be reflected in the choices shown in the preferences
dialog.

User choice for Code Editor Style is saved in the cppcheck-gui
preferences under the heading "EditorStyle".
jubnzv pushed a commit to jubnzv/cppcheck that referenced this pull request Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants