summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre de la Rocha <andre.rocha@qt.io>2017-08-21 13:23:48 +0200
committerAndre de la Rocha <andre.rocha@qt.io>2017-08-23 11:01:43 +0000
commitc2751b1d664748cfbd05d2e397f95f2cc0bec13f (patch)
tree6a7a884caf28250927ee66f395e0634470ac0851
parentb3e88744f36144db7cda0b85c161cdb10026eb65 (diff)
downloadqtactiveqt-c2751b1d664748cfbd05d2e397f95f2cc0bec13f.tar.gz
Active Qt Examples: Brush up to C++ 11
Use nullptr, member initialization, new connect syntax, QStringLiteral, etc. Change-Id: Ia79473ca302216f91eec6a32f670cf606761ed0d Reviewed-by: Michael Winkelmann <michael.winkelmann@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--examples/activeqt/comapp/main.cpp83
-rw-r--r--examples/activeqt/hierarchy/objects.cpp16
-rw-r--r--examples/activeqt/hierarchy/objects.h18
-rw-r--r--examples/activeqt/menus/main.cpp11
-rw-r--r--examples/activeqt/menus/menus.cpp54
-rw-r--r--examples/activeqt/menus/menus.h4
-rw-r--r--examples/activeqt/multiple/ax1.h13
-rw-r--r--examples/activeqt/multiple/ax2.h27
-rw-r--r--examples/activeqt/opengl/glbox.cpp103
-rw-r--r--examples/activeqt/opengl/glbox.h26
-rw-r--r--examples/activeqt/opengl/globjwin.cpp57
-rw-r--r--examples/activeqt/opengl/globjwin.h2
-rw-r--r--examples/activeqt/opengl/main.cpp11
-rw-r--r--examples/activeqt/qutlook/addressview.cpp121
-rw-r--r--examples/activeqt/qutlook/addressview.h12
-rw-r--r--examples/activeqt/qutlook/main.cpp4
-rw-r--r--examples/activeqt/simple/main.cpp66
-rw-r--r--examples/activeqt/simpleqml/main.cpp18
-rw-r--r--examples/activeqt/webbrowser/main.cpp93
-rw-r--r--examples/activeqt/webbrowser/webaxwidget.h5
-rw-r--r--examples/activeqt/wrapper/main.cpp169
21 files changed, 450 insertions, 463 deletions
diff --git a/examples/activeqt/comapp/main.cpp b/examples/activeqt/comapp/main.cpp
index 8e49d0e..cfe0586 100644
--- a/examples/activeqt/comapp/main.cpp
+++ b/examples/activeqt/comapp/main.cpp
@@ -41,6 +41,7 @@
#include <QApplication>
#include <QAxFactory>
#include <QTabWidget>
+#include <QScopedPointer>
#include <QTimer>
class Application;
@@ -58,8 +59,8 @@ class Document : public QObject
Q_PROPERTY(QString title READ title WRITE setTitle)
public:
- Document(DocumentList *list);
- ~Document();
+ explicit Document(DocumentList *list);
+ virtual ~Document();
Application *application() const;
@@ -67,7 +68,7 @@ public:
void setTitle(const QString &title);
private:
- QWidget *page;
+ QScopedPointer <QWidget> m_page;
};
//! [0]
@@ -83,7 +84,7 @@ class DocumentList : public QObject
Q_PROPERTY(int count READ count)
public:
- DocumentList(Application *application);
+ explicit DocumentList(Application *application);
int count() const;
Application *application() const;
@@ -93,7 +94,7 @@ public slots:
Document *item(int index) const;
private:
- QList<Document*> list;
+ QList<Document *> m_list;
};
//! [1]
@@ -111,7 +112,7 @@ class Application : public QObject
Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
public:
- Application(QObject *parent = 0);
+ explicit Application(QObject *parent = nullptr);
DocumentList *documents() const;
QString id() const { return objectName(); }
@@ -119,15 +120,14 @@ public:
void setVisible(bool on);
bool isVisible() const;
- QTabWidget *window() const { return ui; }
+ QTabWidget *window() const { return m_ui.data(); }
public slots:
void quit();
private:
- DocumentList *docs;
-
- QTabWidget *ui;
+ QScopedPointer <DocumentList> m_docs;
+ QScopedPointer <QTabWidget> m_ui;
};
//! [2]
@@ -136,35 +136,34 @@ Document::Document(DocumentList *list)
: QObject(list)
{
QTabWidget *tabs = list->application()->window();
- page = new QWidget(tabs);
- page->setWindowTitle("Unnamed");
- tabs->addTab(page, page->windowTitle());
+ m_page.reset(new QWidget(tabs));
+ m_page->setWindowTitle(tr("Unnamed"));
+ tabs->addTab(m_page.data(), m_page->windowTitle());
- page->show();
+ m_page->show();
}
Document::~Document()
{
- delete page;
}
Application *Document::application() const
{
- return qobject_cast<DocumentList*>(parent())->application();
+ return qobject_cast<DocumentList *>(parent())->application();
}
QString Document::title() const
{
- return page->windowTitle();
+ return m_page->windowTitle();
}
void Document::setTitle(const QString &t)
{
- page->setWindowTitle(t);
+ m_page->setWindowTitle(t);
QTabWidget *tabs = application()->window();
- int index = tabs->indexOf(page);
- tabs->setTabText(index, page->windowTitle());
+ int index = tabs->indexOf(m_page.data());
+ tabs->setTabText(index, m_page->windowTitle());
}
//! [3] //! [4]
@@ -175,64 +174,56 @@ DocumentList::DocumentList(Application *application)
Application *DocumentList::application() const
{
- return qobject_cast<Application*>(parent());
+ return qobject_cast<Application *>(parent());
}
int DocumentList::count() const
{
- return list.count();
+ return m_list.count();
}
Document *DocumentList::item(int index) const
{
- if (index >= list.count())
- return 0;
-
- return list.at(index);
+ return m_list.value(index, nullptr);
}
Document *DocumentList::addDocument()
{
Document *document = new Document(this);
- list.append(document);
+ m_list.append(document);
return document;
}
-
//! [4] //! [5]
Application::Application(QObject *parent)
-: QObject(parent), ui(0)
+: QObject(parent),
+ m_ui(new QTabWidget),
+ m_docs(new DocumentList(this))
{
- ui = new QTabWidget;
-
- setObjectName("From QAxFactory");
- docs = new DocumentList(this);
+ setObjectName(QStringLiteral("From QAxFactory"));
}
DocumentList *Application::documents() const
{
- return docs;
+ return m_docs.data();
}
void Application::setVisible(bool on)
{
- ui->setVisible(on);
+ m_ui->setVisible(on);
}
bool Application::isVisible() const
{
- return ui->isVisible();
+ return m_ui->isVisible();
}
void Application::quit()
{
- delete docs;
- docs = 0;
-
- delete ui;
- ui = 0;
- QTimer::singleShot(0, qApp, SLOT(quit()));
+ m_docs.reset();
+ m_ui.reset();
+ QTimer::singleShot(0 /*ms*/, qApp, &QCoreApplication::quit);
}
#include "main.moc"
@@ -246,8 +237,9 @@ QAXFACTORY_BEGIN("{edd3e836-f537-4c6f-be7d-6014c155cc7a}", "{b7da3de8-83bb-4bbe-
QAXFACTORY_END()
//! [6] //! [7]
-int main(int argc, char **argv)
+int main(int argc, char *argv[])
{
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
@@ -256,12 +248,13 @@ int main(int argc, char **argv)
return app.exec();
// started by user
- Application appobject(0);
- appobject.setObjectName("From Application");
+ Application appobject;
+ appobject.setObjectName(QStringLiteral("From Application"));
QAxFactory::startServer();
QAxFactory::registerActiveObject(&appobject);
+ appobject.window()->setMinimumSize(300, 100);
appobject.setVisible(true);
QObject::connect(&app, &QGuiApplication::lastWindowClosed, &appobject, &Application::quit);
diff --git a/examples/activeqt/hierarchy/objects.cpp b/examples/activeqt/hierarchy/objects.cpp
index 1cb59ae..c0d0f0d 100644
--- a/examples/activeqt/hierarchy/objects.cpp
+++ b/examples/activeqt/hierarchy/objects.cpp
@@ -45,16 +45,16 @@
/* Implementation of QParentWidget */
//! [0]
QParentWidget::QParentWidget(QWidget *parent)
-: QWidget(parent)
+: QWidget(parent),
+ m_vbox(new QVBoxLayout(this))
{
- vbox = new QVBoxLayout(this);
}
//! [0] //! [1]
void QParentWidget::createSubWidget(const QString &name)
{
QSubWidget *sw = new QSubWidget(this, name);
- vbox->addWidget(sw);
+ m_vbox->addWidget(sw);
sw->setLabel(name);
sw->show();
}
@@ -62,7 +62,7 @@ void QParentWidget::createSubWidget(const QString &name)
//! [1] //! [2]
QSubWidget *QParentWidget::subWidget(const QString &name)
{
- return findChild<QSubWidget*>(name);
+ return findChild<QSubWidget *>(name);
}
//! [2]
@@ -81,27 +81,27 @@ QSubWidget::QSubWidget(QWidget *parent, const QString &name)
void QSubWidget::setLabel(const QString &text)
{
- lbl = text;
+ m_label = text;
setObjectName(text);
update();
}
QString QSubWidget::label() const
{
- return lbl;
+ return m_label;
}
QSize QSubWidget::sizeHint() const
{
QFontMetrics fm(font());
- return QSize(fm.width(lbl), fm.height());
+ return QSize(fm.width(m_label), fm.height());
}
void QSubWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(palette().text().color());
- painter.drawText(rect(), Qt::AlignCenter, lbl);
+ painter.drawText(rect(), Qt::AlignCenter, m_label);
//! [3] //! [4]
}
//! [4]
diff --git a/examples/activeqt/hierarchy/objects.h b/examples/activeqt/hierarchy/objects.h
index 4ceea1f..49b1535 100644
--- a/examples/activeqt/hierarchy/objects.h
+++ b/examples/activeqt/hierarchy/objects.h
@@ -56,17 +56,17 @@ class QParentWidget : public QWidget
Q_CLASSINFO("InterfaceID", "{4a30719d-d9c2-4659-9d16-67378209f822}");
Q_CLASSINFO("EventsID", "{4a30719d-d9c2-4659-9d16-67378209f823}");
public:
- QParentWidget(QWidget *parent = 0);
+ explicit QParentWidget(QWidget *parent = nullptr);
QSize sizeHint() const;
public slots:
- void createSubWidget( const QString &name );
+ void createSubWidget(const QString &name);
- QSubWidget *subWidget( const QString &name );
+ QSubWidget *subWidget(const QString &name);
private:
- QVBoxLayout *vbox;
+ QVBoxLayout *m_vbox;
};
//! [0]
@@ -74,25 +74,25 @@ private:
class QSubWidget : public QWidget
{
Q_OBJECT
- Q_PROPERTY( QString label READ label WRITE setLabel )
+ Q_PROPERTY(QString label READ label WRITE setLabel)
Q_CLASSINFO("ClassID", "{850652f4-8f71-4f69-b745-bce241ccdc30}");
Q_CLASSINFO("InterfaceID", "{2d76cc2f-3488-417a-83d6-debff88b3c3f}");
Q_CLASSINFO("ToSuperClass", "QSubWidget");
public:
- QSubWidget(QWidget *parent = 0, const QString &name = QString());
+ QSubWidget(QWidget *parent = nullptr, const QString &name = QString());
- void setLabel( const QString &text );
+ void setLabel(const QString &text);
QString label() const;
QSize sizeHint() const;
protected:
- void paintEvent( QPaintEvent *e );
+ void paintEvent(QPaintEvent *e);
private:
- QString lbl;
+ QString m_label;
};
//! [1]
diff --git a/examples/activeqt/menus/main.cpp b/examples/activeqt/menus/main.cpp
index 0a4867c..12342cf 100644
--- a/examples/activeqt/menus/main.cpp
+++ b/examples/activeqt/menus/main.cpp
@@ -41,6 +41,7 @@
#include "menus.h"
#include <QApplication>
#include <QAxFactory>
+#include <QScopedPointer>
QAXFACTORY_BEGIN(
"{ce947ee3-0403-4fdc-895a-4fe779394b46}", // type library ID
@@ -48,13 +49,13 @@ QAXFACTORY_BEGIN(
QAXCLASS(QMenus)
QAXFACTORY_END()
-int main( int argc, char **argv )
+int main(int argc, char *argv[])
{
- QApplication a( argc, argv );
+ QApplication a(argc, argv);
+ QScopedPointer<QWidget> window;
- QWidget *window = 0;
- if ( !QAxFactory::isServer() ) {
- window = new QMenus();
+ if (!QAxFactory::isServer()) {
+ window.reset(new QMenus());
window->show();
}
diff --git a/examples/activeqt/menus/menus.cpp b/examples/activeqt/menus/menus.cpp
index 638bcd2..cde6291 100644
--- a/examples/activeqt/menus/menus.cpp
+++ b/examples/activeqt/menus/menus.cpp
@@ -56,52 +56,52 @@ QMenus::QMenus(QWidget *parent)
QMenu *file = new QMenu(this);
- action = new QAction(QPixmap((const char**)fileopen), "&Open", this);
+ action = new QAction(QPixmap((const char**)fileopen), tr("&Open"), this);
action->setShortcut(tr("CTRL+O"));
connect(action, &QAction::triggered, this, &QMenus::fileOpen);
file->addAction(action);
- action = new QAction(QPixmap((const char**)filesave),"&Save", this);
+ action = new QAction(QPixmap((const char**)filesave), tr("&Save"), this);
action->setShortcut(tr("CTRL+S"));
connect(action, &QAction::triggered, this, &QMenus::fileSave);
file->addAction(action);
QMenu *edit = new QMenu(this);
- action = new QAction("&Normal", this);
+ action = new QAction(tr("&Normal"), this);
action->setShortcut(tr("CTRL+N"));
- action->setToolTip("Normal");
- action->setStatusTip("Toggles Normal");
+ action->setToolTip(tr("Normal"));
+ action->setStatusTip(tr("Toggles Normal"));
action->setCheckable(true);
connect(action, &QAction::triggered, this, &QMenus::editNormal);
edit->addAction(action);
- action = new QAction("&Bold", this);
+ action = new QAction(tr("&Bold"), this);
action->setShortcut(tr("CTRL+B"));
action->setCheckable(true);
connect(action, &QAction::triggered, this, &QMenus::editBold);
edit->addAction(action);
- action = new QAction("&Underline", this);
+ action = new QAction(tr("&Underline"), this);
action->setShortcut(tr("CTRL+U"));
action->setCheckable(true);
connect(action, &QAction::triggered, this, &QMenus::editUnderline);
edit->addAction(action);
QMenu *advanced = new QMenu(this);
- action = new QAction("&Font...", this);
+ action = new QAction(tr("&Font..."), this);
connect(action, &QAction::triggered, this, &QMenus::editAdvancedFont);
advanced->addAction(action);
- action = new QAction("&Style...", this);
+ action = new QAction(tr("&Style..."), this);
connect(action, &QAction::triggered, this, &QMenus::editAdvancedStyle);
advanced->addAction(action);
- edit->addMenu(advanced)->setText("&Advanced");
+ edit->addMenu(advanced)->setText(tr("&Advanced"));
edit->addSeparator();
- action = new QAction("Una&vailable", this);
+ action = new QAction(tr("Una&vailable"), this);
action->setShortcut(tr("CTRL+V"));
action->setCheckable(true);
action->setEnabled(false);
@@ -110,65 +110,65 @@ QMenus::QMenus(QWidget *parent)
QMenu *help = new QMenu(this);
- action = new QAction("&About...", this);
+ action = new QAction(tr("&About..."), this);
action->setShortcut(tr("F1"));
connect(action, &QAction::triggered, this, &QMenus::helpAbout);
help->addAction(action);
- action = new QAction("&About Qt...", this);
+ action = new QAction(tr("&About Qt..."), this);
connect(action, &QAction::triggered, this, &QMenus::helpAboutQt);
help->addAction(action);
if (!QAxFactory::isServer())
- menuBar()->addMenu(file)->setText("&File");
- menuBar()->addMenu(edit)->setText("&Edit");
- menuBar()->addMenu(help)->setText("&Help");
+ menuBar()->addMenu(file)->setText(tr("&File"));
+ menuBar()->addMenu(edit)->setText(tr("&Edit"));
+ menuBar()->addMenu(help)->setText(tr("&Help"));
- editor = new QTextEdit(this);
- setCentralWidget(editor);
+ m_editor = new QTextEdit(this);
+ setCentralWidget(m_editor);
statusBar();
}
void QMenus::fileOpen()
{
- editor->append("File Open selected.");
+ m_editor->append(tr("File Open selected."));
}
void QMenus::fileSave()
{
- editor->append("File Save selected.");
+ m_editor->append(tr("File Save selected."));
}
void QMenus::editNormal()
{
- editor->append("Edit Normal selected.");
+ m_editor->append(tr("Edit Normal selected."));
}
void QMenus::editBold()
{
- editor->append("Edit Bold selected.");
+ m_editor->append(tr("Edit Bold selected."));
}
void QMenus::editUnderline()
{
- editor->append("Edit Underline selected.");
+ m_editor->append(tr("Edit Underline selected."));
}
void QMenus::editAdvancedFont()
{
- editor->append("Edit Advanced Font selected.");
+ m_editor->append(tr("Edit Advanced Font selected."));
}
void QMenus::editAdvancedStyle()
{
- editor->append("Edit Advanced Style selected.");
+ m_editor->append(tr("Edit Advanced Style selected."));
}
void QMenus::helpAbout()
{
- QMessageBox::about(this, "About QMenus",
- "This example implements an in-place ActiveX control with menus and status messages.");
+ QMessageBox::about(this, tr("About QMenus"),
+ tr("This example implements an in-place ActiveX control with menus and status messages."));
}
void QMenus::helpAboutQt()
diff --git a/examples/activeqt/menus/menus.h b/examples/activeqt/menus/menus.h
index 480a367..dc45b86 100644
--- a/examples/activeqt/menus/menus.h
+++ b/examples/activeqt/menus/menus.h
@@ -55,7 +55,7 @@ class QMenus : public QMainWindow
Q_CLASSINFO("EventsID", "{13eca64b-ee2a-4f3c-aa04-5d9d975979a7}")
public:
- QMenus(QWidget *parent = 0);
+ explicit QMenus(QWidget *parent = nullptr);
public slots:
void fileOpen();
@@ -72,7 +72,7 @@ public slots:
void helpAboutQt();
private:
- QTextEdit *editor;
+ QTextEdit *m_editor;
};
#endif // MENUS_H
diff --git a/examples/activeqt/multiple/ax1.h b/examples/activeqt/multiple/ax1.h
index 286645f..2cd6b33 100644
--- a/examples/activeqt/multiple/ax1.h
+++ b/examples/activeqt/multiple/ax1.h
@@ -54,18 +54,19 @@ class QAxWidget1 : public QWidget
Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor)
public:
- QAxWidget1(QWidget *parent = 0)
- : QWidget(parent), fill_color(Qt::red)
+ explicit QAxWidget1(QWidget *parent = nullptr)
+ : QWidget(parent), m_fillColor(Qt::red)
{
}
QColor fillColor() const
{
- return fill_color;
+ return m_fillColor;
}
+
void setFillColor(const QColor &fc)
{
- fill_color = fc;
+ m_fillColor = fc;
repaint();
}
@@ -75,11 +76,11 @@ protected:
QPainter paint(this);
QRect r = rect();
r.adjust(10, 10, -10, -10);
- paint.fillRect(r, fill_color);
+ paint.fillRect(r, m_fillColor);
}
private:
- QColor fill_color;
+ QColor m_fillColor;
};
//! [0]
diff --git a/examples/activeqt/multiple/ax2.h b/examples/activeqt/multiple/ax2.h
index 8b04653..211878c 100644
--- a/examples/activeqt/multiple/ax2.h
+++ b/examples/activeqt/multiple/ax2.h
@@ -55,38 +55,39 @@ class QAxWidget2 : public QWidget
Q_CLASSINFO("StockEvents", "yes")
Q_CLASSINFO("Insertable", "yes")
- Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
+ Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth)
public:
- QAxWidget2(QWidget *parent = 0)
- : QWidget(parent), line_width( 1 )
+ explicit QAxWidget2(QWidget *parent = nullptr)
+ : QWidget(parent), m_lineWidth(1)
{
}
int lineWidth() const
{
- return line_width;
+ return m_lineWidth;
}
- void setLineWidth( int lw )
+
+ void setLineWidth(int lw)
{
- line_width = lw;
+ m_lineWidth = lw;
repaint();
}
protected:
- void paintEvent( QPaintEvent *e )
+ void paintEvent(QPaintEvent *e)
{
- QPainter paint( this );
+ QPainter paint(this);
QPen pen = paint.pen();
- pen.setWidth( line_width );
- paint.setPen( pen );
+ pen.setWidth(m_lineWidth);
+ paint.setPen(pen);
QRect r = rect();
- r.adjust( 10, 10, -10, -10 );
- paint.drawEllipse( r );
+ r.adjust(10, 10, -10, -10);
+ paint.drawEllipse(r);
}
private:
- int line_width;
+ int m_lineWidth;
};
//! [0]
diff --git a/examples/activeqt/opengl/glbox.cpp b/examples/activeqt/opengl/glbox.cpp
index 04c854c..3c6862f 100644
--- a/examples/activeqt/opengl/glbox.cpp
+++ b/examples/activeqt/opengl/glbox.cpp
@@ -62,12 +62,12 @@
Create a GLBox widget
*/
-GLBox::GLBox( QWidget* parent, const char* name )
- : QGLWidget( parent )
+GLBox::GLBox(QWidget *parent, const char *name)
+ : QGLWidget(parent)
{
- xRot = yRot = zRot = 0.0; // default object rotation
- scale = 1.25; // default object scale
- object = 0;
+ m_xRot = m_yRot = m_zRot = 0.0; // default object rotation
+ m_scale = 1.25; // default object scale
+ m_object = 0;
}
@@ -79,8 +79,8 @@ GLBox::~GLBox()
{
makeCurrent();
- if (object)
- glDeleteLists( object, 1 );
+ if (m_object)
+ glDeleteLists(m_object, 1);
}
@@ -91,17 +91,17 @@ GLBox::~GLBox()
void GLBox::paintGL()
{
- glClear( GL_COLOR_BUFFER_BIT );
+ glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
- glTranslatef( 0.0, 0.0, -10.0 );
- glScalef( scale, scale, scale );
+ glTranslatef(0.0, 0.0, -10.0);
+ glScalef(m_scale, m_scale, m_scale);
- glRotatef( xRot, 1.0, 0.0, 0.0 );
- glRotatef( yRot, 0.0, 1.0, 0.0 );
- glRotatef( zRot, 0.0, 0.0, 1.0 );
+ glRotatef(m_xRot, 1.0, 0.0, 0.0);
+ glRotatef(m_yRot, 0.0, 1.0, 0.0);
+ glRotatef(m_zRot, 0.0, 0.0, 1.0);
- glCallList( object );
+ glCallList(m_object);
}
@@ -114,8 +114,8 @@ void GLBox::initializeGL()
initializeOpenGLFunctions();
qglClearColor(Qt::black); // Let OpenGL clear to black
- object = makeObject(); // Generate an OpenGL display list
- glShadeModel( GL_FLAT );
+ m_object = makeObject(); // Generate an OpenGL display list
+ glShadeModel(GL_FLAT);
}
@@ -124,13 +124,13 @@ void GLBox::initializeGL()
Set up the OpenGL view port, matrix mode, etc.
*/
-void GLBox::resizeGL( int w, int h )
+void GLBox::resizeGL(int w, int h)
{
- glViewport( 0, 0, (GLint)w, (GLint)h );
- glMatrixMode( GL_PROJECTION );
+ glViewport(0, 0, (GLint)w, (GLint)h);
+ glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
- glMatrixMode( GL_MODELVIEW );
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);
+ glMatrixMode(GL_MODELVIEW);
}
@@ -142,33 +142,33 @@ GLuint GLBox::makeObject()
{
GLuint list;
- list = glGenLists( 1 );
+ list = glGenLists(1);
- glNewList( list, GL_COMPILE );
+ glNewList(list, GL_COMPILE);
qglColor(Qt::white); // Shorthand for glColor3f or glIndex
- glLineWidth( 2.0 );
+ glLineWidth(2.0);
- glBegin( GL_LINE_LOOP );
- glVertex3f( 1.0, 0.5, -0.4 );
- glVertex3f( 1.0, -0.5, -0.4 );
- glVertex3f( -1.0, -0.5, -0.4 );
- glVertex3f( -1.0, 0.5, -0.4 );
+ glBegin(GL_LINE_LOOP);
+ glVertex3f( 1.0, 0.5, -0.4);
+ glVertex3f( 1.0, -0.5, -0.4);
+ glVertex3f(-1.0, -0.5, -0.4);
+ glVertex3f(-1.0, 0.5, -0.4);
glEnd();
- glBegin( GL_LINE_LOOP );
- glVertex3f( 1.0, 0.5, 0.4 );
- glVertex3f( 1.0, -0.5, 0.4 );
- glVertex3f( -1.0, -0.5, 0.4 );
- glVertex3f( -1.0, 0.5, 0.4 );
+ glBegin(GL_LINE_LOOP);
+ glVertex3f( 1.0, 0.5, 0.4);
+ glVertex3f( 1.0, -0.5, 0.4);
+ glVertex3f(-1.0, -0.5, 0.4);
+ glVertex3f(-1.0, 0.5, 0.4);
glEnd();
- glBegin( GL_LINES );
- glVertex3f( 1.0, 0.5, -0.4 ); glVertex3f( 1.0, 0.5, 0.4 );
- glVertex3f( 1.0, -0.5, -0.4 ); glVertex3f( 1.0, -0.5, 0.4 );
- glVertex3f( -1.0, -0.5, -0.4 ); glVertex3f( -1.0, -0.5, 0.4 );
- glVertex3f( -1.0, 0.5, -0.4 ); glVertex3f( -1.0, 0.5, 0.4 );
+ glBegin(GL_LINES);
+ glVertex3f( 1.0, 0.5, -0.4); glVertex3f( 1.0, 0.5, 0.4);
+ glVertex3f( 1.0, -0.5, -0.4); glVertex3f( 1.0, -0.5, 0.4);
+ glVertex3f(-1.0, -0.5, -0.4); glVertex3f(-1.0, -0.5, 0.4);
+ glVertex3f(-1.0, 0.5, -0.4); glVertex3f(-1.0, 0.5, 0.4);
glEnd();
glEndList();
@@ -181,9 +181,9 @@ GLuint GLBox::makeObject()
Set the rotation angle of the object to \e degrees around the X axis.
*/
-void GLBox::setXRotation( int degrees )
+void GLBox::setXRotation(int degrees)
{
- xRot = (GLfloat)(degrees % 360);
+ m_xRot = (GLfloat)(degrees % 360);
updateGL();
}
@@ -192,9 +192,9 @@ void GLBox::setXRotation( int degrees )
Set the rotation angle of the object to \e degrees around the Y axis.
*/
-void GLBox::setYRotation( int degrees )
+void GLBox::setYRotation(int degrees)
{
- yRot = (GLfloat)(degrees % 360);
+ m_yRot = (GLfloat)(degrees % 360);
updateGL();
}
@@ -203,9 +203,9 @@ void GLBox::setYRotation( int degrees )
Set the rotation angle of the object to \e degrees around the Z axis.
*/
-void GLBox::setZRotation( int degrees )
+void GLBox::setZRotation(int degrees)
{
- zRot = (GLfloat)(degrees % 360);
+ m_zRot = (GLfloat)(degrees % 360);
updateGL();
}
@@ -215,12 +215,12 @@ class ObjectSafetyImpl : public QAxAggregated,
{
public:
//! [1] //! [2]
- ObjectSafetyImpl() {}
+ explicit ObjectSafetyImpl() {}
- long queryInterface( const QUuid &iid, void **iface )
+ long queryInterface(const QUuid &iid, void **iface)
{
- *iface = 0;
- if ( iid == IID_IObjectSafety )
+ *iface = nullptr;
+ if (iid == IID_IObjectSafety)
*iface = (IObjectSafety*)this;
else
return E_NOINTERFACE;
@@ -233,13 +233,14 @@ public:
QAXAGG_IUNKNOWN;
//! [3] //! [4]
- HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions )
+ HRESULT WINAPI GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
{
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
return S_OK;
}
- HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions )
+
+ HRESULT WINAPI SetInterfaceSafetyOptions(REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions)
{
return S_OK;
}
diff --git a/examples/activeqt/opengl/glbox.h b/examples/activeqt/opengl/glbox.h
index 5c09912..a1b854a 100644
--- a/examples/activeqt/opengl/glbox.h
+++ b/examples/activeqt/opengl/glbox.h
@@ -63,32 +63,28 @@ class GLBox : public QGLWidget,
//! [0] //! [1]
public:
-
- GLBox( QWidget* parent, const char* name = 0 );
- ~GLBox();
-
+ explicit GLBox(QWidget *parent, const char *name = nullptr);
+ virtual ~GLBox();
QAxAggregated *createAggregate();
public slots:
-
- void setXRotation( int degrees );
+ void setXRotation(int degrees);
//! [1]
- void setYRotation( int degrees );
- void setZRotation( int degrees );
+ void setYRotation(int degrees);
+ void setZRotation(int degrees);
protected:
-
void initializeGL();
void paintGL();
- void resizeGL( int w, int h );
-
+ void resizeGL(int w, int h);
virtual GLuint makeObject();
private:
-
- GLuint object;
- GLfloat xRot, yRot, zRot, scale;
-
+ GLuint m_object;
+ GLfloat m_xRot;
+ GLfloat m_yRot;
+ GLfloat m_zRot;
+ GLfloat m_scale;
};
#endif // GLBOX_H
diff --git a/examples/activeqt/opengl/globjwin.cpp b/examples/activeqt/opengl/globjwin.cpp
index 367ede2..56b0902 100644
--- a/examples/activeqt/opengl/globjwin.cpp
+++ b/examples/activeqt/opengl/globjwin.cpp
@@ -49,62 +49,61 @@
#include <QApplication>
-GLObjectWindow::GLObjectWindow(QWidget* parent)
+GLObjectWindow::GLObjectWindow(QWidget *parent)
: QWidget(parent)
{
-
// Create a menu
- QMenu *file = new QMenu( this );
- file->addAction( "Exit", qApp, SLOT(quit())/*, CTRL+Key_Q*/);
+ QMenu *file = new QMenu(this);
+ file->addAction(tr("Exit"), qApp, &QApplication::quit);
// Create a menu bar
- QMenuBar *m = new QMenuBar( this );
- m->addMenu(file)->setText("&File");
+ QMenuBar *m = new QMenuBar(this);
+ m->addMenu(file)->setText(tr("&File"));
// Create a nice frame to put around the OpenGL widget
- QFrame* f = new QFrame(this);
- f->setFrameStyle( QFrame::Sunken | QFrame::Panel );
- f->setLineWidth( 2 );
+ QFrame *f = new QFrame(this);
+ f->setFrameStyle(QFrame::Sunken | QFrame::Panel);
+ f->setLineWidth(2);
// Create our OpenGL widget
- GLBox* c = new GLBox( f, "glbox");
+ GLBox *c = new GLBox(f, "glbox");
// Create the three sliders; one for each rotation axis
- QSlider* x = new QSlider(Qt::Vertical, this);
+ QSlider *x = new QSlider(Qt::Vertical, this);
x->setMaximum(360);
x->setPageStep(60);
- x->setTickPosition( QSlider::TicksLeft );
- QObject::connect( x, SIGNAL(valueChanged(int)),c,SLOT(setXRotation(int)) );
+ x->setTickPosition(QSlider::TicksLeft);
+ connect(x, &QSlider::valueChanged, c, &GLBox::setXRotation);
- QSlider* y = new QSlider(Qt::Vertical, this);
+ QSlider *y = new QSlider(Qt::Vertical, this);
y->setMaximum(360);
y->setPageStep(60);
- y->setTickPosition( QSlider::TicksLeft );
- QObject::connect( y, SIGNAL(valueChanged(int)),c,SLOT(setYRotation(int)) );
+ y->setTickPosition(QSlider::TicksLeft);
+ connect(y, &QSlider::valueChanged, c, &GLBox::setYRotation);
- QSlider* z = new QSlider(Qt::Vertical, this);
+ QSlider *z = new QSlider(Qt::Vertical, this);
z->setMaximum(360);
z->setPageStep(60);
- z->setTickPosition( QSlider::TicksLeft );
- QObject::connect( z, SIGNAL(valueChanged(int)),c,SLOT(setZRotation(int)) );
+ z->setTickPosition(QSlider::TicksLeft);
+ connect(z, &QSlider::valueChanged, c, &GLBox::setZRotation);
// Now that we have all the widgets, put them into a nice layout
// Top level layout, puts the sliders to the left of the frame/GL widget
- QHBoxLayout* hlayout = new QHBoxLayout(this);
+ QHBoxLayout *hlayout = new QHBoxLayout(this);
// Put the sliders on top of each other
- QVBoxLayout* vlayout = new QVBoxLayout();
- vlayout->addWidget( x );
- vlayout->addWidget( y );
- vlayout->addWidget( z );
+ QVBoxLayout *vlayout = new QVBoxLayout();
+ vlayout->addWidget(x);
+ vlayout->addWidget(y);
+ vlayout->addWidget(z);
// Put the GL widget inside the frame
- QHBoxLayout* flayout = new QHBoxLayout(f);
+ QHBoxLayout *flayout = new QHBoxLayout(f);
flayout->setMargin(0);
- flayout->addWidget( c, 1 );
+ flayout->addWidget(c, 1);
- hlayout->setMenuBar( m );
- hlayout->addLayout( vlayout );
- hlayout->addWidget( f, 1 );
+ hlayout->setMenuBar(m);
+ hlayout->addLayout(vlayout);
+ hlayout->addWidget(f, 1);
}
diff --git a/examples/activeqt/opengl/globjwin.h b/examples/activeqt/opengl/globjwin.h
index cd9a8d9..64006b1 100644
--- a/examples/activeqt/opengl/globjwin.h
+++ b/examples/activeqt/opengl/globjwin.h
@@ -55,7 +55,7 @@ class GLObjectWindow : public QWidget
Q_OBJECT
public:
- GLObjectWindow(QWidget *parent = 0);
+ explicit GLObjectWindow(QWidget *parent = nullptr);
};
#endif
diff --git a/examples/activeqt/opengl/main.cpp b/examples/activeqt/opengl/main.cpp
index 1c8a79b..45a90e1 100644
--- a/examples/activeqt/opengl/main.cpp
+++ b/examples/activeqt/opengl/main.cpp
@@ -65,19 +65,20 @@ QAXFACTORY_END()
The main program is here.
*/
-int main( int argc, char **argv )
+int main(int argc, char *argv[])
{
- QApplication::setColorSpec( QApplication::CustomColor );
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ QApplication::setColorSpec(QApplication::CustomColor);
QApplication a(argc,argv);
if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL) {
- qWarning( "This system does not support OpenGL. Exiting." );
+ qWarning("This system does not support OpenGL. Exiting.");
return -1;
}
- if ( !QAxFactory::isServer() ) {
+ if (!QAxFactory::isServer()) {
GLObjectWindow w;
- w.resize( 400, 350 );
+ w.resize(400, 350);
w.show();
return a.exec();
//! [1] //! [2]
diff --git a/examples/activeqt/qutlook/addressview.cpp b/examples/activeqt/qutlook/addressview.cpp
index b92c793..283da3a 100644
--- a/examples/activeqt/qutlook/addressview.cpp
+++ b/examples/activeqt/qutlook/addressview.cpp
@@ -46,8 +46,8 @@
class AddressBookModel : public QAbstractListModel
{
public:
- AddressBookModel(AddressView *parent);
- ~AddressBookModel();
+ explicit AddressBookModel(AddressView *parent);
+ virtual ~AddressBookModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent) const;
@@ -97,13 +97,13 @@ int AddressBookModel::rowCount(const QModelIndex &) const
return contactItems ? contactItems->Count() : 0;
}
-int AddressBookModel::columnCount(const QModelIndex &parent) const
+int AddressBookModel::columnCount(const QModelIndex & /*parent*/) const
{
return 4;
}
//! [3] //! [4]
-QVariant AddressBookModel::headerData(int section, Qt::Orientation orientation, int role) const
+QVariant AddressBookModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
@@ -182,69 +182,68 @@ void AddressBookModel::update()
endResetModel();
}
-
//! [8] //! [9]
AddressView::AddressView(QWidget *parent)
: QWidget(parent)
{
QGridLayout *mainGrid = new QGridLayout(this);
- QLabel *liFirstName = new QLabel("First &Name", this);
- liFirstName->resize(liFirstName->sizeHint());
- mainGrid->addWidget(liFirstName, 0, 0);
+ QLabel *firstNameLabel = new QLabel(tr("First &Name"), this);
+ firstNameLabel->resize(firstNameLabel->sizeHint());
+ mainGrid->addWidget(firstNameLabel, 0, 0);
- QLabel *liLastName = new QLabel("&Last Name", this);
- liLastName->resize(liLastName->sizeHint());
- mainGrid->addWidget(liLastName, 0, 1);
+ QLabel *lastNameLabel = new QLabel(tr("&Last Name"), this);
+ lastNameLabel->resize(lastNameLabel->sizeHint());
+ mainGrid->addWidget(lastNameLabel, 0, 1);
- QLabel *liAddress = new QLabel("Add&ress", this);
- liAddress->resize(liAddress->sizeHint());
- mainGrid->addWidget(liAddress, 0, 2);
+ QLabel *addressLabel = new QLabel(tr("Add&ress"), this);
+ addressLabel->resize(addressLabel->sizeHint());
+ mainGrid->addWidget(addressLabel, 0, 2);
- QLabel *liEMail = new QLabel("&E-Mail", this);
- liEMail->resize(liEMail->sizeHint());
- mainGrid->addWidget(liEMail, 0, 3);
+ QLabel *emailLabel = new QLabel(tr("&E-Mail"), this);
+ emailLabel->resize(emailLabel->sizeHint());
+ mainGrid->addWidget(emailLabel, 0, 3);
- add = new QPushButton("A&dd", this);
- add->resize(add->sizeHint());
- mainGrid->addWidget(add, 0, 4);
- connect(add, SIGNAL(clicked()), this, SLOT(addEntry()));
+ m_addButton = new QPushButton(tr("A&dd"), this);
+ m_addButton->resize(m_addButton->sizeHint());
+ mainGrid->addWidget(m_addButton, 0, 4);
+ connect(m_addButton, &QPushButton::clicked, this, &AddressView::addEntry);
- iFirstName = new QLineEdit(this);
- iFirstName->resize(iFirstName->sizeHint());
- mainGrid->addWidget(iFirstName, 1, 0);
- liFirstName->setBuddy(iFirstName);
+ m_firstName = new QLineEdit(this);
+ m_firstName->resize(m_firstName->sizeHint());
+ mainGrid->addWidget(m_firstName, 1, 0);
+ firstNameLabel->setBuddy(m_firstName);
- iLastName = new QLineEdit(this);
- iLastName->resize(iLastName->sizeHint());
- mainGrid->addWidget(iLastName, 1, 1);
- liLastName->setBuddy(iLastName);
+ m_lastName = new QLineEdit(this);
+ m_lastName->resize(m_lastName->sizeHint());
+ mainGrid->addWidget(m_lastName, 1, 1);
+ lastNameLabel->setBuddy(m_lastName);
- iAddress = new QLineEdit(this);
- iAddress->resize(iAddress->sizeHint());
- mainGrid->addWidget(iAddress, 1, 2);
- liAddress->setBuddy(iAddress);
+ m_address = new QLineEdit(this);
+ m_address->resize(m_address->sizeHint());
+ mainGrid->addWidget(m_address, 1, 2);
+ addressLabel->setBuddy(m_address);
- iEMail = new QLineEdit(this);
- iEMail->resize(iEMail->sizeHint());
- mainGrid->addWidget(iEMail, 1, 3);
- liEMail->setBuddy(iEMail);
+ m_email = new QLineEdit(this);
+ m_email->resize(m_email->sizeHint());
+ mainGrid->addWidget(m_email, 1, 3);
+ emailLabel->setBuddy(m_email);
- change = new QPushButton("&Change", this);
- change->resize(change->sizeHint());
- mainGrid->addWidget(change, 1, 4);
- connect(change, SIGNAL(clicked()), this, SLOT(changeEntry()));
+ m_changeButton = new QPushButton(tr("&Change"), this);
+ m_changeButton->resize(m_changeButton->sizeHint());
+ mainGrid->addWidget(m_changeButton, 1, 4);
+ connect(m_changeButton, &QPushButton::clicked, this, &AddressView::changeEntry);
- treeView = new QTreeView(this);
- treeView->setSelectionMode(QTreeView::SingleSelection);
- treeView->setRootIsDecorated(false);
+ m_treeView = new QTreeView(this);
+ m_treeView->setSelectionMode(QTreeView::SingleSelection);
+ m_treeView->setRootIsDecorated(false);
model = new AddressBookModel(this);
- treeView->setModel(model);
+ m_treeView->setModel(model);
- connect(treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(itemSelected(QModelIndex)));
+ connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &AddressView::itemSelected);
- mainGrid->addWidget(treeView, 2, 0, 1, 5);
+ mainGrid->addWidget(m_treeView, 2, 0, 1, 5);
}
void AddressView::updateOutlook()
@@ -254,23 +253,23 @@ void AddressView::updateOutlook()
void AddressView::addEntry()
{
- if (!iFirstName->text().isEmpty() || !iLastName->text().isEmpty() ||
- !iAddress->text().isEmpty() || !iEMail->text().isEmpty()) {
- model->addItem(iFirstName->text(), iFirstName->text(), iAddress->text(), iEMail->text());
+ if (!m_firstName->text().isEmpty() || !m_lastName->text().isEmpty() ||
+ !m_address->text().isEmpty() || !m_email->text().isEmpty()) {
+ model->addItem(m_firstName->text(), m_lastName->text(), m_address->text(), m_email->text());
}
- iFirstName->setText("");
- iLastName->setText("");
- iAddress->setText("");
- iEMail->setText("");
+ m_firstName->clear();
+ m_lastName->clear();
+ m_address->clear();
+ m_email->clear();
}
void AddressView::changeEntry()
{
- QModelIndex current = treeView->currentIndex();
+ QModelIndex current = m_treeView->currentIndex();
if (current.isValid())
- model->changeItem(current, iFirstName->text(), iLastName->text(), iAddress->text(), iEMail->text());
+ model->changeItem(current, m_firstName->text(), m_lastName->text(), m_address->text(), m_email->text());
}
//! [9] //! [10]
@@ -279,10 +278,10 @@ void AddressView::itemSelected(const QModelIndex &index)
if (!index.isValid())
return;
- QAbstractItemModel *model = treeView->model();
- iFirstName->setText(model->data(model->index(index.row(), 0)).toString());
- iLastName->setText(model->data(model->index(index.row(), 1)).toString());
- iAddress->setText(model->data(model->index(index.row(), 2)).toString());
- iEMail->setText(model->data(model->index(index.row(), 3)).toString());
+ QAbstractItemModel *model = m_treeView->model();
+ m_firstName->setText(model->data(model->index(index.row(), 0)).toString());
+ m_lastName->setText(model->data(model->index(index.row(), 1)).toString());
+ m_address->setText(model->data(model->index(index.row(), 2)).toString());
+ m_email->setText(model->data(model->index(index.row(), 3)).toString());
}
//! [10]
diff --git a/examples/activeqt/qutlook/addressview.h b/examples/activeqt/qutlook/addressview.h
index c29c537..6b54629 100644
--- a/examples/activeqt/qutlook/addressview.h
+++ b/examples/activeqt/qutlook/addressview.h
@@ -57,7 +57,7 @@ class AddressView : public QWidget
Q_OBJECT
public:
- AddressView(QWidget *parent = 0);
+ explicit AddressView(QWidget *parent = nullptr);
protected slots:
void addEntry();
@@ -69,9 +69,13 @@ protected slots:
protected:
AddressBookModel *model;
- QTreeView *treeView;
- QPushButton *add, *change;
- QLineEdit *iFirstName, *iLastName, *iAddress, *iEMail;
+ QTreeView *m_treeView;
+ QPushButton *m_addButton;
+ QPushButton *m_changeButton;
+ QLineEdit *m_firstName;
+ QLineEdit *m_lastName;
+ QLineEdit *m_address;
+ QLineEdit *m_email;
};
//! [0]
diff --git a/examples/activeqt/qutlook/main.cpp b/examples/activeqt/qutlook/main.cpp
index 4cb6fa5..b7b2199 100644
--- a/examples/activeqt/qutlook/main.cpp
+++ b/examples/activeqt/qutlook/main.cpp
@@ -42,12 +42,12 @@
#include "addressview.h"
#include <QApplication>
-int main(int argc, char ** argv)
+int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressView view;
- view.setWindowTitle("Qt Example - Looking at Outlook");
+ view.setWindowTitle(QObject::tr("Qt Example - Looking at Outlook"));
view.show();
return a.exec();
diff --git a/examples/activeqt/simple/main.cpp b/examples/activeqt/simple/main.cpp
index 4e855b3..a5348f9 100644
--- a/examples/activeqt/simple/main.cpp
+++ b/examples/activeqt/simple/main.cpp
@@ -54,33 +54,34 @@ class QSimpleAX : public QWidget, public QAxBindable
Q_CLASSINFO("ClassID", "{DF16845C-92CD-4AAB-A982-EB9840E74669}")
Q_CLASSINFO("InterfaceID", "{616F620B-91C5-4410-A74E-6B81C76FFFE0}")
Q_CLASSINFO("EventsID", "{E1816BBA-BF5D-4A31-9855-D6BA432055FF}")
- Q_PROPERTY( QString text READ text WRITE setText )
- Q_PROPERTY( int value READ value WRITE setValue )
+ Q_PROPERTY(QString text READ text WRITE setText)
+ Q_PROPERTY(int value READ value WRITE setValue)
public:
- QSimpleAX(QWidget *parent = 0)
+ explicit QSimpleAX(QWidget *parent = nullptr)
: QWidget(parent)
{
- QVBoxLayout *vbox = new QVBoxLayout( this );
+ QVBoxLayout *vbox = new QVBoxLayout(this);
- slider = new QSlider( Qt::Horizontal, this );
- LCD = new QLCDNumber( 3, this );
- edit = new QLineEdit( this );
+ m_slider = new QSlider(Qt::Horizontal, this);
+ m_LCD = new QLCDNumber(3, this);
+ m_edit = new QLineEdit(this);
- connect( slider, &QAbstractSlider::valueChanged, this, &QSimpleAX::setValue );
- connect( edit, &QLineEdit::textChanged, this, &QSimpleAX::setText );
+ connect(m_slider, &QAbstractSlider::valueChanged, this, &QSimpleAX::setValue);
+ connect(m_edit, &QLineEdit::textChanged, this, &QSimpleAX::setText);
- vbox->addWidget( slider );
- vbox->addWidget( LCD );
- vbox->addWidget( edit );
+ vbox->addWidget(m_slider);
+ vbox->addWidget(m_LCD);
+ vbox->addWidget(m_edit);
}
QString text() const
{
- return edit->text();
+ return m_edit->text();
}
+
int value() const
{
- return slider->value();
+ return m_slider->value();
}
signals:
@@ -89,41 +90,42 @@ signals:
void textChanged(const QString&);
public slots:
- void setText( const QString &string )
+ void setText(const QString &string)
{
- if ( !requestPropertyChange( "text" ) )
+ if (!requestPropertyChange("text"))
return;
- edit->blockSignals( true );
- edit->setText( string );
- edit->blockSignals( false );
+ QSignalBlocker blocker(m_edit);
+ m_edit->setText(string);
emit someSignal();
- emit textChanged( string );
+ emit textChanged(string);
- propertyChanged( "text" );
+ propertyChanged("text");
}
+
void about()
{
QMessageBox::information( this, "About QSimpleAX", "This is a Qt widget, and this slot has been\n"
"called through ActiveX/OLE automation!" );
}
- void setValue( int i )
+
+ void setValue(int i)
{
- if ( !requestPropertyChange( "value" ) )
+ if (!requestPropertyChange("value"))
return;
- slider->blockSignals( true );
- slider->setValue( i );
- slider->blockSignals( false );
- LCD->display( i );
- emit valueChanged( i );
- propertyChanged( "value" );
+ QSignalBlocker blocker(m_slider);
+ m_slider->setValue(i);
+ m_LCD->display(i);
+ emit valueChanged(i);
+
+ propertyChanged("value");
}
private:
- QSlider *slider;
- QLCDNumber *LCD;
- QLineEdit *edit;
+ QSlider *m_slider;
+ QLCDNumber *m_LCD;
+ QLineEdit *m_edit;
};
//! [0]
diff --git a/examples/activeqt/simpleqml/main.cpp b/examples/activeqt/simpleqml/main.cpp
index 8983b22..bd7dd33 100644
--- a/examples/activeqt/simpleqml/main.cpp
+++ b/examples/activeqt/simpleqml/main.cpp
@@ -50,19 +50,15 @@ class Controller : public QObject
Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QColor color READ color NOTIFY valueChanged)
public:
- explicit Controller(QWidget *parent = 0) :
- QObject(parent),
- m_value(0)
+ explicit Controller(QWidget *parent = nullptr) :
+ QObject(parent)
{ }
qreal value() const { return m_value; }
void setValue(qreal value)
{
- if (value < 0) value = 0;
- if (value > 1) value = 1;
-
- m_value = value;
+ m_value = qBound(qreal(0.0), value, qreal(1.0));
valueChanged();
}
@@ -84,7 +80,7 @@ signals:
void valueChanged();
private:
- qreal m_value;
+ qreal m_value = 0;
};
class QSimpleQmlAx : public QMainWindow
@@ -94,7 +90,7 @@ class QSimpleQmlAx : public QMainWindow
Q_CLASSINFO("InterfaceID", "{A5EC7D99-CEC9-4BD1-8336-ED15A579B185}")
Q_CLASSINFO("EventsID", "{5BBFBCFD-20FD-48A3-96C7-1F6649CD1F52}")
public:
- explicit QSimpleQmlAx(QWidget *parent = 0) :
+ explicit QSimpleQmlAx(QWidget *parent = nullptr) :
QMainWindow(parent)
{
auto ui = new QQuickWidget(this);
@@ -103,10 +99,10 @@ public:
qmlRegisterType<Controller>("app", 1, 0, "Controller");
// Initialize view
- ui->rootContext()->setContextProperty("context", QVariant::fromValue(new Controller(this)));
+ ui->rootContext()->setContextProperty(QStringLiteral("context"), QVariant::fromValue(new Controller(this)));
ui->setMinimumSize(200, 200);
ui->setResizeMode(QQuickWidget::SizeRootObjectToView);
- ui->setSource(QUrl("qrc:/main.qml"));
+ ui->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
setCentralWidget(ui);
}
};
diff --git a/examples/activeqt/webbrowser/main.cpp b/examples/activeqt/webbrowser/main.cpp
index 869ddfc..9d64601 100644
--- a/examples/activeqt/webbrowser/main.cpp
+++ b/examples/activeqt/webbrowser/main.cpp
@@ -125,8 +125,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow();
- ~MainWindow();
+ explicit MainWindow();
+ virtual ~MainWindow();
public slots:
void navigate(const QString &address);
@@ -145,17 +145,17 @@ public slots:
private:
inline const QString address() const
- { return addressEdit->text().trimmed(); }
+ { return m_addressEdit->text().trimmed(); }
QList<Location> bookmarks() const;
QAction *addLocation(const Location &location, QMenu *menu);
inline void addBookmark(const Location &location)
- { bookmarkActions << addLocation(location, BookmarksMenu); }
+ { m_bookmarkActions << addLocation(location, BookmarksMenu); }
- QProgressBar *pb;
- QLineEdit *addressEdit;
- QList<QAction *> bookmarkActions;
- QList<QAction *> historyActions;
- QSignalMapper locationActionMapper;
+ QProgressBar *m_progressBar;
+ QLineEdit *m_addressEdit;
+ QList<QAction *> m_bookmarkActions;
+ QList<QAction *> m_historyActions;
+ QSignalMapper m_locationActionMapper;
};
//! [0] //! [1]
@@ -163,11 +163,12 @@ MainWindow::MainWindow()
{
setupUi(this);
- addressEdit = new QLineEdit;
+ m_addressEdit = new QLineEdit;
tbAddress->insertWidget(actionGo, new QLabel(tr("Address")));
- tbAddress->insertWidget(actionGo, addressEdit);
+ tbAddress->insertWidget(actionGo, m_addressEdit);
+
+ connect(m_addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger()));
- connect(addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger()));
connect(actionBack, SIGNAL(triggered()), WebBrowser, SLOT(GoBack()));
connect(actionForward, SIGNAL(triggered()), WebBrowser, SLOT(GoForward()));
connect(actionStop, SIGNAL(triggered()), WebBrowser, SLOT(Stop()));
@@ -175,12 +176,12 @@ MainWindow::MainWindow()
connect(actionHome, SIGNAL(triggered()), WebBrowser, SLOT(GoHome()));
connect(actionSearch, SIGNAL(triggered()), WebBrowser, SLOT(GoSearch()));
- pb = new QProgressBar(statusBar());
- pb->setTextVisible(false);
- pb->hide();
- statusBar()->addPermanentWidget(pb);
+ m_progressBar = new QProgressBar(statusBar());
+ m_progressBar->setTextVisible(false);
+ m_progressBar->hide();
+ statusBar()->addPermanentWidget(m_progressBar);
- connect(&locationActionMapper, SIGNAL(mapped(QString)), this, SLOT(navigate(QString)));
+ connect(&m_locationActionMapper, QOverload<const QString &>::of(&QSignalMapper::mapped), this, &MainWindow::navigate);
QSettings settings(QSettings::IniFormat, QSettings::UserScope,
QCoreApplication::organizationName(), QCoreApplication::applicationName());
@@ -214,23 +215,23 @@ QAction *MainWindow::addLocation(const Location &location, QMenu *menu)
{
QAction *action = menu->addAction(location.title);
action->setData(QVariant::fromValue(location));
- locationActionMapper.setMapping(action, location.address);
- connect(action, SIGNAL(triggered()), &locationActionMapper, SLOT(map()));
+ m_locationActionMapper.setMapping(action, location.address);
+ connect(action, &QAction::triggered, &m_locationActionMapper, QOverload<>::of(&QSignalMapper::map));
return action;
}
QList<Location> MainWindow::bookmarks() const
{
QList<Location> result;
- for (const QAction *action : qAsConst(bookmarkActions))
+ for (const QAction *action : qAsConst(m_bookmarkActions))
result.append(locationFromAction(action));
return result;
}
void MainWindow::on_actionAddBookmark_triggered()
{
- if (!historyActions.isEmpty()) {
- const Location location = locationFromAction(historyActions.last());
+ if (!m_historyActions.isEmpty()) {
+ const Location location = locationFromAction(m_historyActions.last());
if (!containsAddress(bookmarks(), location.address))
addBookmark(location);
}
@@ -241,26 +242,26 @@ void MainWindow::on_WebBrowser_TitleChange(const QString &title)
{
// This is called multiple times after NavigateComplete().
// Add new URLs to history here.
- setWindowTitle("Qt WebBrowser - " + title);
+ setWindowTitle(tr("Qt WebBrowser - ") + title);
const QString currentAddress = address();
- const QString historyAddress = historyActions.isEmpty() ?
- QString() : locationFromAction(historyActions.last()).address;
- if (currentAddress.isEmpty() || currentAddress == "about:blank" || currentAddress == historyAddress)
+ const QString historyAddress = m_historyActions.isEmpty() ?
+ QString() : locationFromAction(m_historyActions.last()).address;
+ if (currentAddress.isEmpty() || currentAddress == QStringLiteral("about:blank") || currentAddress == historyAddress)
return;
- historyActions << addLocation(Location(title, currentAddress), HistoryMenu);
- if (historyActions.size() > 10)
- delete historyActions.takeFirst();
+ m_historyActions << addLocation(Location(title, currentAddress), HistoryMenu);
+ if (m_historyActions.size() > 10)
+ delete m_historyActions.takeFirst();
}
void MainWindow::on_WebBrowser_ProgressChange(int a, int b)
{
if (a <= 0 || b <= 0) {
- pb->hide();
+ m_progressBar->hide();
return;
}
- pb->show();
- pb->setRange(0, b);
- pb->setValue(a);
+ m_progressBar->setRange(0, b);
+ m_progressBar->setValue(a);
+ m_progressBar->show();
}
void MainWindow::on_WebBrowser_CommandStateChange(int cmd, bool on)
@@ -282,10 +283,9 @@ void MainWindow::on_WebBrowser_BeforeNavigate()
void MainWindow::on_WebBrowser_NavigateComplete(const QString &url)
{
+ QSignalBlocker blocker(m_addressEdit);
actionStop->setEnabled(false);
- const bool blocked = addressEdit->blockSignals(true);
- addressEdit->setText(url);
- addressEdit->blockSignals(blocked);
+ m_addressEdit->setText(url);
}
//! [3]
@@ -305,9 +305,9 @@ void MainWindow::on_actionNewWindow_triggered()
{
MainWindow *window = new MainWindow;
window->show();
- if (addressEdit->text().isEmpty())
+ if (m_addressEdit->text().isEmpty())
return;
- window->addressEdit->setText(addressEdit->text());
+ window->m_addressEdit->setText(m_addressEdit->text());
window->actionStop->setEnabled(true);
window->on_actionGo_triggered();
}
@@ -315,9 +315,9 @@ void MainWindow::on_actionNewWindow_triggered()
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, tr("About WebBrowser"),
- tr("This Example has been created using the ActiveQt integration into Qt Designer.\n"
- "It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX\n"
- "control into a Qt application."));
+ tr("This Example has been created using the ActiveQt integration into Qt Designer.\n"
+ "It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX\n"
+ "control into a Qt application."));
}
void MainWindow::on_actionAboutQt_triggered()
@@ -333,16 +333,15 @@ void MainWindow::on_actionFileClose_triggered()
#include "main.moc"
//! [3] //! [4]
-int main(int argc, char ** argv)
+int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- QCoreApplication::setApplicationName("Active Qt Web Browser");
- QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationName(QStringLiteral("Active Qt Web Browser"));
+ QCoreApplication::setOrganizationName(QStringLiteral("QtProject"));
MainWindow w;
- const QStringList arguments = QCoreApplication::arguments();
- const QString url = arguments.size() > 1 ?
- arguments.at(1) : QString::fromLatin1(qtUrl);
+ const auto &arguments = QCoreApplication::arguments();
+ const QString url = arguments.value(1, QString::fromLatin1(qtUrl));
w.navigate(url);
w.show();
return a.exec();
diff --git a/examples/activeqt/webbrowser/webaxwidget.h b/examples/activeqt/webbrowser/webaxwidget.h
index acb936e..8dac77e 100644
--- a/examples/activeqt/webbrowser/webaxwidget.h
+++ b/examples/activeqt/webbrowser/webaxwidget.h
@@ -48,7 +48,7 @@ class WebAxWidget : public QAxWidget
{
public:
- WebAxWidget(QWidget* parent = 0, Qt::WindowFlags f = 0)
+ WebAxWidget(QWidget *parent = nullptr, Qt::WindowFlags f = 0)
: QAxWidget(parent, f)
{
}
@@ -57,8 +57,7 @@ protected:
{
if (message >= WM_KEYFIRST && message <= WM_KEYLAST)
return true;
- else
- return QAxWidget::translateKeyEvent(message, keycode);
+ return QAxWidget::translateKeyEvent(message, keycode);
}
};
diff --git a/examples/activeqt/wrapper/main.cpp b/examples/activeqt/wrapper/main.cpp
index 2c0db5f..b18d6cf 100644
--- a/examples/activeqt/wrapper/main.cpp
+++ b/examples/activeqt/wrapper/main.cpp
@@ -44,117 +44,112 @@
#include <QPushButton>
#include <QToolButton>
#include <QPixmap>
-
-/* XPM */
-static const char *fileopen[] = {
-" 16 13 5 1",
-". c #040404",
-"# c #808304",
-"a c None",
-"b c #f3f704",
-"c c #f3f7f3",
-"aaaaaaaaa...aaaa",
-"aaaaaaaa.aaa.a.a",
-"aaaaaaaaaaaaa..a",
-"a...aaaaaaaa...a",
-".bcb.......aaaaa",
-".cbcbcbcbc.aaaaa",
-".bcbcbcbcb.aaaaa",
-".cbcb...........",
-".bcb.#########.a",
-".cb.#########.aa",
-".b.#########.aaa",
-"..#########.aaaa",
-"...........aaaaa"
-};
-
+#include <functional>
//! [0]
class ActiveQtFactory : public QAxFactory
{
public:
- ActiveQtFactory( const QUuid &lib, const QUuid &app )
- : QAxFactory( lib, app )
+ ActiveQtFactory(const QUuid &lib, const QUuid &app)
+ : QAxFactory(lib, app)
{}
+
QStringList featureList() const
{
- QStringList list;
- list << "QCheckBox";
- list << "QRadioButton";
- list << "QPushButton";
- list << "QToolButton";
- return list;
+ return m_activeElements.keys();
}
+
QObject *createObject(const QString &key)
{
- if ( key == "QCheckBox" )
- return new QCheckBox(0);
- if ( key == "QRadioButton" )
- return new QRadioButton(0);
- if ( key == "QPushButton" )
- return new QPushButton(0 );
- if ( key == "QToolButton" ) {
- QToolButton *tb = new QToolButton(0);
-// tb->setIcon( QPixmap(fileopen) );
- return tb;
- }
-
- return 0;
+ auto it = m_activeElements.find(key);
+ if (it != m_activeElements.end())
+ return it->create();
+ return nullptr;
}
- const QMetaObject *metaObject( const QString &key ) const
- {
- if ( key == "QCheckBox" )
- return &QCheckBox::staticMetaObject;
- if ( key == "QRadioButton" )
- return &QRadioButton::staticMetaObject;
- if ( key == "QPushButton" )
- return &QPushButton::staticMetaObject;
- if ( key == "QToolButton" )
- return &QToolButton::staticMetaObject;
- return 0;
- }
- QUuid classID( const QString &key ) const
+ const QMetaObject *metaObject(const QString &key) const
{
- if ( key == "QCheckBox" )
- return "{6E795DE9-872D-43CF-A831-496EF9D86C68}";
- if ( key == "QRadioButton" )
- return "{AFCF78C8-446C-409A-93B3-BA2959039189}";
- if ( key == "QPushButton" )
- return "{2B262458-A4B6-468B-B7D4-CF5FEE0A7092}";
- if ( key == "QToolButton" )
- return "{7c0ffe7a-60c3-4666-bde2-5cf2b54390a1}";
+ auto it = m_activeElements.find(key);
+ if (it != m_activeElements.end())
+ return it->metaObject;
+ return nullptr;
+ }
+ QUuid classID(const QString &key) const
+ {
+ auto it = m_activeElements.find(key);
+ if (it != m_activeElements.end())
+ return it->classID;
return QUuid();
}
- QUuid interfaceID( const QString &key ) const
- {
- if ( key == "QCheckBox" )
- return "{4FD39DD7-2DE0-43C1-A8C2-27C51A052810}";
- if ( key == "QRadioButton" )
- return "{7CC8AE30-206C-48A3-A009-B0A088026C2F}";
- if ( key == "QPushButton" )
- return "{06831CC9-59B6-436A-9578-6D53E5AD03D3}";
- if ( key == "QToolButton" )
- return "{6726080f-d63d-4950-a366-9bf33e5cdf84}";
+ QUuid interfaceID(const QString &key) const
+ {
+ auto it = m_activeElements.find(key);
+ if (it != m_activeElements.end())
+ return it->interfaceID;
return QUuid();
}
- QUuid eventsID( const QString &key ) const
- {
- if ( key == "QCheckBox" )
- return "{FDB6FFBE-56A3-4E90-8F4D-198488418B3A}";
- if ( key == "QRadioButton" )
- return "{73EE4860-684C-4A66-BF63-9B9EFFA0CBE5}";
- if ( key == "QPushButton" )
- return "{3CC3F17F-EA59-4B58-BBD3-842D467131DD}";
- if ( key == "QToolButton" )
- return "{f4d421fd-4ead-4fd9-8a25-440766939639}";
+ QUuid eventsID(const QString &key) const
+ {
+ auto it = m_activeElements.find(key);
+ if (it != m_activeElements.end())
+ return it->eventsID;
return QUuid();
}
+
+private:
+
+ struct ActiveElement {
+ QUuid classID;
+ QUuid interfaceID;
+ QUuid eventsID;
+ const QMetaObject *metaObject;
+ std::function<QObject *()> create;
+ };
+
+ const QHash<QString, ActiveElement> m_activeElements {
+ {
+ QStringLiteral("QCheckBox"), {
+ QUuid("{6E795DE9-872D-43CF-A831-496EF9D86C68}"),
+ QUuid("{4FD39DD7-2DE0-43C1-A8C2-27C51A052810}"),
+ QUuid("{FDB6FFBE-56A3-4E90-8F4D-198488418B3A}"),
+ &QCheckBox::staticMetaObject,
+ []() { return new QCheckBox; }
+ }
+ },
+ {
+ QStringLiteral("QRadioButton"), {
+ QUuid("{AFCF78C8-446C-409A-93B3-BA2959039189}"),
+ QUuid("{7CC8AE30-206C-48A3-A009-B0A088026C2F}"),
+ QUuid("{73EE4860-684C-4A66-BF63-9B9EFFA0CBE5}"),
+ &QRadioButton::staticMetaObject,
+ []() { return new QRadioButton; }
+ }
+ },
+ {
+ QStringLiteral("QPushButton"), {
+ QUuid("{2B262458-A4B6-468B-B7D4-CF5FEE0A7092}"),
+ QUuid("{06831CC9-59B6-436A-9578-6D53E5AD03D3}"),
+ QUuid("{3CC3F17F-EA59-4B58-BBD3-842D467131DD}"),
+ &QPushButton::staticMetaObject,
+ []() { return new QPushButton; }
+ }
+ },
+ {
+ QStringLiteral("QToolButton"), {
+ QUuid("{7c0ffe7a-60c3-4666-bde2-5cf2b54390a1}"),
+ QUuid("{6726080f-d63d-4950-a366-9bf33e5cdf84}"),
+ QUuid("{f4d421fd-4ead-4fd9-8a25-440766939639}"),
+ &QToolButton::staticMetaObject,
+ []() { return new QToolButton; }
+ }
+ },
+ };
+
};
//! [0] //! [1]
-QAXFACTORY_EXPORT( ActiveQtFactory, "{3B756301-0075-4E40-8BE8-5A81DE2426B7}", "{AB068077-4924-406a-BBAF-42D91C8727DD}" )
+QAXFACTORY_EXPORT(ActiveQtFactory, "{3B756301-0075-4E40-8BE8-5A81DE2426B7}", "{AB068077-4924-406a-BBAF-42D91C8727DD}")
//! [1]