Bug 371800 - Automatically adjust the headers in the structures view (w/ patches)
Summary: Automatically adjust the headers in the structures view (w/ patches)
Status: ASSIGNED
Alias: None
Product: okteta
Classification: Applications
Component: Structures Tool (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR wishlist
Target Milestone: ---
Assignee: Alex Richardson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-28 20:40 UTC by Staffan Palmroos
Modified: 2019-06-11 21:07 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch: automatically adjust the width of the view headers (11.55 KB, patch)
2016-10-28 20:40 UTC, Staffan Palmroos
Details
Missing entry in the .kcfg file for the automatic width adjustment (1.10 KB, patch)
2016-11-02 21:27 UTC, Staffan Palmroos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Staffan Palmroos 2016-10-28 20:40:37 UTC
Created attachment 101866 [details]
patch: automatically adjust the width of the view headers

I've been using the structures tool quite a lot recently and one thing that has annoyed me is that I had to constantly adjust the width of the headers to see the information properly.

So I dug around a little bit and I managed to fix the problem myself. The QViewHeaders class has a mode for automatically adjust the headers so I added a checkbox to the Settings window to allow the user to switch between automatically adjusting the widths or doing it manually.

It's just a small problem, I couldn't figure out how to make the settings dialog window bigger so the checkbox is actually outside of view by default, you need to enlarge the window manually to see it. I'm sure someone better versed in Qt coding than me can figure out how to do this.

I'm attaching my patches to this report.
Comment 1 Alex Richardson 2016-10-29 01:19:30 UTC
I agree this is annoying. Initially I used QHeaderView::ResizeToContents but once you have a few hundred items it gets extremely slow (even if they aren't visible). It's quite possible that this issue has been fixed since I initially wrote the code so maybe I should adjust it to use that by default. I'm not sure we should add a setting for this, ideally the view should just do the right thing. I am currently travelling but I'll look into this once I'm back (in two weeks). Thank you very much for the patch!
Comment 2 Staffan Palmroos 2016-11-02 21:27:06 UTC
Created attachment 101985 [details]
Missing entry in the .kcfg file for the automatic width adjustment
Comment 3 Staffan Palmroos 2016-11-02 21:27:18 UTC
True, it might be unnecessary to have a setting for it. On the other hand, there might be a situation where some name or type string is very long or very indented pushing the value column very far to the right. It could then be annoying to not be able to make the other columns narrower.

Anyway, I forgot a small piece in the last patch apparently, the entry in the .kcfg file. I've attached a patch for it should you want to use it.
Comment 4 abraao80 2019-06-11 21:06:48 UTC
Comment on attachment 101866 [details]
patch: automatically adjust the width of the view headers

>From 4ec66687e337395aaf0f00198652719e4d9a3c80 Mon Sep 17 00:00:00 2001
>From: Staffan Palmroos <spalmroos@gmail.com>
>Date: Fri, 28 Oct 2016 23:37:27 +0300
>Subject: [PATCH] Give the user the option to have the structure view headers
> automatically adjust their widths
>
>---
> .../settings/structviewdisplaysettingswidget.ui    | 256 +++++++++++----------
> kasten/controllers/view/structures/structview.cpp  |  26 ++-
> kasten/controllers/view/structures/structview.h    |   1 +
> 3 files changed, 158 insertions(+), 125 deletions(-)
>
>diff --git a/kasten/controllers/view/structures/settings/structviewdisplaysettingswidget.ui b/kasten/controllers/view/structures/settings/structviewdisplaysettingswidget.ui
>index c290815..1085251 100644
>--- a/kasten/controllers/view/structures/settings/structviewdisplaysettingswidget.ui
>+++ b/kasten/controllers/view/structures/settings/structviewdisplaysettingswidget.ui
>@@ -6,135 +6,145 @@
>    <rect>
>     <x>0</x>
>     <y>0</y>
>-    <width>411</width>
>-    <height>292</height>
>+    <width>310</width>
>+    <height>421</height>
>    </rect>
>   </property>
>-  <layout class="QVBoxLayout" name="verticalLayout">
>-   <item>
>-    <layout class="QFormLayout" name="formLayout_2">
>-     <property name="fieldGrowthPolicy">
>-      <enum>QFormLayout::ExpandingFieldsGrow</enum>
>-     </property>
>-     <item row="0" column="0">
>-      <widget class="QLabel" name="byteOrderLabel">
>+  <widget class="QWidget" name="layoutWidget">
>+   <property name="geometry">
>+    <rect>
>+     <x>7</x>
>+     <y>7</y>
>+     <width>297</width>
>+     <height>407</height>
>+    </rect>
>+   </property>
>+   <layout class="QFormLayout" name="formLayout">
>+    <item row="0" column="0">
>+     <widget class="QLabel" name="byteOrderLabel">
>+      <property name="text">
>+       <string>Byte order:</string>
>+      </property>
>+      <property name="buddy">
>+       <cstring>kcfg_ByteOrder</cstring>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="0" column="1">
>+     <widget class="KComboBox" name="kcfg_ByteOrder">
>+      <property name="sizeAdjustPolicy">
>+       <enum>QComboBox::AdjustToContents</enum>
>+      </property>
>+      <item>
>        <property name="text">
>-        <string>Byte order:</string>
>+        <string>Big endian</string>
>        </property>
>-       <property name="buddy">
>-        <cstring>kcfg_ByteOrder</cstring>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="0" column="1">
>-      <widget class="KComboBox" name="kcfg_ByteOrder">
>-       <property name="sizeAdjustPolicy">
>-        <enum>QComboBox::AdjustToContents</enum>
>-       </property>
>-       <item>
>-        <property name="text">
>-         <string>Big endian</string>
>-        </property>
>-       </item>
>-       <item>
>-        <property name="text">
>-         <string>Little endian</string>
>-        </property>
>-       </item>
>-      </widget>
>-     </item>
>-     <item row="1" column="0" colspan="2">
>-      <widget class="QCheckBox" name="kcfg_ShortTypeNames">
>-       <property name="text">
>-        <string>Use short type names</string>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="2" column="0" colspan="2">
>-      <widget class="QCheckBox" name="kcfg_LocaleAwareDecimalFormatting">
>-       <property name="text">
>-        <string>Use locale-aware integer formatting</string>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="3" column="0">
>-      <widget class="QLabel" name="unsigned_label">
>-       <property name="text">
>-        <string>Unsigned values:</string>
>-       </property>
>-       <property name="buddy">
>-        <cstring>combo_UnsignedDisplayBase</cstring>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="3" column="1">
>-      <widget class="KComboBox" name="combo_UnsignedDisplayBase"/>
>-     </item>
>-     <item row="4" column="0">
>-      <widget class="QLabel" name="signed_label">
>-       <property name="text">
>-        <string>Signed values:</string>
>-       </property>
>-       <property name="buddy">
>-        <cstring>combo_SignedDisplayBase</cstring>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="4" column="1">
>-      <widget class="KComboBox" name="combo_SignedDisplayBase"/>
>-     </item>
>-     <item row="5" column="0" colspan="2">
>-      <widget class="QCheckBox" name="kcfg_LocaleAwareFloatFormatting">
>-       <property name="text">
>-        <string>Use locale-aware floating-point formatting</string>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="6" column="0">
>-      <widget class="QLabel" name="label">
>-       <property name="text">
>-        <string>Floating-point precision:</string>
>-       </property>
>-       <property name="buddy">
>-        <cstring>kcfg_FloatPrecision</cstring>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="6" column="1">
>-      <widget class="QSpinBox" name="kcfg_FloatPrecision"/>
>-     </item>
>-     <item row="7" column="0" colspan="2">
>-      <widget class="QCheckBox" name="kcfg_ShowCharNumericalValue">
>+      </item>
>+      <item>
>        <property name="text">
>-        <string>Show numerical value of chars</string>
>-       </property>
>-      </widget>
>-     </item>
>-     <item row="8" column="0">
>-      <widget class="QLabel" name="char_label">
>-       <property name="text">
>-        <string>Character value:</string>
>-       </property>
>-       <property name="buddy">
>-        <cstring>combo_CharDisplayBase</cstring>
>+        <string>Little endian</string>
>        </property>
>-      </widget>
>-     </item>
>-     <item row="8" column="1">
>-      <widget class="KComboBox" name="combo_CharDisplayBase"/>
>-     </item>
>-     <item row="9" column="0">
>-      <widget class="QSpinBox" name="kcfg_CharDisplayBase"/>
>-     </item>
>-     <item row="9" column="1">
>-      <widget class="QSpinBox" name="kcfg_SignedDisplayBase"/>
>-     </item>
>-     <item row="10" column="0">
>-      <widget class="QSpinBox" name="kcfg_UnsignedDisplayBase"/>
>-     </item>
>-    </layout>
>-   </item>
>-  </layout>
>+      </item>
>+     </widget>
>+    </item>
>+    <item row="1" column="0" colspan="2">
>+     <widget class="QCheckBox" name="kcfg_ShortTypeNames">
>+      <property name="text">
>+       <string>Use short type names</string>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="2" column="0" colspan="2">
>+     <widget class="QCheckBox" name="kcfg_LocaleAwareDecimalFormatting">
>+      <property name="text">
>+       <string>Use locale-aware integer formatting</string>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="3" column="0">
>+     <widget class="QLabel" name="unsigned_label">
>+      <property name="text">
>+       <string>Unsigned values:</string>
>+      </property>
>+      <property name="buddy">
>+       <cstring>combo_UnsignedDisplayBase</cstring>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="3" column="1">
>+     <widget class="KComboBox" name="combo_UnsignedDisplayBase"/>
>+    </item>
>+    <item row="4" column="0">
>+     <widget class="QLabel" name="signed_label">
>+      <property name="text">
>+       <string>Signed values:</string>
>+      </property>
>+      <property name="buddy">
>+       <cstring>combo_SignedDisplayBase</cstring>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="4" column="1">
>+     <widget class="KComboBox" name="combo_SignedDisplayBase"/>
>+    </item>
>+    <item row="5" column="0" colspan="2">
>+     <widget class="QCheckBox" name="kcfg_LocaleAwareFloatFormatting">
>+      <property name="text">
>+       <string>Use locale-aware floating-point formatting</string>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="6" column="0">
>+     <widget class="QLabel" name="label">
>+      <property name="text">
>+       <string>Floating-point precision:</string>
>+      </property>
>+      <property name="buddy">
>+       <cstring>kcfg_FloatPrecision</cstring>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="6" column="1">
>+     <widget class="QSpinBox" name="kcfg_FloatPrecision"/>
>+    </item>
>+    <item row="7" column="0" colspan="2">
>+     <widget class="QCheckBox" name="kcfg_ShowCharNumericalValue">
>+      <property name="text">
>+       <string>Show numerical value of chars</string>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="8" column="0">
>+     <widget class="QLabel" name="char_label">
>+      <property name="text">
>+       <string>Character value:</string>
>+      </property>
>+      <property name="buddy">
>+       <cstring>combo_CharDisplayBase</cstring>
>+      </property>
>+     </widget>
>+    </item>
>+    <item row="8" column="1">
>+     <widget class="KComboBox" name="combo_CharDisplayBase"/>
>+    </item>
>+    <item row="9" column="0">
>+     <widget class="QSpinBox" name="kcfg_CharDisplayBase"/>
>+    </item>
>+    <item row="9" column="1">
>+     <widget class="QSpinBox" name="kcfg_SignedDisplayBase"/>
>+    </item>
>+    <item row="10" column="0">
>+     <widget class="QSpinBox" name="kcfg_UnsignedDisplayBase"/>
>+    </item>
>+    <item row="11" column="0" colspan="2">
>+     <widget class="QCheckBox" name="kcfg_AutoAdjustHeaders">
>+      <property name="text">
>+       <string>Adjust header widths automatically</string>
>+      </property>
>+     </widget>
>+    </item>
>+   </layout>
>+  </widget>
>  </widget>
>  <customwidgets>
>   <customwidget>
>diff --git a/kasten/controllers/view/structures/structview.cpp b/kasten/controllers/view/structures/structview.cpp
>index df121dd..67da76a 100644
>--- a/kasten/controllers/view/structures/structview.cpp
>+++ b/kasten/controllers/view/structures/structview.cpp
>@@ -83,8 +83,14 @@ StructView::StructView(StructTool* tool, QWidget* parent) :
>     mStructTreeView->setSortingEnabled(false);
>     mStructTreeView->installEventFilter(this);
>     QHeaderView* header = mStructTreeView->header();
>-    header->setSectionResizeMode(QHeaderView::Interactive);
>-
>+    if (Kasten::StructViewPreferences::autoAdjustHeaders())
>+    {
>+        header->setSectionResizeMode(QHeaderView::ResizeToContents);
>+    }
>+    else
>+    {
>+        header->setSectionResizeMode(QHeaderView::Interactive);
>+    }
>     baseLayout->addWidget(mStructTreeView, 10);
> 
>     // settings
>@@ -166,12 +172,28 @@ void StructView::openSettingsDlg()
> 
>     //User edited the configuration - update your local copies of the configuration data
>     connect(dialog, &KConfigDialog::settingsChanged, mTool, &StructTool::setSelectedStructuresInView);
>+    connect(dialog, &KConfigDialog::settingsChanged, this, &StructView::setAutoAdjustHeaders);
> 
> #pragma message("TODO: kconfig_compiler signals work now, use those signals and not the generic KConfigDialog::settingsChanged")
>     dialog->setCurrentPage(displ);
>     dialog->show();
> }
> 
>+// Change the header resize policy of the structures view if the user changed the setting.
>+void StructView::setAutoAdjustHeaders()
>+{
>+    QHeaderView* header = mStructTreeView->header();
>+    if (Kasten::StructViewPreferences::autoAdjustHeaders())
>+    {
>+        header->setSectionResizeMode(QHeaderView::ResizeToContents);
>+    }
>+    else
>+    {
>+        header->setSectionResizeMode(QHeaderView::Interactive);
>+    }
>+}
>+
>+
> bool StructView::eventFilter(QObject* object, QEvent* event)
> {
>     if (object == mStructTreeView)
>diff --git a/kasten/controllers/view/structures/structview.h b/kasten/controllers/view/structures/structview.h
>index 404481e..a0bb28b 100644
>--- a/kasten/controllers/view/structures/structview.h
>+++ b/kasten/controllers/view/structures/structview.h
>@@ -75,6 +75,7 @@ protected Q_SLOTS:
>     void lockButtonToggled();
>     void setLockButtonState(bool structureLocked);
>     void onByteArrayModelChanged(Okteta::AbstractByteArrayModel* model);
>+    void setAutoAdjustHeaders();
> private:
>     void setLockButtonState(const QModelIndex& current);
> };
>-- 
>2.7.3
>