diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-08 12:32:29 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-08 16:26:36 +0200 |
commit | f44850b5c3464cdda0ee9b1ee858d95f3ffaa3e2 (patch) | |
tree | 580aa25716bfc88d57f15ad68f7bfa727aebc400 /examples | |
parent | f955bd8ced8b93d142b7f755665946424c6d3644 (diff) | |
parent | 3622ebaac51abd2e4d1541120ae3b6e42932359f (diff) |
Merge "Merge remote-tracking branch 'origin/dev' into wip/qt6"
Diffstat (limited to 'examples')
-rw-r--r-- | examples/sql/books/initdb.h | 38 | ||||
-rw-r--r-- | examples/widgets/doc/src/stardelegate.qdoc | 2 | ||||
-rw-r--r-- | examples/widgets/widgets/styles/norwegianwoodstyle.cpp | 13 | ||||
-rw-r--r-- | examples/widgets/widgets/styles/norwegianwoodstyle.h | 2 |
4 files changed, 41 insertions, 14 deletions
diff --git a/examples/sql/books/initdb.h b/examples/sql/books/initdb.h index 44f74f0c37..773e3fb74c 100644 --- a/examples/sql/books/initdb.h +++ b/examples/sql/books/initdb.h @@ -79,6 +79,32 @@ QVariant addAuthor(QSqlQuery &q, const QString &name, const QDate &birthdate) return q.lastInsertId(); } +const auto BOOKS_SQL = QLatin1String(R"( + create table books(id integer primary key, title varchar, author integer, + genre integer, year integer, rating integer) + )"); + +const auto AUTHORS_SQL = QLatin1String(R"( + create table authors(id integer primary key, name varchar, birthdate date) + )"); + +const auto GENRES_SQL = QLatin1String(R"( + create table genres(id integer primary key, name varchar) + )"); + +const auto INSERT_AUTHOR_SQL = QLatin1String(R"( + insert into authors(name, birthdate) values(?, ?) + )"); + +const auto INSERT_BOOK_SQL = QLatin1String(R"( + insert into books(title, year, author, genre, rating) + values(?, ?, ?, ?, ?) + )"); + +const auto INSERT_GENRE_SQL = QLatin1String(R"( + insert into genres(name) values(?) + )"); + QSqlError initDb() { QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); @@ -93,26 +119,26 @@ QSqlError initDb() return QSqlError(); QSqlQuery q; - if (!q.exec(QLatin1String("create table books(id integer primary key, title varchar, author integer, genre integer, year integer, rating integer)"))) + if (!q.exec(BOOKS_SQL)) return q.lastError(); - if (!q.exec(QLatin1String("create table authors(id integer primary key, name varchar, birthdate date)"))) + if (!q.exec(AUTHORS_SQL)) return q.lastError(); - if (!q.exec(QLatin1String("create table genres(id integer primary key, name varchar)"))) + if (!q.exec(GENRES_SQL)) return q.lastError(); - if (!q.prepare(QLatin1String("insert into authors(name, birthdate) values(?, ?)"))) + if (!q.prepare(INSERT_AUTHOR_SQL)) return q.lastError(); QVariant asimovId = addAuthor(q, QLatin1String("Isaac Asimov"), QDate(1920, 2, 1)); QVariant greeneId = addAuthor(q, QLatin1String("Graham Greene"), QDate(1904, 10, 2)); QVariant pratchettId = addAuthor(q, QLatin1String("Terry Pratchett"), QDate(1948, 4, 28)); - if (!q.prepare(QLatin1String("insert into genres(name) values(?)"))) + if (!q.prepare(INSERT_GENRE_SQL)) return q.lastError(); QVariant sfiction = addGenre(q, QLatin1String("Science Fiction")); QVariant fiction = addGenre(q, QLatin1String("Fiction")); QVariant fantasy = addGenre(q, QLatin1String("Fantasy")); - if (!q.prepare(QLatin1String("insert into books(title, year, author, genre, rating) values(?, ?, ?, ?, ?)"))) + if (!q.prepare(INSERT_BOOK_SQL)) return q.lastError(); addBook(q, QLatin1String("Foundation"), 1951, asimovId, sfiction, 3); addBook(q, QLatin1String("Foundation and Empire"), 1952, asimovId, sfiction, 4); diff --git a/examples/widgets/doc/src/stardelegate.qdoc b/examples/widgets/doc/src/stardelegate.qdoc index 0b91723a51..b33fa3550f 100644 --- a/examples/widgets/doc/src/stardelegate.qdoc +++ b/examples/widgets/doc/src/stardelegate.qdoc @@ -269,7 +269,7 @@ \codeline \snippet itemviews/stardelegate/main.cpp 4 - Notice the call to qVariantFromValue to convert a \c + Notice the call to QVariant::fromValue to convert a \c StarRating to a QVariant. \section1 Possible Extensions and Suggestions diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp index 1d7ef2637b..a178769bd8 100644 --- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp +++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp @@ -64,9 +64,9 @@ void NorwegianWoodStyle::polish(QPalette &palette) QColor beige(236, 182, 120); QColor slightlyOpaqueBlack(0, 0, 0, 63); - QPixmap backgroundImage(":/images/woodbackground.png"); - QPixmap buttonImage(":/images/woodbutton.png"); - QPixmap midImage = buttonImage; + QImage backgroundImage(":/images/woodbackground.png"); + QImage buttonImage(":/images/woodbutton.png"); + QImage midImage = buttonImage.convertToFormat(QImage::Format_RGB32); QPainter painter; painter.begin(&midImage); @@ -311,11 +311,12 @@ void NorwegianWoodStyle::drawControl(ControlElement element, //! [37] void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role, //! [37] //! [38] - const QPixmap &pixmap) + const QImage &image) { for (int i = 0; i < QPalette::NColorGroups; ++i) { - QColor color = palette.brush(QPalette::ColorGroup(i), role).color(); - palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap)); + QBrush brush(image); + brush.setColor(palette.brush(QPalette::ColorGroup(i), role).color()); + palette.setBrush(QPalette::ColorGroup(i), role, brush); } } //! [38] diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.h b/examples/widgets/widgets/styles/norwegianwoodstyle.h index c41d81d23a..5a1783eb4d 100644 --- a/examples/widgets/widgets/styles/norwegianwoodstyle.h +++ b/examples/widgets/widgets/styles/norwegianwoodstyle.h @@ -80,7 +80,7 @@ public: private: static void setTexture(QPalette &palette, QPalette::ColorRole role, - const QPixmap &pixmap); + const QImage &image); static QPainterPath roundRectPath(const QRect &rect); }; //! [0] |