summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tutorials/modelview/2_formatting
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/tutorials/modelview/2_formatting')
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/main.cpp8
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp24
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/mymodel.h4
3 files changed, 13 insertions, 23 deletions
diff --git a/examples/widgets/tutorials/modelview/2_formatting/main.cpp b/examples/widgets/tutorials/modelview/2_formatting/main.cpp
index 80383f8c94..ea571d3699 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/main.cpp
+++ b/examples/widgets/tutorials/modelview/2_formatting/main.cpp
@@ -50,16 +50,16 @@
//! [Quoting ModelView Tutorial]
// main.cpp
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QTableView>
+#include <QApplication>
+#include <QTableView>
#include "mymodel.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableView tableView;
- MyModel myModel(0);
- tableView.setModel( &myModel );
+ MyModel myModel;
+ tableView.setModel(&myModel);
tableView.show();
return a.exec();
}
diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp
index 9511648392..938597a34e 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp
+++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp
@@ -48,13 +48,14 @@
**
****************************************************************************/
+#include "mymodel.h"
+
#include <QFont>
#include <QBrush>
-#include "mymodel.h"
#include <QDebug>
MyModel::MyModel(QObject *parent)
- :QAbstractTableModel(parent)
+ : QAbstractTableModel(parent)
{
}
@@ -78,7 +79,7 @@ QVariant MyModel::data(const QModelIndex &index, int role) const
qDebug() << QString("row %1, col%2, role %3")
.arg(row).arg(col).arg(role);
- switch(role){
+ switch (role) {
case Qt::DisplayRole:
if (row == 0 && col == 1) return QString("<--left");
if (row == 1 && col == 1) return QString("right-->");
@@ -86,36 +87,25 @@ QVariant MyModel::data(const QModelIndex &index, int role) const
return QString("Row%1, Column%2")
.arg(row + 1)
.arg(col +1);
- break;
case Qt::FontRole:
- if (row == 0 && col == 0) //change font only for cell(0,0)
- {
+ if (row == 0 && col == 0) { //change font only for cell(0,0)
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
break;
case Qt::BackgroundRole:
-
if (row == 1 && col == 2) //change background only for cell(1,2)
- {
- QBrush redBackground(Qt::red);
- return redBackground;
- }
+ return QBrush(Qt::red);
break;
case Qt::TextAlignmentRole:
-
if (row == 1 && col == 1) //change text alignment only for cell(1,1)
- {
return Qt::AlignRight + Qt::AlignVCenter;
- }
break;
case Qt::CheckStateRole:
-
if (row == 1 && col == 0) //add a checkbox to cell(1,0)
- {
return Qt::Checked;
- }
+ break;
}
return QVariant();
}
diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
index 9c12f98ba9..e8ae673f62 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
+++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h
@@ -57,8 +57,8 @@ class MyModel : public QAbstractTableModel
{
Q_OBJECT
public:
- MyModel(QObject *parent);
- int rowCount(const QModelIndex &parent = QModelIndex()) const override ;
+ MyModel(QObject *parent = nullptr);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
};