Praktische Aspekte der Informatik

Similar documents
Lab 12: GUI programming with Qt

Exercises Lecture 2 The Qt Object Model and Signal Slot Mechanism

Qt Essentials - Objects Module

Document Revision No.: 1 Revised: 03/12/09 RIT KGCOE MSD Program. P09027 Upper Extremity Motion Capture System. Software Manual

INSTRUCTIONS: GOOD LUCK! [TURN OVER]

Qt Essentials - Fundamentals of Qt Module

Praktische Aspekte der Informatik

Qt Essentials - Fundamentals of Qt Module

Qt in Education. The Qt object model and the signal slot concept

C++ GUI Programming with Qt 3

Integrating QML with C++

Friday, 4 January 13. Introduction to Qt

NHERI SIMCENTER PROGRAMMING BOOTCAMP JULY 30 THROUGH AUGUST 3, 2018, AT UC BERKELEY S RICHMOND FIELD STATION. GUI Development

+ C++11. Qt5 with a touch of C++11. Matthew Eshleman covemountainsoftware.com

CopperSpice: A Pure C++ GUI Library. Barbara Geller & Ansel Sermersheim CPPCon - September 2015

Qt-Interface For Volume Visualization

Praktische Aspekte der Informatik

Object-Oriented Programming

Creating Dynamic UIs with Qt Declarative UI

Tuesday, 9 March Introduction to Qt

Designing Interactive Systems II

Review. Designing Interactive Systems II. Introduction. Web 2.0 in keywords GWT Cappuccino HTML5. Cross platform GUI Toolkit

SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26,

C++ Important Questions with Answers

OpenGL and Qt Creator: a Gentle Introduction

OO for GUI Design (contd.) Questions:

Praktische Aspekte der Informatik

Praktische Aspekte der Informatik

Common Misunderstandings from Exam 1 Material

QObject. An important class to become familiar with is the one from which all Qt Widgets are derived: QObject.

OpenGL Introduction Computer Graphics and Visualization

Qt Essentials - Graphics View Module

Praktische Aspekte der Informatik

Qt-Based Implementation of Low Level ROOT Graphical Layer

Qt Introduction. Topics. C++ Build Process. Ch & Ch 3. 1) What's Qt? 2) How can we make a Qt console program? 3) How can we use dialogs?

C++ GUI Programming with Qt 3. Rozália Szabó Nacsa Eötvös Loránd University, Budapest

Qt Quick From bottom to top

ECE 462 Object-Oriented Programming using C++ and Java. Graphical User Interface

Final CSE 131B Spring 2004

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

Advanced Systems Programming

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

CopperSpice and the Next Generation of Signals. Barbara Geller & Ansel Sermersheim CppNow - May 2016

Introduction to CGAL. Constantinos Tsirogiannis. TU/Eindhoven

Exercises Lecture 3 Layouts and widgets

Qt Essentials - Basic Types Module

2. The quiz screen showing the question, text field (QLineEdit in QT) for the answer and the Next Question button

C++ Constructor Insanity

Luis Ibáñez William Schroeder Insight Software Consortium. ITK and Graphical User Interface

Lecture 15a Persistent Memory & Shared Pointers

Exercise Session 2 Systems Programming and Computer Architecture

Prof. Tiago G. S. Carneiro DECOM - UFOP. Threads em Qt. Prof. Tiago Garcia de Senna Carneiro

Recitation 2/18/2012

Python GUIs. $ conda install pyqt

Stream Computing using Brook+

the gamedesigninitiative at cornell university Lecture 6 C++: Basics

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Why C++ is much more fun than C (C++ FAQ)?

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns

G52CPP C++ Programming Lecture 7. Dr Jason Atkin

Intermediate Programming, Spring 2017*

Qt Essentials - Application Creation Module

GUI in C++ PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill. Faculty of Informatics, Masaryk University.

Qt + Maemo development

Why you should be excited about Qt 5

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

CS 223: Data Structures and Programming Techniques. Exam 2

Lecture 10. Implementing User Interface with QML

Mar :51 gltexobj.cpp

Reviewing gcc, make, gdb, and Linux Editors 1

Praktische Aspekte der Informatik. Thomas Löwe Prof. Marcus Magnor

Today we spend some time in OO Programming (Object Oriented). Hope you did already work with the first Starter and the box at:

Using the GeoX Framework

CSE 333 Lecture 6 - data structures

Slide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

A tale of ELFs and DWARFs

ECE 3574: Dynamic Polymorphism using Inheritance

