From: Benjamin ROBIN <dev@benjarobin.fr>
To: <y.karadz@gmail.com>
Cc: <linux-trace-devel@vger.kernel.org>, Benjamin ROBIN <dev@benjarobin.fr>
Subject: [PATCH 32/34] kernelshark: Fix KsTableView columns width, and KsTraceViewer size
Date: Sun, 14 Jan 2024 18:17:21 +0100 [thread overview]
Message-ID: <20240114171723.14092-33-dev@benjarobin.fr> (raw)
In-Reply-To: <20240114171723.14092-1-dev@benjarobin.fr>
- Use QSizePolicy::Expanding for KsTraceViewer object to use full height
- Do not use StyleSheet for KsTableView. When the StyleSheet is updated Qt6
redraw the whole table but with default column width without querying items
sizeHint(). So instead use QPalette::Highlight.
- Simplify _resizeToContents() since the columns have a proper width with Qt6
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=218351
Signed-off-by: Benjamin ROBIN <dev@benjarobin.fr>
---
src/KsTraceViewer.cpp | 67 ++++++++++++-------------------------------
src/KsTraceViewer.hpp | 2 ++
2 files changed, 20 insertions(+), 49 deletions(-)
diff --git a/src/KsTraceViewer.cpp b/src/KsTraceViewer.cpp
index 86e9185..93535a4 100644
--- a/src/KsTraceViewer.cpp
+++ b/src/KsTraceViewer.cpp
@@ -83,7 +83,7 @@ KsTraceViewer::KsTraceViewer(QWidget *parent)
_mState(nullptr),
_data(nullptr)
{
- this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+ this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
/* Make a search toolbar. */
_toolbar.setOrientation(Qt::Horizontal);
@@ -125,6 +125,7 @@ KsTraceViewer::KsTraceViewer(QWidget *parent)
int defaultRowHeight = FONT_HEIGHT * 1.25;
auto lamSelectionChanged = [this, defaultRowHeight] (const QItemSelection &selected,
const QItemSelection &deselected) {
+
if (deselected.count()) {
_view.verticalHeader()->resizeSection(deselected.indexes().first().row(),
defaultRowHeight);
@@ -208,33 +209,13 @@ void KsTraceViewer::loadData(KsDataStore *data)
/** Connect the QTableView widget and the State machine of the Dual marker. */
void KsTraceViewer::setMarkerSM(KsDualMarkerSM *m)
{
- QString styleSheetA, styleSheetB;
-
_mState = m;
_model.setMarkerColors(_mState->markerA()._color,
_mState->markerB()._color);
- /*
- * Assign a property to State A of the Dual marker state machine. When
- * the marker is in State A the background color of the selected row
- * will be the same as the color of Marker A.
- */
- styleSheetA = "selection-background-color : " +
- _mState->markerA()._color.name() + ";";
-
- _mState->stateAPtr()->assignProperty(&_view, "styleSheet",
- styleSheetA);
-
- /*
- * Assign a property to State B. When the marker is in State B the
- * background color of the selected row will be the same as the color
- * of Marker B.
- */
- styleSheetB = "selection-background-color : " +
- _mState->markerB()._color.name() + ";";
-
- _mState->stateBPtr()->assignProperty(&_view, "styleSheet",
- styleSheetB);
+ _viewPalette = _view.palette();
+ _viewPalette.setColor(QPalette::Highlight, _mState->activeMarker()._color);
+ _view.setPalette(_viewPalette);
}
/** Reset (empty) the table. */
@@ -502,35 +483,38 @@ void KsTraceViewer::markSwitch()
ssize_t row;
/* The state of the Dual marker has changed. Get the new active marker. */
- DualMarkerState state = _mState->getState();
+ DualMarkerState actState = _mState->getState();
+ DualMarkerState pasState = !actState;
/* First deal with the passive marker. */
- if (_mState->getMarker(!state)._isSet) {
+ KsGraphMark &pasMark = _mState->getMarker(pasState);
+ if (pasMark._isSet) {
/*
* The passive marker is set. Use the model to color the row of
* the passive marker.
*/
- _model.selectRow(!state, _mState->getMarker(!state)._pos);
+ _model.selectRow(pasState, pasMark._pos);
}
else {
/*
* The passive marker is not set.
* Make sure that the model colors nothing.
*/
- _model.selectRow(!state, KS_NO_ROW_SELECTED);
+ _model.selectRow(pasState, KS_NO_ROW_SELECTED);
}
/*
* Now deal with the active marker. This has to be done after dealing
* with the model, because changing the model clears the selection.
*/
- if (_mState->getMarker(state)._isSet) {
+ KsGraphMark &actMark = _mState->getMarker(actState);
+ if (actMark._isSet) {
/*
* The active marker is set. Use QTableView to select its row.
* The index in the source model is used to retrieve the value
* of the row number in the proxy model.
*/
- row =_mState->getMarker(state)._pos;
+ row = actMark._pos;
QModelIndex index =
_proxyModel.mapFromSource(_model.index(row, 0));
@@ -552,6 +536,9 @@ void KsTraceViewer::markSwitch()
_view.clearSelection();
}
+ _viewPalette.setColor(QPalette::Highlight, actMark._color);
+ _view.setPalette(_viewPalette);
+
row = selectedRow();
if (row >= 0) {
_setSearchIterator(row);
@@ -604,7 +591,7 @@ void KsTraceViewer::keyReleaseEvent(QKeyEvent *event)
void KsTraceViewer::_resizeToContents()
{
- int col, rows, columnSize, markRow = selectedRow();
+ int markRow = selectedRow();
_view.setVisible(false);
_view.resizeColumnsToContents();
@@ -617,24 +604,6 @@ void KsTraceViewer::_resizeToContents()
*/
if (markRow == KS_NO_ROW_SELECTED)
_view.clearSelection();
-
- /*
- * Because of some unknown reason some of the columns doesn't get
- * resized properly by the code above. We will resize this
- * column by hand.
- */
- col = KsViewModel::TRACE_VIEW_COL_STREAM;
- columnSize = STRING_WIDTH(_model.header().at(col)) + FONT_WIDTH;
- _view.setColumnWidth(col, columnSize);
-
- col = KsViewModel::TRACE_VIEW_COL_CPU;
- columnSize = STRING_WIDTH(_model.header().at(col)) + FONT_WIDTH * 2;
- _view.setColumnWidth(col, columnSize);
-
- col = KsViewModel::TRACE_VIEW_COL_INDEX;
- rows = _model.rowCount({});
- columnSize = STRING_WIDTH(QString("%1").arg(rows)) + FONT_WIDTH;
- _view.setColumnWidth(col, columnSize);
}
//! @cond Doxygen_Suppress
diff --git a/src/KsTraceViewer.hpp b/src/KsTraceViewer.hpp
index 7cc5751..9815787 100644
--- a/src/KsTraceViewer.hpp
+++ b/src/KsTraceViewer.hpp
@@ -123,6 +123,8 @@ private:
KsTableView _view;
+ QPalette _viewPalette;
+
KsViewModel _model;
KsFilterProxyModel _proxyModel;
--
2.43.0
next prev parent reply other threads:[~2024-01-14 17:17 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-14 17:16 [PATCH 00/34] Fix kernelshark issues introduced by the migration to Qt6 Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 01/34] kernelshark: Fix modelReset() signaling, rename update to updateGeom Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 02/34] kernelshark: Add .gitignore Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 03/34] kernelshark: Remove function param when not used, whenever possible Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 04/34] kernelshark: Do not create a temporary container for looping over QMap Benjamin ROBIN
2024-01-21 17:16 ` Yordan Karadzhov
2024-01-28 21:30 ` Benjamin ROBIN
2024-02-04 18:34 ` Yordan Karadzhov
2024-02-04 18:59 ` Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 05/34] kernelshark: Prevent potential detach of QMap container Benjamin ROBIN
2024-01-21 17:17 ` Yordan Karadzhov
2024-01-28 19:38 ` [PATCH v2 " Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 06/34] kernelshark: Fix used after free of QByteArray raw data Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 07/34] kernelshark: Fix potential memory leak in KsGLWidget Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 08/34] kernelshark: Use lambda parameter instead of captured local variable Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 09/34] kernelshark: Keep overridden method protected instead of public Benjamin ROBIN
2024-01-14 17:16 ` [PATCH 10/34] kernelshark: Use sliced() or first() instead of mid/right/left() Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 11/34] kernelshark: Prevent potential divide by zero in Shape::center() Benjamin ROBIN
2024-01-21 19:49 ` Yordan Karadzhov
2024-01-28 19:26 ` [PATCH v2 " Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 12/34] kernelshark: Fix potential access to uninitialized variable Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 13/34] kernelshark: Remove unused locals variables Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 14/34] kernelshark: Fix range-loop-reference Clazy warning Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 15/34] kernelshark: Fix moving a temp object prevents copy elision warning Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 16/34] kernelshark: Add receiver object to connect() call Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 17/34] kernelshark: Return by reference the list of header in KsModels Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 18/34] kernelshark: Fix detaching-temporary Clazy warning Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 19/34] kernelshark: Fix qfileinfo-exists " Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 20/34] kernelshark: Fix potential memory leaks in libkshark-configio Benjamin ROBIN
2024-01-21 18:41 ` Yordan Karadzhov
2024-01-28 19:25 ` [PATCH v2 " Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 21/34] kernelshark: Fix potential access to uninitialized variable Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 22/34] kernelshark: Fix potential double free of histo->map, histo->bin_count Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 23/34] kernelshark: Fix 'const' type qualifier on return type has no effect Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 24/34] kernelshark: Fix potential memory leaks in libkshark-tepdata Benjamin ROBIN
2024-01-21 18:50 ` Yordan Karadzhov
2024-01-28 19:24 ` [PATCH v2 " Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 25/34] kernelshark: Fix typo in comment of KsGLWidget::resizeGL() Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 26/34] kernelshark: Remove unused KsDataWidget::wipPtr() and broken function Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 27/34] kernelshark: In KsTimeOffsetDialog() constructor use parent param Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 28/34] kernelshark: Fixed loop counter incremented suspiciously twice Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 29/34] kernelshark: Fix tepdata_dump_entry() for event_id = KS_EVENT_OVERFLOW Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 30/34] kernelshark: Use static_cast instead of C cast in KsMainWindow Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 31/34] kernelshark: Fix comparison of integers of different signs warnings Benjamin ROBIN
2024-01-21 19:09 ` Yordan Karadzhov
2024-01-14 17:17 ` Benjamin ROBIN [this message]
2024-01-14 17:17 ` [PATCH 33/34] kernelshark: Allow to reduce a bit more the graph height Benjamin ROBIN
2024-01-21 19:37 ` Yordan Karadzhov
2024-01-28 18:59 ` [PATCH v2 " Benjamin ROBIN
2024-01-14 17:17 ` [PATCH 34/34] kernelshark: Cleanup of KsDualMarker methods Benjamin ROBIN
2024-01-21 17:08 ` [PATCH 00/34] Fix kernelshark issues introduced by the migration to Qt6 Yordan Karadzhov
2024-03-03 9:56 ` Benjamin ROBIN
2024-03-03 15:47 ` Yordan Karadzhov
2024-03-03 17:07 ` Sudip Mukherjee
2024-03-03 20:43 ` Sudip Mukherjee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240114171723.14092-33-dev@benjarobin.fr \
--to=dev@benjarobin.fr \
--cc=linux-trace-devel@vger.kernel.org \
--cc=y.karadz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).