Skip to content

Improved readability of QColor constructors#971

Merged
vadi2 merged 6 commits intoMudlet:developmentfrom
vadi2:convert-to-qcolor
Apr 28, 2017
Merged

Improved readability of QColor constructors#971
vadi2 merged 6 commits intoMudlet:developmentfrom
vadi2:convert-to-qcolor

Conversation

@vadi2
Copy link
Copy Markdown
Member

@vadi2 vadi2 commented Apr 27, 2017

Replaced the more obvious ones with enums.

Replaced the more obvious ones with enums.
@vadi2 vadi2 self-assigned this Apr 27, 2017
@vadi2 vadi2 requested review from SlySven and ahmedcharles April 27, 2017 14:07
@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Apr 27, 2017

I'm aware src/run-lua-code-v4.xml snuck in there (and why did it even get those elements? Why waste space and be verbose?) - but in getting it out, I lost all my work, so I'm not interested in doing more git history surgery.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.0">
<TriggerPackage/>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

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

I think we can go further and get rid of the QColor(...) part in some/many/all {delete as appropriate} places?

QColor blue = QColor(Qt::blue);
QColor green = QColor(Qt::green);
QColor red = QColor(Qt::red);
QColor black = QColor(Qt::black);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you do not need these locals - I suspect you can drop the Qt global constants directly into the printDebug(...) argument list.

Copy link
Copy Markdown
Member Author

@vadi2 vadi2 Apr 28, 2017

Choose a reason for hiding this comment

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

That's not possible to do. The function expects a QColor so the constants don't work, and QColor(<constant>) says expression must be lvalue.

src/T2DMap.cpp Outdated
_poly.append( _pt );
QBrush brush = p.brush();
brush.setColor( QColor(0, 0 ,0) );
brush.setColor( QColor(Qt::black) );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In some places I think you can drop the constant in without a QColor(...) around the outside - especially if a colour is expected (as a const reference perhaps?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That worked.

@ahmedcharles
Copy link
Copy Markdown
Contributor

Fixed the unrelated change, merge conflicts and accidental changes when resolving the merge conflicts.

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Apr 28, 2017

@SlySven updated.

Copy link
Copy Markdown
Contributor

@ahmedcharles ahmedcharles left a comment

Choose a reason for hiding this comment

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

QColor has an implicit constructor that accepts GlobalColor, which is the enum type used for the Qt:: values. This means that anywhere that accepts a QColor explicitly, should also accept a GlobalColor implicitly.

QColor black = QColor(0,0,0);
QColor green = QColor(Qt::green);
QColor blue = QColor(Qt::blue);
QColor black = QColor(Qt::black);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

QColor green = Qt::green; should work just fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, I see.

I'll go with auto green = QColor(Qt::green); as it's pretty much the same thing but more consistent in style.

All of them are obvious QColors from the `= QColor()`
@ahmedcharles
Copy link
Copy Markdown
Contributor

I guess I'm less of an auto fan than you are, even. :P

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Apr 28, 2017

Comes with my Lua background where local was enough to get the job done I suppose

@ahmedcharles
Copy link
Copy Markdown
Contributor

Hehe, but lua doesn't have types for variables, only values.

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Apr 28, 2017

That's right. auto makes it so I have to worry a bit less about types, while still enforcing everything about a typed system. It's nice.

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Apr 28, 2017

Linux-Cmake-GCC CI build failed for Travis Infrastructure reasons - have kicked that one build to try it again...

@vadi2 vadi2 merged commit d273e3d into Mudlet:development Apr 28, 2017
@vadi2 vadi2 deleted the convert-to-qcolor branch April 28, 2017 18:50
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.

3 participants