LECTURE 18 GUI Programming Part 2

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I

Installing and Using Xcode

Part 1: I don t say Qute! [but I might say Q-awesome ]

Asynchronous Database Access with Qt 4.x

11 TREES DATA STRUCTURES AND ALGORITHMS IMPLEMENTATION & APPLICATIONS IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

Qt Essentials - Widgets Module

Containers & Iterators

Exercises Lecture 6 The Graphics View Canvas

JAVA An overview for C++ programmers

QT/KDE Research Paper CS B 27 February 2002

About 1. Chapter 1: Getting started with pyqt5 2. Remarks 2. Examples 2. Installation or Setup 2. Hello World Example 6. Adding an application icon 8

CSE 374 Programming Concepts & Tools

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

Lecture 10: building large projects, beginning C++, C++ and structs

Meet Qt. Justin Noel Senior Consulting Engineer ICS, Inc.

Introduction to Supercomputing

The C Preprocessor (and more)!

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Composition I. composition is a way to combine or compose multiple classes together to create new class

Chapter 1: Object-Oriented Programming Using C++

Transcription:

Praktische Aspekte der Informatik Moritz Mühlhausen Prof. Marcus Magnor https://graphics.tu-bs.de/teaching/ws1718/padi/ 1

Your Proposal It s due 17.11.2017! https://graphics.tu-bs.de/teaching/ws1718/padi/ 2

Your Proposal Use the template available on the website. Your proposal is a guideline for your project: Required goals Optional goals Don t worry too much about your proposal, you can still change details later on. You will have to upload your proposal to our git server as part of the next assignment. https://graphics.tu-bs.de/teaching/ws1718/padi/ 3

Your Proposal proposal.txt Name, Matrikelnummer, Bachelor/Master Studiengang Projektname Kurze Zusammenfassung Detaillierte Beschreibung/Auflistung der Funktionalität Welche externen Bibliotheken werden benutzt und wofür? Welche besonderen Anforderungen ergeben sich? https://graphics.tu-bs.de/teaching/ws1718/padi/ 4

GUI Programming Qt, Signals and Slots, moc, ui, and Qt Designer https://graphics.tu-bs.de/teaching/ws1718/padi/ 5

Further Reading Warning! The following slides are meant to give you a very superficial introduction. If you want to learn more, have a look at: http://doc.qt.io/qt-5 https://graphics.tu-bs.de/teaching/ws1718/padi/ 6

Outline About Qt Signals and Slots (.moc) User Interfaces (.ui) Resources (.qrc) QObject Assignment https://graphics.tu-bs.de/teaching/ws1718/padi/ 7

What is Qt? Qt is a cross-platform application and UI framework Qt comes with tons of extras It s own build system (qmake) It s own specialized IDE (Qt Creator) A great documentation (Qt Assistant) https://graphics.tu-bs.de/teaching/ws1718/padi/ 8

What is Qt? Benefits: Big and Powerful Filled with useful extras Has excellent documentation (use it!) Comes with its own tool chain Drawbacks: May require extra compile steps You might not need everything https://graphics.tu-bs.de/teaching/ws1718/padi/ 9

Qt Example #include <QApplication> #include <QMainWindow> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget * window = new QWidget; window->resize(320, 240); window->setwindowtitle("simple example"); } window->show(); return app.exec(); https://graphics.tu-bs.de/teaching/ws1718/padi/ 10

Qt Example #include <QApplication> #include <QMainWindow> #include <QBoxLayout> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget * window = new QWidget; window->resize(320, 240); window->setwindowtitle("simple example"); window->setlayout(new QBoxLayout(QBoxLayout::TopToBottom)); QPushButton * button = new QPushButton("Magic!"); window->layout()->addwidget(button); } window.show(); return app.exec(); https://graphics.tu-bs.de/teaching/ws1718/padi/ 11

What s different in Qt? Signals and Slots Classes can communicate with SIGNALS and SLOTS. Can be queried/connected at runtime. Can communicate across threads. Code Generators Qt-specific stuff is translated to standard C++ MOC: Qt-enhanced headers to C++ UIC: ui-xml to C++ headers RCC: Resources to binaries https://graphics.tu-bs.de/teaching/ws1718/padi/ 12

Outline About Qt Signals and Slots (.moc) User Interfaces (.ui) Resources (.qrc) QObject Assignment https://graphics.tu-bs.de/teaching/ws1718/padi/ 13

