Examples should show idiomatic use of Qt and C++, so mark the custom widget constructors in this example as explicit and their destructors are override. Amends 2690822428deec4f0c08f4d118d69a7c6036369e, which, however, inherited the missing explicit from older code. Pick-to: 6.8 Change-Id: I5b5b49f69330c6f139345bed7264c85a36c36e9b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit e0e9a5627376e04aba1b2ca2591554851d7de240) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
72 lines
1.5 KiB
C++
72 lines
1.5 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
#ifndef BROWSER_H
|
|
#define BROWSER_H
|
|
|
|
#include <QWidget>
|
|
#include <QSqlTableModel>
|
|
|
|
#include <memory>
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QSqlError)
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
namespace Ui
|
|
{
|
|
class Browser;
|
|
}
|
|
QT_END_NAMESPACE
|
|
|
|
class Browser : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit Browser(QWidget *parent = nullptr);
|
|
~Browser() override;
|
|
|
|
QSqlError addConnection(const QString &driver, const QString &dbName, const QString &host,
|
|
const QString &user, const QString &passwd, int port);
|
|
|
|
public slots:
|
|
void openNewConnectionDialog();
|
|
void about();
|
|
|
|
protected:
|
|
void insertRow();
|
|
void deleteRow();
|
|
void updateActions();
|
|
|
|
protected slots:
|
|
void exec();
|
|
void showTable(const QString &table);
|
|
void showMetaData(const QString &table);
|
|
|
|
void onFieldStrategyAction();
|
|
void onRowStrategyAction();
|
|
void onManualStrategyAction();
|
|
void onSubmitButton();
|
|
void onClearButton();
|
|
|
|
signals:
|
|
void statusMessage(const QString &message);
|
|
|
|
private:
|
|
const std::unique_ptr<Ui::Browser> m_ui;
|
|
};
|
|
|
|
class CustomModel : public QSqlTableModel
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
using QSqlTableModel::QSqlTableModel;
|
|
QVariant data(const QModelIndex &idx, int role) const override
|
|
{
|
|
if (role == Qt::BackgroundRole && isDirty(idx))
|
|
return QBrush(QColor(Qt::yellow));
|
|
return QSqlTableModel::data(idx, role);
|
|
}
|
|
};
|
|
|
|
#endif
|