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

Add 'New Tileset...' button when no tileset is opened #1789

Merged
merged 8 commits into from
Nov 7, 2017

Conversation

RhenaudTheLukark
Copy link
Contributor

Feature announced in the issue #1766.

Copy link
Contributor

@ketanhwr ketanhwr left a comment

Choose a reason for hiding this comment

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

Some general suggestions regarding the code style 🙂

@@ -553,6 +576,11 @@ void TilesetDock::deleteTilesetView(int index)
delete view; // view needs to go before the tab
mTabBar->removeTab(index);

// Make the "New Tileset..." special tab reappear if there is no tileset open
if (mTilesets.count() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove the braces since it's only 1 line block.

Copy link
Contributor Author

@RhenaudTheLukark RhenaudTheLukark Oct 18, 2017

Choose a reason for hiding this comment

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

I've already changed that in the second commit.
Or maybe I didn't?
I'll check again.
EDIT: You were right, I removed the brackets in the first commit but somehow added them again?
Anyway it's fixed now!

@@ -165,7 +165,7 @@ private slots:
TilesetDocumentsFilterModel *mTilesetDocumentsFilterModel;

QTabBar *mTabBar;
QStackedWidget *mViewStack;
QStackedWidget *mSuperViewStack, *mViewStack;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define each variable in a new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do on the third commit.

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

I didn't get around to trying it out yet, but here's my comments on the code.

class NewTilesetView : public QWidget
{
public:
explicit NewTilesetView(QWidget *tmb = nullptr)
Copy link
Member

Choose a reason for hiding this comment

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

What's a tmb? Normally this parameter is called the parent.

{
QWidget *w = new QWidget(this);

QPushButton *pbNewTileset = new QPushButton(w);
Copy link
Member

Choose a reason for hiding this comment

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

Please just call it newTilesetButton.

QPushButton *pbNewTileset = new QPushButton(w);
pbNewTileset->setText(QStringLiteral("New Tileset..."));

connect(pbNewTileset, SIGNAL(released()), tmb, SLOT(newTileset()));
Copy link
Member

Choose a reason for hiding this comment

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

At this point, "tmb" is just a widget. It does not indicate what this "newTileset" slot may be, which is bad for code readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it, instead of giving a QWidget, I'll specify you need to give the TilesetDock itself, which is what this QWidget is.

@@ -553,6 +576,10 @@ void TilesetDock::deleteTilesetView(int index)
delete view; // view needs to go before the tab
mTabBar->removeTab(index);

// Make the "New Tileset..." special tab reappear if there is no tileset open
if (mTilesets.count() == 0)
Copy link
Member

Choose a reason for hiding this comment

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

Please use mTilesets.isEmpty()

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

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

I've tried it out but, but here's out it looks on my side:

selection_225

There's two problems here:

  • The button didn't receive the size it needs for the label to fit properly.
  • I think the button should be centered.

You'll need to set a layout (probably QGridLayout) on the NewTilesetView (which I think would be better named NoTilesetWidget) that will apply the size preferences of the button and to which you can add QSpacerItem instances for centering the button. You could check out noeditorwidget.ui to see how this could be achieved and either do the same in code (see the generated ui_noeditorwidget.h when in doubt) or also make a .ui file for this widget.

explicit NewTilesetView(TilesetDock *parent = nullptr)
: QWidget(parent)
{
QWidget *w = new QWidget(this);
Copy link
Member

Choose a reason for hiding this comment

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

This widget serves no purpose apart from adding just another level to the widget hierarchy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I'll take a look at all of that.

I tried to center the button, but everything I tried didn't work.

Copy link
Member

Choose a reason for hiding this comment

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

You basically just need spacer items on all 4 sides for centering the button, and for that it needs to be in a grid layout.

@RhenaudTheLukark
Copy link
Contributor Author

I tried to center the button, but no matter which way I took the problem from, I couldn't do better than that.

This is a simple task, yet somehow the QGridLayout widget is not taking the whole space the QDockWidget provides, so the button is centered horizontally but not vertically.

I surrounded it with QSpacerItem objects, but I couldn't center it vertically anyway.

Tell me if this is good enough (I really hope it is)

QGridLayout *gridLayout = new QGridLayout(this);

QSpacerItem *spacerVertTop = new QSpacerItem(1, 1, QSizePolicy::Ignored, QSizePolicy::Expanding);
gridLayout->addItem(spacerVertTop, 1, 0, Qt::AlignCenter);
Copy link
Member

Choose a reason for hiding this comment

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

This isn't doing what you think it does. You're actually passing Qt::AlignCenter as the row-span argument to addItem, which explains why the centering isn't working correctly.

I found out that the use of spacers isn't needed at all though, since we can just pass Qt::AlignCenter when adding the New Tileset button. I'll push this change in a moment.

@bjorn
Copy link
Member

bjorn commented Nov 7, 2017

Tell me if this is good enough (I really hope it is)

Of course it isn't good enough to have a bunch of code sitting there not achieving what it is meant to do. :-)

It wasn't easy for me either to find out what was going on though. A compiler warning would have certainly helped, but in C++ passing an enum value to an int parameter is perfectly valid.

@bjorn bjorn merged commit 77def2b into mapeditor:master Nov 7, 2017
@bjorn
Copy link
Member

bjorn commented Nov 7, 2017

Thanks! :-)

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.

None yet

3 participants