Signals and Slots class Counter : public QObject { Q_OBJECT // Mandatory!! public: Counter(QObject * parent = 0); virtual ~Counter(); int value() const; public slots: void setvalue(int value); signals: void valuechanged(int newvalue); // needs no implementation! private: int value_; }; void Counter::setValue(int value) { if (this->value_!= value) { this->value_ = value; emit valuechanged(this->value_); // Emit a signal } } https://graphics.tu-bs.de/teaching/ws1718/padi/ 14

Signals and Slots Counter * sender = new Counter; Counter * receiver = new Counter; // Old Syntax (still valid) connect(sender, SIGNAL(valueChanged(int)), receiver, SLOT(setValue(int)); // NEW: Alternative syntax connect(sender, &Counter::valueChanged, receiver, &Counter::setValue); // NEW: Connecting to simple function connect(sender, &Counter::valueChanged, somefunction); https://wiki.qt.io/new_signal_slot_syntax https://graphics.tu-bs.de/teaching/ws1718/padi/ 15

Meta Object Compiler http://thelins.se/learnqt/wp-content/uploads/qt-buildsystem.png https://graphics.tu-bs.de/teaching/ws1718/padi/ 16

Meta Object Compiler Makefile $(EXE): main.o moc_counter.o counter.o g++ $(LIBPATH) $(OPTIONS) $^ -o $@ main.o: main.cpp g++ $(INCPATH) $(CCFLAGS) -c $< moc_counter.o: moc_counter.cpp g++ $(INCPATH) $(CCFLAGS) -c moc_counter.cpp moc_counter.cpp: counter.h moc $(INCPATH) $< -o $@ counter.o: counter.cpp g++ $(INCPATH) $(CCFLAGS) -c counter.cpp clean: rm -f *.o *~ $(EXE) moc_*.cpp https://graphics.tu-bs.de/teaching/ws1718/padi/ 17

Outline About Qt Signals and Slots (.moc) User Interfaces (.ui) Resources (.qrc) QObject Assignment https://graphics.tu-bs.de/teaching/ws1718/padi/ 18

User Interfaces <?xml version="1.0" encoding="utf-8"?> <ui version="4.0"> <class>communicateclassname</class> <widget class="qwidget" name="communicateclassname"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>350</width> <height>190</height> </rect> </property> <property name="windowtitle"> <string>communicate</string> </property> <widget class="qpushbutton" name="plus"> <property name="geometry"> <rect> <x>50</x> <y>40</y> <width>75</width> <height>30</height> [ ] https://graphics.tu-bs.de/teaching/ws1718/padi/ 19

User Interfaces https://graphics.tu-bs.de/teaching/ws1718/padi/ 20

User Interfaces You can compose a new widget from existing ones organize child widgets using layouts style widgets using stylesheets (qss) http://doc.qt.io/qt-5/qtwidgets-index.html https://graphics.tu-bs.de/teaching/ws1718/padi/ 21

User Interfaces #include <QWidget> #include "ui_communicate.h" class Communicate : public QWidget { Q_OBJECT public: Communicate(QWidget * parent = NULL) : QWidget(parent), ui(new Ui::Communicate) { ui->setupui(this); connect(ui->plus, SIGNAL(clicked()), this, SLOT(onPlus())); connect(ui->minus, SIGNAL(clicked()), this, SLOT(onMinus())); } virtual ~Communicate() { delete ui; } public slots: void onplus() {... } void onminus() {... } private: Ui::Communicate * ui; } https://graphics.tu-bs.de/teaching/ws1718/padi/ 22

User Interface Compiler http://thelins.se/learnqt/wp-content/uploads/qt-buildsystem.png https://graphics.tu-bs.de/teaching/ws1718/padi/ 23

User Interface Compiler Makefile $(EXE): main.o moc_communicate.o communicate.o g++ $(LIBPATH) $(OPTIONS) $^ -o $@ main.o: main.cpp ui_communicate.h g++ $(INCPATH) $(CCFLAGS) -c $< moc_communicate.o: moc_communicate.cpp g++ $(INCPATH) $(CCFLAGS) -c moc_communicate.cpp moc_communicate.cpp: communicate.h ui_communicate.h moc $(INCPATH) $< -o $@ communicate.o: communicate.cpp ui_communicate.h g++ $(INCPATH) $(CCFLAGS) -c communicate.cpp ui_communicate.h: communicate.ui uic $< -o $@ https://graphics.tu-bs.de/teaching/ws1718/padi/ 24

Outline About Qt Signals and Slots (.moc) User Interfaces (.ui) Resources (.qrc) QObject Assignment https://graphics.tu-bs.de/teaching/ws1718/padi/ 25

Resources icons.qrc <!DOCTYPE RCC><RCC version="1.0"> <qresource> <file>images/copy.png</file> <file>images/cut.png</file> <file>images/new.png</file> <file>images/open.png</file> <file>images/paste.png</file> <file>images/save.png</file> </qresource> </RCC> In your code: QImage icon(":/images/copy.png"); http://doc.qt.io/qt-5/resources.html https://graphics.tu-bs.de/teaching/ws1718/padi/ 26

Resource Compiler http://thelins.se/learnqt/wp-content/uploads/qt-buildsystem.png https://graphics.tu-bs.de/teaching/ws1718/padi/ 27

Outline About Qt Signals and Slots (.moc) User Interfaces (.ui) Resources (.qrc) QObject Assignment https://graphics.tu-bs.de/teaching/ws1718/padi/ 28

What s different in Qt? Code Generators Qt-specific stuff is translated to standard C++ MOC: Qt-enhanced headers to C++ UIC: ui-xml to C++ headers RCC: Resources to binaries or just use qmake Signals and Slots Classes communicate using SIGNALS and SLOTS. (That means objects do not have to know each other) Can be queried/connected at runtime. Can communicate across threads. https://graphics.tu-bs.de/teaching/ws1718/padi/ 29

A few cool things about QObjects Have a look at the documentation of QObject! http://doc.qt.io/qt-5/qobject.html SIGNAL / SLOT Events (especially for QWidget) findchildren Q_PROPERTY macro QMetaObject https://graphics.tu-bs.de/teaching/ws1718/padi/ 30

Events If you want to create your very own Widget you can add interaction by overloading these protected functions: virtual void keypressevent(qkeyevent * event); virtual void keyreleaseevent(qkeyevent * event); virtual void mousepressevent(qmouseevent * event); virtual void mousereleaseevent(qmouseevent * event); virtual void mousemoveevent(qmouseevent * event); you can also customize what is drawn: virtual void paintevent(qpaintevent * event) { } QPainter p(this); // check out the documentation! p.setpen(qt::blue); p.setfont(qfont( Arial, 32)); p.drawtext(this->rect(), Qt::AlignCenter, My Widget! ); https://graphics.tu-bs.de/teaching/ws1718/padi/ 31

findchildren By design QObjects know nothing about each other QObject are organized in a tree structure. Delete one object (node) and the entire subtree gets cleaned up. Objects should only communicate using events or signals / slots. QObject::findChildren can be useful: // Temporarily find all children that are QPushButtons QList<QPushButton*> allbuttons = parent.findchildren<qpushbutton*>(); // Temporarily find all children that are QWidgets named widgetname QList<QWidget*> widgets = parent.findchildren<qwidget*>("widgetname"); https://graphics.tu-bs.de/teaching/ws1718/padi/ 32

Q_PROPERTY macro #include <QObject> class MyObject : public QObject { Q_OBJECT Q_PROPERTY(int foo READ getfoo WRITE setfoo) public: MyObject(QObject * parent = 0); virtual ~MyObject(); int getfoo() const; void setfoo(int foo); private: int foo; } // Data-driven design MyObject a; a.setproperty( foo, 42); // calls: a.setfoo(42); https://graphics.tu-bs.de/teaching/ws1718/padi/ 33

QMetaObject Every QObject has a QMetaObject. myobject->metaobject() QMetaObjects are magic What is the name of this object s class? How many function does my class have? Please, invoke function 5 with these arguments! and many, many more. It s great for data-driven design! http://doc.qt.io/qt-5/metaobjects.html https://graphics.tu-bs.de/teaching/ws1718/padi/ 34

A few cool things about QObjects Have a look at the documentation of QObject! http://doc.qt.io/qt-5/qobject.html SIGNAL / SLOT Events (especially for QWidget) findchildren Q_PROPERTY macro QMetaObject https://graphics.tu-bs.de/teaching/ws1718/padi/ 35

Outline About Qt Signals and Slots (.moc) User Interfaces (.ui) Resources (.qrc) QObject Assignment https://graphics.tu-bs.de/teaching/ws1718/padi/ 36

Assignment A. Create an account on our git server Go to the website: git.cg.cs.tu-bs.de Create an Account with your lastname as username B. Simple Data Visualization Implement a small Qt widget that reads a.csv file, and draws a simple graph (Bar Graph, Line Graph, etc.) Look at assignment_stub for more information. C. Have Fun! How about more graph types? How about multiple graphs? How about animation? https://graphics.tu-bs.de/teaching/ws1718/padi/ 37