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

More options in conditional formatting #2013

Merged
merged 6 commits into from
Sep 29, 2019
Merged

More options in conditional formatting #2013

merged 6 commits into from
Sep 29, 2019

Conversation

mgrojo
Copy link
Member

@mgrojo mgrojo commented Sep 27, 2019

This implements more style options for the conditional formats feature (#1815), being the first step in the addition of more formatting options to the data browser (#1976).

This also adds some minor spreadsheet-like features, like default right alignment for numbers and highlighting of column headers when a cell of that column is included in the selection.

See individual commits for details.

It is ready for merging and testing, but I plan to add more free formatting capabilities later.

The conditional format manager allows now to set the font style: bold,
italic and underline.

The project format has been updated. This is also the base for setting
other font formats without further changing the project schema.

New icons form the Silk icon set.

See issue #1976 and #1815.
Added font combo box and spin box for selecting font and font point size
of a conditional format. The default for a new conditional format is the
corresponding setting.

Minor dialog adjustments for better display.

See issues #1976 and #1815.
Combo box for selecting the desired text alignment for a conditional
format.

The default alignment in the browser has been adjusted for numbers, which
are now aligned to the right as in spreadsheets.

Project file format updated.

See issues #1976 and #1815.
Font point size preference is taken into account when creating a new
default conditional format.

New conditional formats in dialog are resized to contents.

See issues #1976 and #1815.
The column headers contained in a selection are highlighted for
consistency to the row headers and to emulated spreadsheet behaviour.
Copy link
Member

@MKleusberg MKleusberg left a comment

Choose a reason for hiding this comment

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

These are the only two (minor) issues I found. It all works really well 😄 Maybe it's best to merge this quickly then, just to avoid more merge conflicts later.

return condFormat;
bool isNumber;
value.toDouble(&isNumber);
return isNumber ? Qt::AlignRight : Qt::AlignLeft;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add vertical alignment here? Like so:

return static_cast<int>((isNumber ? Qt::AlignRight : Qt::AlignLeft) | Qt::AlignVCenter);

Same for the case where there is a conditional format. At least on my system it looks kind of weird without this because Qt set the row height a bit to high.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or what about AlignBottom? That is what LibreOffice does by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

On the other hand, LibreOffice centers vertically when the height of the text and the cell are the default. I'll use your proposal, since it was the alignment used before this change.

QTreeWidgetItem* item = ui->tableCondFormats->topLevelItem(selectedRow);

// Rescue widgets, since they will be deleted, and add them later.
QFontComboBox* fontCombo = qobject_cast<QFontComboBox*>(ui->tableCondFormats->itemWidget(item, ColumnFont));
Copy link
Member

Choose a reason for hiding this comment

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

The font combobox is too wide on my system and overlaps the other controls. Either we need to make sure it's not as wide or somehow fix the automatic column resizing. Or maybe this problem even depends on the Qt version?
Screenshot_20190928_153111

Copy link
Member Author

@mgrojo mgrojo Sep 28, 2019

Choose a reason for hiding this comment

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

That's weird! This is how it looks in my version:
imagen

Setting a maximum width could make the trick, but it looks like a Qt bug. I have another problem when a row is moved to the top:

imagen

A simple resize of the window fixes the layout.

The new toolbar is hidden by default and can be toggled using a button in
the main Data Browser toolbar. Margins and spacing have been updated to
improve appearance of the two toolbars.

These tool buttons apply the format to the columns which are contained in
the selection. This is done by updating or adding a new condition-less
format to the list of conditional formats of those columns.

New style icons from the Silk icon set. Changed existent ones for
coherence.

See issue #1976.
@mgrojo
Copy link
Member Author

mgrojo commented Sep 29, 2019

I'm having problems with the merge. The find functionality has stopped moving the scroll to the found cell, don't know why. @MKleusberg, in case you have some idea about where to look, it will be appreciated.

I go on looking into this.

@mgrojo
Copy link
Member Author

mgrojo commented Sep 29, 2019

I'm having problems with the merge. The find functionality has stopped moving the scroll to the found cell, don't know why. @MKleusberg, in case you have some idea about where to look, it will be appreciated.

I go on looking into this.

I had to add a call to ui->dataTable->scrollTo(match);. Don't know why 😕

mgrojo added a commit that referenced this pull request Sep 29, 2019
The requested text alignment is always combined with AlignVCenter, which is
the value used before conditional formatting was implemented and gives
better display result.

When creating a new conditional formatting while applying a format from the
toolbar to a column which does not already have one, the alignment flag
of the format is taken from the current cell. In this way, the default text
alignment for numbers is preserved.

See issue #1976 and PR #2013
@mgrojo mgrojo merged commit 63aabb9 into master Sep 29, 2019
@mgrojo mgrojo deleted the browser_formats branch September 29, 2019 18:17
@mgrojo
Copy link
Member Author

mgrojo commented Sep 29, 2019

I've discovered the problem with the find toolbar, which is also affecting the cursor navigation inside the table. I'm trying to use a protected slot as if it were a signal.

connect(ui->dataTable, &ExtendedTableWidget::currentChanged, this, [this](const QModelIndex &current, const QModelIndex &) {

void currentChanged(const QModelIndex &current, const QModelIndex &previous);

I've tried with this without success:

    connect(ui->dataTable->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() {

Isn't there any signal to be notified when the current index changes?

@justinclift
Copy link
Member

@scottfurry @MKleusberg ping? 😄

@scottfurry
Copy link
Contributor

Part of the problem may be the inheritance. TableBrowser class has QWidget as parent. Unlike other Qt classes with underlying table structures, we're missing a signal.

Easiest solution is to edit the header and custom signals and/or slots

# inside TableBrowser class
signal:
    customsignal(params);
public slots:
    customslot(params);

... and then the implementation in the cpp file.

@scottfurry
Copy link
Contributor

Oh yeah... and then implement the connectivity where used.
i.e. connect(....). It's messy in Qt Creator, but can be done easily in code.

@scottfurry
Copy link
Contributor

@mgrojo
Copy link
Member Author

mgrojo commented Sep 30, 2019

Thank you, @scottfurry. I guess I can reimplement the currentChanged slot in ExtentedTableWidget, call the parent implementation and then emit a new signal that can be connected from TableBrowser. I'm just surprised that there doesn't seem to be an easier way.

mgrojo added a commit that referenced this pull request Sep 30, 2019
This was causing that cursor navigation in table browser did not move the
scroll or that find bar required an additional scrollTo call.

Problem was introduced in 63aabb9

See comments in PR #2013
@SilvioGrosso
Copy link

SilvioGrosso commented Oct 2, 2019

Hello @mgrojo

Just tested on Windows 10 (64 bit) the new options as regards the Conditional Formats
It works extremely well!

Just a minor glitch:
You can not resize the cell of the condition to make it larger (by dragging its right border).
The text one types is not displayed correctly (even tough it does work in the filter afterwards)
See this screenshot where the word "agronomist" in the cell is not displayed fine. It only occurs on my laptop where the monitor is only 13 inches. It works fine with a bigger monitor though (I suppose it is a Qt "bug"...).

cell_conditional_formats

On top of this, you lose all your changes when you close the database.
This of course is not a bug but a missing feature :-)

BTW, with the conditional formats you can not undo quickly your change (with other applications the shortcuts are usually ctr+z to undo AND ctr+y to redo). You are forced to apply the conditional filter once again to remove the colours.
This would be an advantage in case you can directly colour your cells (without the filter, by way of a toolbar in the GUIs) where I suppose this option (undo - redo) might be easier to implement.
Once again all changes (new colours) should be saved when you close the database in order to get them later back when you reopen your database.

@SilvioGrosso
Copy link

SilvioGrosso commented Oct 2, 2019

Hello @mgrojo

Today, I have tested your improvements on a different computer at work.
I have tested a lot the new toolbar, with all tools ready to pick in the Browse data: fonts, size, clear conditional format etc. The new icons are extremely good-looking :-)

A problem with the conditional format is that I can not find a way to select only the whole word.
More precisely:
If I want to select the word melo the conditional format also select melone (in short it picks melo plus melone). Probably there is already a way to avoid this but I was unable to discover it :-)

As far as the changes in the GUIs are concerned (I mean the option to save all format changes in the preference file, in order to get them when you reopen the database) I really don't know whether this might open a can of worms. In short, create a feature which is extremely complicated and extremely time-consuming to code.

With GUIs changes (new improvements) there are often new bugs as soon as you change the QT version. On Windows 64, the current version with Db Browser is 5.11.3 whereas the stable version for QT is 5.13.X...
.

@mgrojo
Copy link
Member Author

mgrojo commented Oct 2, 2019

Just tested on Windows 10 (64 bit) the new options as regards the Conditional Formats
It works extremely well!

Great to hear that!

Just a minor glitch:
You can not resize the cell of the condition to make it larger (by dragging its right border).

No? I can resize it in Linux native and in Linux using Wine. Do you mean the column or that box that appears in your screenshot?

The text one types is not displayed correctly (even tough it does work in the filter afterwards)
See this screenshot where the word "agronomist" in the cell is not displayed fine. It only occurs on my laptop where the monitor is only 13 inches. It works fine with a bigger monitor though (I suppose it is a Qt "bug"...).

Yes, there are issues in this dialog. In my case they are fixed when you resize the window. It seems a Qt bug, but don't know whether I'm doing something "unusual".

On top of this, you lose all your changes when you close the database.
This of course is not a bug but a missing feature :-)

Aha, I tested only when opening an already saved project, and I didn't notice that we are not warning the user to save the project when there is no project file, except for changes in SQL tabs. I guess we should do the same when there are changes in conditional formats.

BTW, with the conditional formats you can not undo quickly your change (with other applications the shortcuts are usually ctr+z to undo AND ctr+y to redo). You are forced to apply the conditional filter once again to remove the colours.

I knew this was the next thing to be missed! You already have the reset button in the dialog and the "Clear All Conditional Formats" in the toolbar, but I know they are a poor replacement. Some day...

This would be an advantage in case you can directly colour your cells (without the filter, by way of a toolbar in the GUIs) where I suppose this option (undo - redo) might be easier to implement.

I don't get this. You hadn't seen yet the toolbar, had you? It doesn't allow yet direct formatting of cells, only of whole columns, though.

Once again all changes (new colours) should be saved when you close the database in order to get them later back when you reopen your database.

You can save them in a project file. The only thing missing is the warning to save the changes when you haven't saved to a project file yet.

Today, I have tested your improvements on a different computer at work.
I have tested a lot the new toolbar, with all tools ready to pick in the Browse data: fonts, size, clear conditional format etc. The new icons are extremely good-looking :-)

