Cleanup Itemviews examples
Cleanup the Itemviews examples - use nullptr instead 0 - use for loop instead foreach - include own header first - remove uselss includes Change-Id: I32e9f64356e42038707d063dcad977239ce1fe9e Reviewed-by: Luca Beldi <v.ronin@yahoo.it> Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com>
This commit is contained in:
parent
b8720e3e7a
commit
af84f12298
@ -48,10 +48,10 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "colorlisteditor.h"
|
#include "colorlisteditor.h"
|
||||||
|
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget)
|
ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget)
|
||||||
{
|
{
|
||||||
populateList();
|
populateList();
|
||||||
@ -65,16 +65,16 @@ QColor ColorListEditor::color() const
|
|||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
void ColorListEditor::setColor(QColor color)
|
void ColorListEditor::setColor(const QColor &color)
|
||||||
{
|
{
|
||||||
setCurrentIndex(findData(color, int(Qt::DecorationRole)));
|
setCurrentIndex(findData(color, Qt::DecorationRole));
|
||||||
}
|
}
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
void ColorListEditor::populateList()
|
void ColorListEditor::populateList()
|
||||||
{
|
{
|
||||||
QStringList colorNames = QColor::colorNames();
|
const QStringList colorNames = QColor::colorNames();
|
||||||
|
|
||||||
for (int i = 0; i < colorNames.size(); ++i) {
|
for (int i = 0; i < colorNames.size(); ++i) {
|
||||||
QColor color(colorNames[i]);
|
QColor color(colorNames[i]);
|
||||||
|
@ -65,11 +65,11 @@ class ColorListEditor : public QComboBox
|
|||||||
Q_PROPERTY(QColor color READ color WRITE setColor USER true)
|
Q_PROPERTY(QColor color READ color WRITE setColor USER true)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ColorListEditor(QWidget *widget = 0);
|
ColorListEditor(QWidget *widget = nullptr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QColor color() const;
|
QColor color() const;
|
||||||
void setColor(QColor c);
|
void setColor(const QColor &color);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void populateList();
|
void populateList();
|
||||||
|
@ -48,11 +48,11 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "colorlisteditor.h"
|
#include "colorlisteditor.h"
|
||||||
|
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
Window::Window()
|
Window::Window()
|
||||||
{
|
{
|
||||||
@ -71,19 +71,18 @@ Window::Window()
|
|||||||
|
|
||||||
void Window::createGUI()
|
void Window::createGUI()
|
||||||
{
|
{
|
||||||
QList<QPair<QString, QColor> > list;
|
const QVector<QPair<QString, QColor> > list =
|
||||||
list << QPair<QString, QColor>(tr("Alice"), QColor("aliceblue")) <<
|
{{ tr("Alice"), QColor("aliceblue") },
|
||||||
QPair<QString, QColor>(tr("Neptun"), QColor("aquamarine")) <<
|
{ tr("Neptun"), QColor("aquamarine") },
|
||||||
QPair<QString, QColor>(tr("Ferdinand"), QColor("springgreen"));
|
{ tr("Ferdinand"), QColor("springgreen") }};
|
||||||
|
|
||||||
QTableWidget *table = new QTableWidget(3, 2);
|
QTableWidget *table = new QTableWidget(3, 2);
|
||||||
table->setHorizontalHeaderLabels(QStringList() << tr("Name")
|
table->setHorizontalHeaderLabels({ tr("Name"), tr("Hair Color") });
|
||||||
<< tr("Hair Color"));
|
|
||||||
table->verticalHeader()->setVisible(false);
|
table->verticalHeader()->setVisible(false);
|
||||||
table->resize(150, 50);
|
table->resize(150, 50);
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
QPair<QString, QColor> pair = list.at(i);
|
const QPair<QString, QColor> &pair = list.at(i);
|
||||||
|
|
||||||
QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first);
|
QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first);
|
||||||
QTableWidgetItem *colorItem = new QTableWidgetItem;
|
QTableWidgetItem *colorItem = new QTableWidgetItem;
|
||||||
|
@ -52,13 +52,11 @@
|
|||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QImage>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QWidgetAction>
|
#include <QWidgetAction>
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
FilterWidget::FilterWidget(QWidget *parent)
|
FilterWidget::FilterWidget(QWidget *parent)
|
||||||
: QLineEdit(parent)
|
: QLineEdit(parent)
|
||||||
@ -127,7 +125,8 @@ QRegExp::PatternSyntax FilterWidget::patternSyntax() const
|
|||||||
|
|
||||||
void FilterWidget::setPatternSyntax(QRegExp::PatternSyntax s)
|
void FilterWidget::setPatternSyntax(QRegExp::PatternSyntax s)
|
||||||
{
|
{
|
||||||
foreach (QAction *a, m_patternGroup->actions()) {
|
const QList<QAction*> actions = m_patternGroup->actions();
|
||||||
|
for (QAction *a : actions) {
|
||||||
if (patternSyntaxFromAction(a) == s) {
|
if (patternSyntaxFromAction(a) == s) {
|
||||||
a->setChecked(true);
|
a->setChecked(true);
|
||||||
break;
|
break;
|
||||||
|
@ -67,7 +67,7 @@ class FilterWidget : public QLineEdit
|
|||||||
Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
|
Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
|
||||||
Q_PROPERTY(QRegExp::PatternSyntax patternSyntax READ patternSyntax WRITE setPatternSyntax)
|
Q_PROPERTY(QRegExp::PatternSyntax patternSyntax READ patternSyntax WRITE setPatternSyntax)
|
||||||
public:
|
public:
|
||||||
explicit FilterWidget(QWidget *parent = 0);
|
explicit FilterWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
Qt::CaseSensitivity caseSensitivity() const;
|
Qt::CaseSensitivity caseSensitivity() const;
|
||||||
void setCaseSensitivity(Qt::CaseSensitivity);
|
void setCaseSensitivity(Qt::CaseSensitivity);
|
||||||
|
@ -48,10 +48,10 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "mysortfilterproxymodel.h"
|
#include "mysortfilterproxymodel.h"
|
||||||
|
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
|
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
@ -77,7 +77,7 @@ void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
|
|||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
|
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
|
||||||
const QModelIndex &sourceParent) const
|
const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||||
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
|
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
|
||||||
|
@ -48,12 +48,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "mysortfilterproxymodel.h"
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "mysortfilterproxymodel.h"
|
||||||
#include "filterwidget.h"
|
#include "filterwidget.h"
|
||||||
|
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
Window::Window()
|
Window::Window()
|
||||||
{
|
{
|
||||||
@ -75,7 +75,7 @@ Window::Window()
|
|||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
filterWidget = new FilterWidget;
|
filterWidget = new FilterWidget;
|
||||||
filterWidget->setText("Grace|Sports");
|
filterWidget->setText(tr("Grace|Sports"));
|
||||||
connect(filterWidget, &FilterWidget::filterChanged, this, &Window::textFilterChanged);
|
connect(filterWidget, &FilterWidget::filterChanged, this, &Window::textFilterChanged);
|
||||||
|
|
||||||
filterPatternLabel = new QLabel(tr("&Filter pattern:"));
|
filterPatternLabel = new QLabel(tr("&Filter pattern:"));
|
||||||
@ -137,6 +137,11 @@ void Window::setSourceModel(QAbstractItemModel *model)
|
|||||||
{
|
{
|
||||||
proxyModel->setSourceModel(model);
|
proxyModel->setSourceModel(model);
|
||||||
sourceView->setModel(model);
|
sourceView->setModel(model);
|
||||||
|
|
||||||
|
for (int i = 0; i < proxyModel->columnCount(); ++i)
|
||||||
|
proxyView->resizeColumnToContents(i);
|
||||||
|
for (int i = 0; i < model->columnCount(); ++i)
|
||||||
|
sourceView->resizeColumnToContents(i);
|
||||||
}
|
}
|
||||||
//! [7]
|
//! [7]
|
||||||
|
|
||||||
|
@ -50,20 +50,18 @@
|
|||||||
|
|
||||||
#include "filelistmodel.h"
|
#include "filelistmodel.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QGuiApplication>
|
||||||
#include <QBrush>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
|
||||||
FileListModel::FileListModel(QObject *parent)
|
FileListModel::FileListModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent), fileCount(0)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
//![4]
|
//![4]
|
||||||
int FileListModel::rowCount(const QModelIndex & /* parent */) const
|
int FileListModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return fileCount;
|
return parent.isValid() ? 0 : fileCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FileListModel::data(const QModelIndex &index, int role) const
|
QVariant FileListModel::data(const QModelIndex &index, int role) const
|
||||||
@ -88,25 +86,26 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
|
|||||||
//![4]
|
//![4]
|
||||||
|
|
||||||
//![1]
|
//![1]
|
||||||
bool FileListModel::canFetchMore(const QModelIndex & /* index */) const
|
bool FileListModel::canFetchMore(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (fileCount < fileList.size())
|
if (parent.isValid())
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
|
return (fileCount < fileList.size());
|
||||||
}
|
}
|
||||||
//![1]
|
//![1]
|
||||||
|
|
||||||
//![2]
|
//![2]
|
||||||
void FileListModel::fetchMore(const QModelIndex & /* index */)
|
void FileListModel::fetchMore(const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
|
if (parent.isValid())
|
||||||
|
return;
|
||||||
int remainder = fileList.size() - fileCount;
|
int remainder = fileList.size() - fileCount;
|
||||||
int itemsToFetch = qMin(100, remainder);
|
int itemsToFetch = qMin(100, remainder);
|
||||||
|
|
||||||
if (itemsToFetch <= 0)
|
if (itemsToFetch <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1);
|
beginInsertRows(QModelIndex(), fileCount, fileCount + itemsToFetch - 1);
|
||||||
|
|
||||||
fileCount += itemsToFetch;
|
fileCount += itemsToFetch;
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
#define FILELISTMODEL_H
|
#define FILELISTMODEL_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
//![0]
|
//![0]
|
||||||
@ -61,7 +60,7 @@ class FileListModel : public QAbstractListModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileListModel(QObject *parent = 0);
|
FileListModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
@ -48,8 +48,8 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "filelistmodel.h"
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "filelistmodel.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ Window::Window(QWidget *parent)
|
|||||||
QListView *view = new QListView;
|
QListView *view = new QListView;
|
||||||
view->setModel(model);
|
view->setModel(model);
|
||||||
|
|
||||||
logViewer = new QTextBrowser;
|
logViewer = new QTextBrowser(this);
|
||||||
logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
|
logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
|
||||||
|
|
||||||
connect(lineEdit, &QLineEdit::textChanged,
|
connect(lineEdit, &QLineEdit::textChanged,
|
||||||
|
@ -62,7 +62,7 @@ class Window : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window(QWidget *parent = 0);
|
Window(QWidget *parent = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateLog(int number);
|
void updateLog(int number);
|
||||||
|
@ -50,14 +50,13 @@
|
|||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
Model::Model(int rows, int columns, QObject *parent)
|
Model::Model(int rows, int columns, QObject *parent)
|
||||||
: QAbstractItemModel(parent),
|
: QAbstractItemModel(parent),
|
||||||
services(QPixmap(":/images/services.png")),
|
services(QPixmap(":/images/services.png")),
|
||||||
rc(rows), cc(columns),
|
rc(rows), cc(columns),
|
||||||
tree(new QVector<Node>(rows, Node(0)))
|
tree(new QVector<Node>(rows, Node()))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class Model : public QAbstractItemModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Model(int rows, int columns, QObject *parent = 0);
|
Model(int rows, int columns, QObject *parent = nullptr);
|
||||||
~Model();
|
~Model();
|
||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
|
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
|
||||||
@ -80,7 +80,7 @@ private:
|
|||||||
|
|
||||||
struct Node
|
struct Node
|
||||||
{
|
{
|
||||||
Node(Node *parent = 0) : parent(parent), children(0) {}
|
Node(Node *parent = nullptr) : parent(parent), children(nullptr) {}
|
||||||
~Node() { delete children; }
|
~Node() { delete children; }
|
||||||
Node *parent;
|
Node *parent;
|
||||||
QVector<Node> *children;
|
QVector<Node> *children;
|
||||||
|
@ -48,8 +48,8 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "imagemodel.h"
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "imagemodel.h"
|
||||||
#include "pixeldelegate.h"
|
#include "pixeldelegate.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
@ -54,10 +54,8 @@
|
|||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
PixelDelegate::PixelDelegate(QObject *parent)
|
PixelDelegate::PixelDelegate(QObject *parent)
|
||||||
: QAbstractItemDelegate(parent)
|
: QAbstractItemDelegate(parent), pixelSize(12)
|
||||||
{
|
{}
|
||||||
pixelSize = 12;
|
|
||||||
}
|
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
@ -70,11 +68,11 @@ void PixelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
int size = qMin(option.rect.width(), option.rect.height());
|
const int size = qMin(option.rect.width(), option.rect.height());
|
||||||
//! [3] //! [4]
|
//! [3] //! [4]
|
||||||
int brightness = index.model()->data(index, Qt::DisplayRole).toInt();
|
const int brightness = index.model()->data(index, Qt::DisplayRole).toInt();
|
||||||
double radius = (size / 2.0) - (brightness / 255.0 * size / 2.0);
|
const double radius = (size / 2.0) - (brightness / 255.0 * size / 2.0);
|
||||||
if (radius == 0.0)
|
if (qFuzzyIsNull(radius))
|
||||||
return;
|
return;
|
||||||
//! [4]
|
//! [4]
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class QObject;
|
|||||||
class QPainter;
|
class QPainter;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
static const int ItemSize = 256;
|
static constexpr int ItemSize = 256;
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class PixelDelegate : public QAbstractItemDelegate
|
class PixelDelegate : public QAbstractItemDelegate
|
||||||
@ -69,13 +69,13 @@ class PixelDelegate : public QAbstractItemDelegate
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PixelDelegate(QObject *parent = 0);
|
PixelDelegate(QObject *parent = nullptr);
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const override;
|
const QModelIndex &index) const override;
|
||||||
|
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
QSize sizeHint(const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index ) const override;
|
const QModelIndex &index) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPixelSize(int size);
|
void setPixelSize(int size);
|
||||||
|
@ -134,7 +134,7 @@ QMimeData *PiecesModel::mimeData(const QModelIndexList &indexes) const
|
|||||||
|
|
||||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||||
|
|
||||||
foreach (QModelIndex index, indexes) {
|
for (const QModelIndex &index : indexes) {
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
QPixmap pixmap = qvariant_cast<QPixmap>(data(index, Qt::UserRole));
|
QPixmap pixmap = qvariant_cast<QPixmap>(data(index, Qt::UserRole));
|
||||||
QPoint location = data(index, Qt::UserRole+1).toPoint();
|
QPoint location = data(index, Qt::UserRole+1).toPoint();
|
||||||
@ -190,10 +190,7 @@ bool PiecesModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|||||||
|
|
||||||
int PiecesModel::rowCount(const QModelIndex &parent) const
|
int PiecesModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
return parent.isValid() ? 0 : pixmaps.size();
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return pixmaps.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::DropActions PiecesModel::supportedDropActions() const
|
Qt::DropActions PiecesModel::supportedDropActions() const
|
||||||
@ -201,7 +198,7 @@ Qt::DropActions PiecesModel::supportedDropActions() const
|
|||||||
return Qt::CopyAction | Qt::MoveAction;
|
return Qt::CopyAction | Qt::MoveAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PiecesModel::addPieces(const QPixmap& pixmap)
|
void PiecesModel::addPieces(const QPixmap &pixmap)
|
||||||
{
|
{
|
||||||
if (!pixmaps.isEmpty()) {
|
if (!pixmaps.isEmpty()) {
|
||||||
beginRemoveRows(QModelIndex(), 0, pixmaps.size() - 1);
|
beginRemoveRows(QModelIndex(), 0, pixmaps.size() - 1);
|
||||||
|
@ -52,10 +52,10 @@
|
|||||||
#define PIECESLIST_H
|
#define PIECESLIST_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QMimeData;
|
class QMimeData;
|
||||||
@ -66,7 +66,7 @@ class PiecesModel : public QAbstractListModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PiecesModel(int pieceSize, QObject *parent = 0);
|
explicit PiecesModel(int pieceSize, QObject *parent = nullptr);
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
@ -80,11 +80,11 @@ public:
|
|||||||
Qt::DropActions supportedDropActions() const override;
|
Qt::DropActions supportedDropActions() const override;
|
||||||
|
|
||||||
void addPiece(const QPixmap &pixmap, const QPoint &location);
|
void addPiece(const QPixmap &pixmap, const QPoint &location);
|
||||||
void addPieces(const QPixmap& pixmap);
|
void addPieces(const QPixmap &pixmap);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QPoint> locations;
|
QVector<QPoint> locations;
|
||||||
QList<QPixmap> pixmaps;
|
QVector<QPixmap> pixmaps;
|
||||||
|
|
||||||
int m_PieceSize;
|
int m_PieceSize;
|
||||||
};
|
};
|
||||||
|
@ -69,7 +69,7 @@ class Window : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window(QWidget *parent = 0);
|
Window(QWidget *parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateButtons(int row);
|
void updateButtons(int row);
|
||||||
|
@ -68,8 +68,8 @@ SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
|
|||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
|
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
|
||||||
const QStyleOptionViewItem &/* option */,
|
const QStyleOptionViewItem &/* option */,
|
||||||
const QModelIndex &/* index */) const
|
const QModelIndex &/* index */) const
|
||||||
{
|
{
|
||||||
QSpinBox *editor = new QSpinBox(parent);
|
QSpinBox *editor = new QSpinBox(parent);
|
||||||
editor->setFrame(false);
|
editor->setFrame(false);
|
||||||
@ -105,7 +105,8 @@ void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|||||||
|
|
||||||
//! [4]
|
//! [4]
|
||||||
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
|
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
|
||||||
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &/* index */) const
|
||||||
{
|
{
|
||||||
editor->setGeometry(option.rect);
|
editor->setGeometry(option.rect);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ class SpinBoxDelegate : public QStyledItemDelegate
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpinBoxDelegate(QObject *parent = 0);
|
SpinBoxDelegate(QObject *parent = nullptr);
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const override;
|
const QModelIndex &index) const override;
|
||||||
@ -68,8 +68,8 @@ public:
|
|||||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
const QModelIndex &index) const override;
|
const QModelIndex &index) const override;
|
||||||
|
|
||||||
void updateEditorGeometry(QWidget *editor,
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
|
||||||
const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
const QModelIndex &index) const override;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -49,10 +49,9 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets/QApplication>
|
#include <QApplication>
|
||||||
#include <QtWidgets/QHeaderView>
|
#include <QShortcut>
|
||||||
#include <QtWidgets/QShortcut>
|
#include <QTreeView>
|
||||||
#include <QtWidgets/QTreeView>
|
|
||||||
|
|
||||||
#include "storagemodel.h"
|
#include "storagemodel.h"
|
||||||
|
|
||||||
|
@ -53,14 +53,6 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <qmath.h>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
StorageModel::StorageModel(QObject *parent) :
|
|
||||||
QAbstractTableModel(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void StorageModel::refresh()
|
void StorageModel::refresh()
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ public:
|
|||||||
ColumnCount
|
ColumnCount
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit StorageModel(QObject *parent = nullptr);
|
using QAbstractTableModel::QAbstractTableModel;
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent) const override;
|
int columnCount(const QModelIndex &parent) const override;
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user