From ff348e0f1a361fe50d0b287a76fb5aeef17281de Mon Sep 17 00:00:00 2001 From: ballessay Date: Thu, 13 Apr 2017 17:04:30 +0200 Subject: [PATCH] Add new helper functions --- src/helpers.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/helpers.h | 10 ++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 1306b570..160d5d6f 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -4,10 +4,20 @@ #include #include #include +#include +#include +#include + + +static QAbstractItemView::ScrollMode scrollMode() +{ + const bool use_scrollperpixel = true; + return use_scrollperpixel ? QAbstractItemView::ScrollPerPixel : QAbstractItemView::ScrollPerItem; +} + namespace qhelpers { - // TODO: wouldn't it be enough to setFont on the QWidget? void normalizeFont(QPlainTextEdit *edit) @@ -34,4 +44,37 @@ namespace qhelpers return QFileInfo(filename).fileName() + "_" + fullHash.toHex().left(10); } + void adjustColumns(QTreeWidget *tw) + { + int count = tw->columnCount(); + for (int i = 0; i != count; ++i) + { + tw->resizeColumnToContents(i); + } + } + + void appendRow(QTreeWidget *tw, const QString &str, const QString &str2, + const QString &str3, const QString &str4, const QString &str5) + { + QTreeWidgetItem *tempItem = new QTreeWidgetItem(); + // Fill dummy hidden column + tempItem->setText(0, "0"); + tempItem->setText(1, str); + if (!str2.isNull()) + tempItem->setText(2, str2); + if (!str3.isNull()) + tempItem->setText(3, str3); + if (!str4.isNull()) + tempItem->setText(4, str4); + if (!str5.isNull()) + tempItem->setText(5, str5); + + tw->insertTopLevelItem(0, tempItem); + } + + void setVerticalScrollMode(QTreeWidget *tw) + { + tw->setVerticalScrollMode(scrollMode()); + } + } // end namespace diff --git a/src/helpers.h b/src/helpers.h index 47c80579..5933694a 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -1,9 +1,12 @@ #ifndef QHELPERS_H #define QHELPERS_H +#include + class QPlainTextEdit; class QTextEdit; class QString; +class QTreeWidget; namespace qhelpers { @@ -11,6 +14,13 @@ namespace qhelpers void normalizeEditFont(QTextEdit *edit); QString uniqueProjectName(const QString &filename); + + void adjustColumns(QTreeWidget *tw); + + void appendRow(QTreeWidget *tw, const QString &str, const QString &str2 = QString(), + const QString &str3 = QString(), const QString &str4 = QString(), const QString &str5 = QString()); + + void setVerticalScrollMode(QTreeWidget* tw); } #endif // HELPERS_H