Great! Icons thanks to our usual icon set: http://www.famfamfam.com/lab/icons/silk/preview.php

A problem with the conditional format is that I can not find a way to select only the whole word.
More precisely:
If I want to select the word melo the conditional format also select melone (in short it picks melo plus melone). Probably there is already a way to avoid this but I was unable to discover it :-)

The condition field has the same syntax as the filters. So you can write "=melon" and melone will not match the conditional format. Did you mean that or have I misunderstood? Ideally the condition box should also have the same contextual menu than the filters.

As far as the changes in the GUIs are concerned (I mean the option to save all format changes in the preference file, in order to get them when you reopen the database) I really don't know whether this might open a can of worms. In short, create a feature which is extremely complicated and time-taking to code.

Are you aware that you can save them in a project file? Definitely the warning when the use has changed the formats but not yet created a project file is needed.

At present, by default, you lose all changes to the formats. For instance, if you change the date (e.g. from 2019-12-31 to 31-12-2019) this change is lost when you reopen the database.

The same warning should be raised when adding display formats. What if we warn the user with any change? The problem is that changing column sizes, sorting, filter... might be too minor to ask for saving when the user has open directly the DB. Any opinions?

With GUIs changes there are often new bugs as soon as you change the QT version. On Windows 64, the current version with Db Browser is 5.11..3 whereas the stable version for QT is 5.13.X...
.

