Custom Items Example▲
Sélectionnez
/**
**************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Data Visualization module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
***************************************************************************
*/
#include
"customitemgraph.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMessageBox>
int
main(int
argc, char
**
argv)
{
QApplication app(argc, argv);
Q3DSurface *
graph =
new
Q3DSurface();
QWidget *
container =
QWidget::
createWindowContainer(graph);
if
(!
graph-&
gt;hasContext()) {
QMessageBox msgBox;
msgBox.setText("Couldn't initialize the OpenGL context."
);
msgBox.exec();
return
-
1
;
}
container-&
gt;setMinimumSize(QSize(800
, 600
));
container-&
gt;setSizePolicy(QSizePolicy::
Expanding, QSizePolicy::
Expanding);
container-&
gt;setFocusPolicy(Qt::
StrongFocus);
QWidget *
widget =
new
QWidget;
QHBoxLayout *
hLayout =
new
QHBoxLayout(widget);
QVBoxLayout *
vLayoutLeft =
new
QVBoxLayout();
vLayoutLeft-&
gt;setAlignment(Qt::
AlignTop);
QVBoxLayout *
vLayoutRight =
new
QVBoxLayout();
vLayoutRight-&
gt;setAlignment(Qt::
AlignTop);
hLayout-&
gt;addLayout(vLayoutLeft);
hLayout-&
gt;addWidget(container, 1
);
hLayout-&
gt;addLayout(vLayoutRight);
QFont font =
QFont("Century Gothic"
, 14
);
QLabel *
label =
new
QLabel("Show:"
);
font.setBold(true
);
label-&
gt;setFont(font);
vLayoutLeft-&
gt;addWidget(label);
font.setBold(false
);
QCheckBox *
checkboxOne =
new
QCheckBox("Oil Rig 1"
);
checkboxOne-&
gt;setChecked(true
);
checkboxOne-&
gt;setFont(font);
vLayoutLeft-&
gt;addWidget(checkboxOne);
QCheckBox *
checkboxTwo =
new
QCheckBox("Oil Rig 2"
);
checkboxTwo-&
gt;setChecked(true
);
checkboxTwo-&
gt;setFont(font);
vLayoutLeft-&
gt;addWidget(checkboxTwo);
QCheckBox *
checkboxThree =
new
QCheckBox("Refinery"
);
checkboxThree-&
gt;setFont(font);
vLayoutLeft-&
gt;addWidget(checkboxThree);
QLabel *
label2 =
new
QLabel("Visuals:"
);
font.setBold(true
);
label2-&
gt;setFont(font);
vLayoutRight-&
gt;addWidget(label2);
QCheckBox *
checkboxOneRight =
new
QCheckBox("See-Through"
);
font.setBold(false
);
checkboxOneRight-&
gt;setFont(font);
vLayoutRight-&
gt;addWidget(checkboxOneRight);
QCheckBox *
checkboxTwoRight =
new
QCheckBox("Highlight Oil"
);
checkboxTwoRight-&
gt;setFont(font);
vLayoutRight-&
gt;addWidget(checkboxTwoRight);
QCheckBox *
checkboxThreeRight =
new
QCheckBox("Shadows"
);
checkboxThreeRight-&
gt;setFont(font);
checkboxThreeRight-&
gt;setChecked(true
);
vLayoutRight-&
gt;addWidget(checkboxThreeRight);
QLabel *
label3 =
new
QLabel("Selection:"
);
font.setBold(true
);
label3-&
gt;setFont(font);
vLayoutRight-&
gt;addWidget(label3);
QLabel *
label4 =
new
QLabel("Nothing"
);
font.setBold(false
);
font.setPointSize(11
);
label4-&
gt;setFont(font);
vLayoutRight-&
gt;addWidget(label4);
widget-&
gt;setWindowTitle(QStringLiteral("Custom Items Example"
));
widget-&
gt;show();
CustomItemGraph *
modifier =
new
CustomItemGraph(graph, label4);
QObject::
connect(checkboxOne, &
amp;QCheckBox::
stateChanged,
modifier, &
amp;CustomItemGraph::
toggleItemOne);
QObject::
connect(checkboxTwo, &
amp;QCheckBox::
stateChanged,
modifier, &
amp;CustomItemGraph::
toggleItemTwo);
QObject::
connect(checkboxThree, &
amp;QCheckBox::
stateChanged,
modifier, &
amp;CustomItemGraph::
toggleItemThree);
QObject::
connect(checkboxOneRight, &
amp;QCheckBox::
stateChanged,
modifier, &
amp;CustomItemGraph::
toggleSeeThrough);
QObject::
connect(checkboxTwoRight, &
amp;QCheckBox::
stateChanged,
modifier, &
amp;CustomItemGraph::
toggleOilHighlight);
QObject::
connect(checkboxThreeRight, &
amp;QCheckBox::
stateChanged,
modifier, &
amp;CustomItemGraph::
toggleShadows);
return
app.exec();
}