diff src/libqxt/qxtcsvmodel.cpp @ 81:5923d569167b

Make Header tooltips configurable
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 18 Jun 2015 17:48:28 +0200
parents 89997d853bf6
children
line wrap: on
line diff
--- a/src/libqxt/qxtcsvmodel.cpp	Tue Jun 16 16:08:05 2015 +0200
+++ b/src/libqxt/qxtcsvmodel.cpp	Thu Jun 18 17:48:28 2015 +0200
@@ -45,12 +45,13 @@
 class QxtCsvModelPrivate : public QxtPrivate<QxtCsvModel>
 {
 public:
-    QxtCsvModelPrivate() : csvData(), header(), maxColumn(0), quoteMode(QxtCsvModel::DefaultQuoteMode)
+    QxtCsvModelPrivate() : csvData(), header(), header_tt(), maxColumn(0), quoteMode(QxtCsvModel::DefaultQuoteMode)
     {}
     QXT_DECLARE_PUBLIC(QxtCsvModel)
 
     QList<QStringList> csvData;
     QStringList header;
+    QStringList header_tt;
     int maxColumn;
     QxtCsvModel::QuoteMode quoteMode;
 };
@@ -139,7 +140,9 @@
 {
     if(section < qxt_d().header.count() && orientation == Qt::Horizontal && (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole))
         return qxt_d().header[section];
-    else
+    else if (section < qxt_d().header_tt.count() && role == Qt::ToolTipRole) {
+        return qxt_d().header_tt[section];
+    } else
         return QAbstractTableModel::headerData(section, orientation, role);
 }
 
@@ -267,12 +270,21 @@
   */
 bool QxtCsvModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role)
 {
-    if(orientation != Qt::Horizontal) return false;                   // We don't support the vertical header
-    if(role != Qt::DisplayRole && role != Qt::EditRole) return false; // We don't support any other roles
     if(section < 0) return false;                                     // Bogus input
     while(section > qxt_d().header.size()) {
         qxt_d().header << QString();
     }
+    while(section >= qxt_d().header_tt.size()) {
+        qxt_d().header_tt << QString();
+    }
+    qDebug() << "Sect " << section  << " size " << qxt_d().header_tt.size();
+    if(orientation != Qt::Horizontal) return false;                   // We don't support the vertical header
+    if(role == Qt::ToolTipRole) {
+        qxt_d().header_tt[section] = value.toString();
+        emit headerDataChanged(Qt::Horizontal, section, section);
+        return true;
+    }
+    if(role != Qt::DisplayRole && role != Qt::EditRole) return false; // We don't support any other roles
     qxt_d().header[section] = value.toString();
     emit headerDataChanged(Qt::Horizontal, section, section);
     return true;
@@ -369,8 +381,10 @@
             row.insert(col, QString());
         }
     }
-    for(int i = 0; i < count ;i++)
+    for(int i = 0; i < count ;i++) {
         d_ptr.header.insert(col, QString());
+        d_ptr.header_tt.insert(col, QString());
+    }
     d_ptr.maxColumn += count;
     endInsertColumns();
     return true;
@@ -400,8 +414,10 @@
             d_ptr.csvData[i].removeAt(col);
         }
     }
-    for(int i = 0; i < count; i++)
+    for(int i = 0; i < count; i++) {
         d_ptr.header.removeAt(col);
+        d_ptr.header_tt.removeAt(col);
+    }
     emit endRemoveColumns();
     return true;
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)