It would be good to test whether the glitches with the Conditional Format Manager dialog are solved. @justinclift would it be possible?

@SilvioGrosso
Copy link

Hello @mgrojo,

What if we warn the user with any change? The problem is that changing column sizes, sorting, filter... might be too minor to ask for saving when the user has open directly the DB. Any opinions?

Yeah. It might be annoying...
With Calc whenever you change something (new formats, new fonts etc) in the GUIs the icon (Save) is changed but you are not forced to change (save) anything until you close the application.
Here is the icon save with a new red circle in it.

SAVE_ICON_CALC

BTW, I have just looked for a whole word with = and it does work (e.g. =melo), in the conditional format. Thanks for the tip!

Are you aware that you can save them in a project file?

Yep. I am aware. I did not make myself clear in my previous message (sorry about that).

@SilvioGrosso
Copy link

SilvioGrosso commented Oct 2, 2019

EDIT:

On Windows 64, the current version with Db Browser is 5.11..3 whereas the stable version for QT is 5.13.X..

Nope. I am completely wrong here!
The current QT "suggested" stable version is 5.12.5 (LTS).

QT 5.13.1 is the bleeding edge brand-new version.
I suppose there is no one who is using this version in their stable softwares since this version is not tested enough right now...

mgrojo added a commit that referenced this pull request Oct 5, 2019
The Filter Line Edit is ideal for this dialog because it has already a
contextual menu for helping user with the syntax and a What's This button.

Moreover, the Line Edit looks better than the integrated persistent editor.

See issue #1976 and comments in PR #2013
mgrojo added a commit that referenced this pull request Oct 6, 2019
This fixes the following issues, which might be Qt bugs or not:
- When moving an item to the top, the inserted widgets of the other items
are misplaced.
- When columns are resized to contents, the font combo box does not resize
with the column, overlapping the cells to its right.
- When adding a new item, the text just input in one filter line edit could
be lost.

See issue #1976 and comments in PR #2013.
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.

5 participants