Small patch for kdf to improve the usability

Wearenotalone wearenotalone at freenet.de
Wed Dec 23 19:14:36 CET 2009


Hi there,
at the moment kdf remembers only the hidden columns. The sortorder of
the rows and the columns is lost after each close. The following small
patch saves this information of the QTreeView header:

--- kdfwidget.cpp       (revision 1065512)
+++ kdfwidget.cpp       (working copy)
@@ -162,6 +162,17 @@
             if( !m_listWidget->isColumnHidden( c.number ) )
                 config.writeEntry( c.name,
m_listWidget->columnWidth(c.number) );
         }
+
+        config.writeEntry("SortColumn", m_sortModel->sortColumn());
+        config.writeEntry("SortOrder", (int)m_sortModel->sortOrder());
+
+        //Save the sort order of the QTreeView Header
+        QHeaderView * header = m_listWidget->header();
+        QList<int> sectionIndices;
+        for (int i = 0; i < header->count(); i++) {
+            sectionIndices.append(header->visualIndex(i));
+        }
+        config.writeEntry("HeaderSectionIndices", sectionIndices);
     }
     config.sync();
     updateDF();
@@ -189,6 +200,24 @@
             m_listWidget->setColumnHidden( c.number, !visible );
         }

+        int sortColumn = config.readEntry("SortColumn",0);
+        int sortOrder =
config.readEntry("SortOrder",(int)Qt::AscendingOrder);
+        m_listWidget->sortByColumn(sortColumn,Qt::SortOrder(sortOrder));
+
+        //Load the sort order of the QTreeView Header
+        //This can also be achieved by header->saveState() and
header->restoreState(...),
+        //but this would not be "human-readable" any more...
+        QHeaderView * header = m_listWidget->header();
+        QList<int> sectionIndices;
+        sectionIndices =
config.readEntry("HeaderSectionIndices",sectionIndices);
+        if (sectionIndices.count() == header->count()) {
+            for (int i = 0; i < header->count(); i++) {
+                int sectionIndex = sectionIndices.at(i);
+                int oldVisualIndex = header->visualIndex(sectionIndex);
+                header->moveSection(oldVisualIndex,i);
+            }
+        }
+
         setUpdateFrequency( mStd.updateFrequency() );
         updateDF();
     }

Unfortunately, I do not know where to send this patch, except to this
mailing list. Therefore, it would be nice if someone could review and
possibly commit this patch.

Sincerely,
WANA


More information about the Kde-utils-devel mailing list