-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
Refactor: use a single enum to classify all TConsole instances #2138
Refactor: use a single enum to classify all TConsole instances #2138
Conversation
By replacing the following somewhat adhoc collection of flags it is easier to refactor code that is dependent on the particular type of `TConsole`: * (bool) TConsole::mIsDebugConsole * (bool) TConsole::mIsSubConsole * (bool) TConsole::mUserConsole - flag for a subConsole/Buffer/UserWindow Also removed the unused: * (bool) TConsole::mWindowIsHidden This has revealed that there are numerous cases where the `Buffer` type of `TConsole` is including code that was likely only intended for the main one for each profile...! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Suggestions for changes are welcome - as I say: some of the conditional code parts now look wrong... |
@@ -122,21 +120,27 @@ TConsole::TConsole(Host* pH, bool isDebugConsole, QWidget* parent) | |||
mStandardFormat.flags &= ~(TCHAR_STRIKEOUT); | |||
} else { | |||
setWindowTitle(tr("Non Debug Console")); | |||
if (parent) { | |||
mIsSubConsole = true; | |||
if (mType & (ErrorConsole|SubConsole|UserWindow)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that the ErrorConsole
type should be here as I do not think it should be added to the "main" console's mSubConsoleList
though give that that is not used anywhere it is probably due for removal anyhow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it matters then - we can leave it be
mpHost->mpConsole->mSubConsoleList.append(this); | ||
mMainFrameTopHeight = 0; | ||
mMainFrameBottomHeight = 0; | ||
mMainFrameLeftWidth = 0; | ||
mMainFrameRightWidth = 0; | ||
} else { | ||
mIsSubConsole = false; | ||
} else if (mType & (MainConsole|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Buffer
type should not be here I think. in fact, in the light of the previous comment I guess the ErrorConsole
and Buffer
types could/should be move to a new else if
with just:
mMainFrameTopHeight = 0;
mMainFrameBottomHeight = 0;
mMainFrameLeftWidth = 0;
mMainFrameRightWidth = 0;
@@ -567,7 +571,7 @@ TConsole::TConsole(Host* pH, bool isDebugConsole, QWidget* parent) | |||
layerCommandLine->setPalette(__pal); | |||
|
|||
changeColors(); | |||
if (!mIsSubConsole && !mIsDebugConsole) { | |||
if (mType & (MainConsole|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should, I think, be just MainConsole
...
@@ -603,7 +607,7 @@ void TConsole::setLabelStyleSheet(std::string& buf, std::string& sh) | |||
|
|||
void TConsole::resizeEvent(QResizeEvent* event) | |||
{ | |||
if (!mIsDebugConsole && !mIsSubConsole) { | |||
if (mType & (MainConsole|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just MainConsole
here also?
@@ -613,7 +617,7 @@ void TConsole::resizeEvent(QResizeEvent* event) | |||
int y = event->size().height(); | |||
|
|||
|
|||
if (!mIsSubConsole && !mIsDebugConsole) { | |||
if (mType & (MainConsole|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this and the previous can be run together with the two event->size()
lines being done beforehand.
@@ -626,7 +630,7 @@ void TConsole::resizeEvent(QResizeEvent* event) | |||
} | |||
mpMainDisplay->move(mMainFrameLeftWidth, mMainFrameTopHeight); | |||
|
|||
if (mIsSubConsole || mIsDebugConsole) { | |||
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic needs to be inverted so that the former else
code is then only used for the MainConsole
case...
@@ -635,7 +639,7 @@ void TConsole::resizeEvent(QResizeEvent* event) | |||
|
|||
QWidget::resizeEvent(event); | |||
|
|||
if (!mIsDebugConsole && !mIsSubConsole) { | |||
if (mType & (MainConsole|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need a WindowResizeEvent
for the Buffer
type but since it is not visible we probably have not been seeing the code being run for them!
@@ -656,7 +660,7 @@ void TConsole::resizeEvent(QResizeEvent* event) | |||
|
|||
void TConsole::refresh() | |||
{ | |||
if (!mIsDebugConsole) { | |||
if (mType & (ErrorConsole|MainConsole|SubConsole|UserWindow|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks odd - being run on everything except the CentralDebugConsole
???
@@ -820,7 +824,7 @@ int TConsole::getButtonState() | |||
|
|||
void TConsole::toggleLogging(bool isMessageEnabled) | |||
{ | |||
if (mIsDebugConsole || mIsSubConsole) { | |||
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, it should include the Buffer
type as well.
@@ -1030,7 +1034,7 @@ void TConsole::toggleLogging(bool isMessageEnabled) | |||
// generated for Lua user control by the Lua subsystem. | |||
void TConsole::slot_toggleLogging() | |||
{ | |||
if (mIsDebugConsole || mIsSubConsole) { | |||
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As previous - should include Buffer
as well.
@@ -1040,7 +1044,7 @@ void TConsole::slot_toggleLogging() | |||
|
|||
void TConsole::slot_toggleReplayRecording() | |||
{ | |||
if (mIsDebugConsole) { | |||
if (mType & CentralDebugConsole) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely this should include everything apart from the MainConsole
so that only that type actually does anything here.
@@ -1329,7 +1335,7 @@ void TConsole::deselect() | |||
|
|||
void TConsole::showEvent(QShowEvent* event) | |||
{ | |||
if (!mIsDebugConsole && !mIsSubConsole) { | |||
if (mType & (MainConsole|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the Buffer
type is never visible I guess it shouldn't be here.
@@ -1339,7 +1345,7 @@ void TConsole::showEvent(QShowEvent* event) | |||
|
|||
void TConsole::hideEvent(QHideEvent* event) | |||
{ | |||
if (!mIsDebugConsole && !mIsSubConsole) { | |||
if (mType & (MainConsole|Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as showEvent
.
@@ -1061,7 +1061,7 @@ void TTextEdit::slot_popupMenu() | |||
|
|||
void TTextEdit::mousePressEvent(QMouseEvent* event) | |||
{ | |||
if (!mpConsole->mIsSubConsole && !mpConsole->mIsDebugConsole) { | |||
if (mpConsole->getType() & (TConsole::MainConsole|TConsole::Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impossible for the Buffer
type!
@@ -1610,7 +1610,7 @@ void TTextEdit::mouseReleaseEvent(QMouseEvent* event) | |||
mCtrlSelecting = false; | |||
} | |||
|
|||
if (!mpConsole->mIsSubConsole && !mpConsole->mIsDebugConsole) { | |||
if (mpConsole->getType() & (TConsole::MainConsole|TConsole::Buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, impossible for the Buffer
type!
@vadi2 This is marked as a W.I.P. because I want feed-back on the types that each |
My 0.02$ is: don't let the PR grow into an untameable mess again. Merge the refractoring which reproduces the current behavior as is. Move the discussion about functional changes into their own issues, which can then spawn seperated PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - lets merge this in now so we have the improvement, and then look into cleanup as a separate PR. I've read through your comments @SlySven and they seem to make sense. Let's also merge early so people can help test!
Okay, I'll raise an issue to link back to the points I've raised here after merging it in. |
By replacing the following somewhat adhoc collection of flags it is easier to refactor code that is dependent on the particular type of
TConsole
:(bool) TConsole::mIsDebugConsole
(bool) TConsole::mIsSubConsole
(bool) TConsole::mUserConsole
- flag for a subConsole/Buffer/UserWindowAlso removed the unused:
*
(bool) TConsole::mWindowIsHidden
This has revealed that there are numerous cases where the
Buffer
type ofTConsole
is including code that was likely only intended for the main one for each profile...!Signed-off-by: Stephen Lyons slysven@virginmedia.com