Refactor CenterAlignSqlTableModel.
This commit is contained in:
@@ -3,3 +3,17 @@
|
||||
//
|
||||
|
||||
#include "CenterAlignSqlTableModel.h"
|
||||
QVariant CenterAlignSqlTableModel::data(const QModelIndex &index, int role) const {
|
||||
if (index.column() > 0 && role == Qt::TextAlignmentRole) {
|
||||
return Qt::AlignCenter;
|
||||
}
|
||||
if (index.column() > 0 && role == Qt::DisplayRole) {
|
||||
auto val = QSqlTableModel::data(index, role).toString();
|
||||
QStringList list = val.split("\n");
|
||||
if (list.size() > 1)
|
||||
return QString("%1...").arg(list[0].left(list[0].length() < 20 ? list[0].length() : 20));
|
||||
return val;
|
||||
} else {
|
||||
return QSqlTableModel::data(index, role);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user