From 4f3e8f92c1e5e98651d4d6ee9a91cb3a9f53ffb8 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Wed, 8 Jan 2014 14:56:23 +0800 Subject: [PATCH] SheetModel: Add more data role support --- examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp | 43 +++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp b/examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp index 3605797..d2142c6 100644 --- a/examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp +++ b/examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp @@ -27,6 +27,8 @@ #include "xlsxsheetmodel_p.h" #include "xlsxworksheet.h" +#include + QT_BEGIN_NAMESPACE_XLSX SheetModelPrivate::SheetModelPrivate(SheetModel *p) @@ -99,6 +101,47 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const return cell->value(); } else if (role == Qt::EditRole) { return userFriendlyValue; + } else if (role == Qt::TextAlignmentRole) { + Qt::Alignment align; + switch (cell->format().horizontalAlignment()) { + case Format::AlignLeft: + align |= Qt::AlignLeft; + break; + case Format::AlignRight: + align |= Qt::AlignRight; + break; + case Format::AlignHCenter: + align |= Qt::AlignHCenter; + break; + case Format::AlignHJustify: + align |= Qt::AlignJustify; + break; + default: + break; + } + switch (cell->format().verticalAlignment()) { + case Format::AlignTop: + align |= Qt::AlignTop; + break; + case Format::AlignBottom: + align |= Qt::AlignBottom; + break; + case Format::AlignVCenter: + align |= Qt::AlignVCenter; + break; + default: + break; + } + return QVariant(align); + } else if (role == Qt::FontRole) { + if (cell->format().hasFontData()) + return cell->format().font(); + } else if (role == Qt::ForegroundRole) { + if (cell->format().fontColor().isValid()) + return QBrush(cell->format().fontColor()); + } else if (role == Qt::BackgroundRole) { + if (cell->format().patternBackgroundColor().isValid()) + return QBrush(cell->format().patternBackgroundColor()); } return QVariant();