comparison 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
comparison
equal deleted inserted replaced
80:d6f3a31e505e 81:5923d569167b
43 #include <QDebug> 43 #include <QDebug>
44 44
45 class QxtCsvModelPrivate : public QxtPrivate<QxtCsvModel> 45 class QxtCsvModelPrivate : public QxtPrivate<QxtCsvModel>
46 { 46 {
47 public: 47 public:
48 QxtCsvModelPrivate() : csvData(), header(), maxColumn(0), quoteMode(QxtCsvModel::DefaultQuoteMode) 48 QxtCsvModelPrivate() : csvData(), header(), header_tt(), maxColumn(0), quoteMode(QxtCsvModel::DefaultQuoteMode)
49 {} 49 {}
50 QXT_DECLARE_PUBLIC(QxtCsvModel) 50 QXT_DECLARE_PUBLIC(QxtCsvModel)
51 51
52 QList<QStringList> csvData; 52 QList<QStringList> csvData;
53 QStringList header; 53 QStringList header;
54 QStringList header_tt;
54 int maxColumn; 55 int maxColumn;
55 QxtCsvModel::QuoteMode quoteMode; 56 QxtCsvModel::QuoteMode quoteMode;
56 }; 57 };
57 58
58 /*! 59 /*!
137 */ 138 */
138 QVariant QxtCsvModel::headerData(int section, Qt::Orientation orientation, int role) const 139 QVariant QxtCsvModel::headerData(int section, Qt::Orientation orientation, int role) const
139 { 140 {
140 if(section < qxt_d().header.count() && orientation == Qt::Horizontal && (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole)) 141 if(section < qxt_d().header.count() && orientation == Qt::Horizontal && (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole))
141 return qxt_d().header[section]; 142 return qxt_d().header[section];
142 else 143 else if (section < qxt_d().header_tt.count() && role == Qt::ToolTipRole) {
144 return qxt_d().header_tt[section];
145 } else
143 return QAbstractTableModel::headerData(section, orientation, role); 146 return QAbstractTableModel::headerData(section, orientation, role);
144 } 147 }
145 148
146 /*! 149 /*!
147 \overload 150 \overload
265 /*! 268 /*!
266 \reimp 269 \reimp
267 */ 270 */
268 bool QxtCsvModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role) 271 bool QxtCsvModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role)
269 { 272 {
270 if(orientation != Qt::Horizontal) return false; // We don't support the vertical header
271 if(role != Qt::DisplayRole && role != Qt::EditRole) return false; // We don't support any other roles
272 if(section < 0) return false; // Bogus input 273 if(section < 0) return false; // Bogus input
273 while(section > qxt_d().header.size()) { 274 while(section > qxt_d().header.size()) {
274 qxt_d().header << QString(); 275 qxt_d().header << QString();
275 } 276 }
277 while(section >= qxt_d().header_tt.size()) {
278 qxt_d().header_tt << QString();
279 }
280 qDebug() << "Sect " << section << " size " << qxt_d().header_tt.size();
281 if(orientation != Qt::Horizontal) return false; // We don't support the vertical header
282 if(role == Qt::ToolTipRole) {
283 qxt_d().header_tt[section] = value.toString();
284 emit headerDataChanged(Qt::Horizontal, section, section);
285 return true;
286 }
287 if(role != Qt::DisplayRole && role != Qt::EditRole) return false; // We don't support any other roles
276 qxt_d().header[section] = value.toString(); 288 qxt_d().header[section] = value.toString();
277 emit headerDataChanged(Qt::Horizontal, section, section); 289 emit headerDataChanged(Qt::Horizontal, section, section);
278 return true; 290 return true;
279 } 291 }
280 292
367 while(col >= row.length()) row.append(QString()); 379 while(col >= row.length()) row.append(QString());
368 for(int j = 0; j < count; j++) { 380 for(int j = 0; j < count; j++) {
369 row.insert(col, QString()); 381 row.insert(col, QString());
370 } 382 }
371 } 383 }
372 for(int i = 0; i < count ;i++) 384 for(int i = 0; i < count ;i++) {
373 d_ptr.header.insert(col, QString()); 385 d_ptr.header.insert(col, QString());
386 d_ptr.header_tt.insert(col, QString());
387 }
374 d_ptr.maxColumn += count; 388 d_ptr.maxColumn += count;
375 endInsertColumns(); 389 endInsertColumns();
376 return true; 390 return true;
377 } 391 }
378 392
398 for(int i = 0; i < rowCount(); i++) { 412 for(int i = 0; i < rowCount(); i++) {
399 for(int j = 0; j < count; j++) { 413 for(int j = 0; j < count; j++) {
400 d_ptr.csvData[i].removeAt(col); 414 d_ptr.csvData[i].removeAt(col);
401 } 415 }
402 } 416 }
403 for(int i = 0; i < count; i++) 417 for(int i = 0; i < count; i++) {
404 d_ptr.header.removeAt(col); 418 d_ptr.header.removeAt(col);
419 d_ptr.header_tt.removeAt(col);
420 }
405 emit endRemoveColumns(); 421 emit endRemoveColumns();
406 return true; 422 return true;
407 } 423 }
408 424
409 static QString qxt_addCsvQuotes(QxtCsvModel::QuoteMode mode, QString field) 425 static QString qxt_addCsvQuotes(QxtCsvModel::QuoteMode mode, QString field)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)