Skip to content

piallai/glove

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Glove

License: GPLv3 Maintenance Generic badge Qt5 Single header Generic badge Generic badge Generic badge

Teaser

Code of samples above:

Summary

  • The library is designed as a general C++ toolkit with straightforward bindings with Qt

    • to manage parametrization of a class

    • to manage data containers as tables

    • to manage progress feedback of algorithms

  • Requires only Qt to be installed

  • Single header available

  • Modularity by relying on template specializations

  • Tutorials available in this page

  • Doxygen documentation available here

Table of contents

  1. Presentation
  2. Features
    1. Class parametrization : automatic widgets
      1. Paradigm
      2. Examples
      3. Save/load interface
      4. Remarks
        1. Widget specializations
        2. Convenient macros
    2. CLI parsing
      1. CLI to GUI
      2. Parametrization parsing
    3. Table interfacing
      1. Examples
    4. Progress feedback
      1. Examples
    5. Files I/O
    6. Specializations overview
  3. Use Glove
    1. Single header
    2. Installation and CMake use
      1. Windows / Visual Studio
      2. Linux
    3. Usage
      1. Library location
      2. CMake configuration of a project using Glove
  4. License

Presentation

Glove is a C++/Qt library aiming at creating simple interfaces. It proposes several basic GUI features that are often necessary to develop a user-friendly program. The toolkit aims at minimizing the required knowledge of Qt. For now, the main features of the library are:

  • The management of parameters

  • Table/tree interfacing with data containers

  • A progress feedback tracking

  • Files management (read and write)

The library consists in an alternative to Qt UI for simple prototypes (QtCreator is not required). It is particularly suited for developpers wishing to create a basic graphical user interface (input/output) of their program or algorithm without needing in-depth knowledge of Qt. A minimal understanding of widgets may be required depending on the use of the library.

The library is separated in two layers.

  • Sleeve

    • Slv prefix

    • C++ only

    • Can compile without Qt

  • Glove

    • Glv prefix

    • Qt layer interpreting the Sleeve layer for interfacing

The library can be used either:

  • by using a single header. See details

    • moc management using CMake or qmake is still required
  • by installation and direct use of sources and compiled libraires. See details

Class parametrization : automatic widgets

Aims at providing a simple framework for parametrization of class instances, by inheriting a dedicated class. Creating the parametrization interface using Qt widgets is straightforward.

Paradigm

The framework explicitly points what are the parameters of a class. Parameters are defined by:

  • a variable name
  • a type
  • a name
  • a comment
  • a default value
  • optional rules on its value

A parametrization can currently contain up to 25 parameters of any type. Parametrizations can contain nested parametrizations. So there is theoretically no limit to the number of parameters.

Examples :

Save/load interface

Each parametrization widget GlvParametrizationWidget and data widget GlvWidget can be extended easily with an input/output file interface.

Examples :

Remarks

GlvWidgetData specializations

You can find the list of type specializations provided in the library here GlvWidgetData_specs.md.

See this page for a custom specialization.

Convient macros

List of convenient macros to handle parametrizations.

  • glvm_parametrization:

    • Declare a parametrization

    • see this page for example

  • glvm_get_parameter_GlvWidget(_parametrization_widget, _parameter_index):

    • Get the GlvWidget associated to parameter _parameter_index
  • glvm_get_parameter_GlvWidgetData(_parametrization_widget, _parameter_index):

    • Get the parameter widget (ex: QSpinBox) associated to parameter _parameter_index

    • see this page for example

  • glvm_SlvEnum / glvm_SlvEnum_named:

    • Declare an enum compatible with glove

    • see here and here for example

CLI parsing

CLI to GUI

The framework includes a simple method to transform the command line arguments of a main into a basic GUI. The framework allows a flexible CLI approach, and can manage saving and loading of the arguments as presented just above.

Example : CLI to GUI

Parametrization parsing

Without relying on Qt, a simple parsing of a 'main' parametrization can be done.

Example : CLI parametrization

Table interfacing

The framework includes a data modeling extra layer for view and edition. The class GlvTableView.h allows visualization of data as tables provided their modeling is defined. The modelings are implemented in specializations. Some specializations related to common containers are already available and listed at Model specializations.

The table view can handle data of multiple dimensions, using different containers, while displaying a handy interface for view and edition.

Examples :

Progress feedback

A progress interface is proposed in the library. Running an algorithm in a separate thread and monitoring its progress is made easy. You can find examples below of how to use the interface.

Examples :

Files I/O

Filesystem : C++11 compatible. Does not need boost.

Examples :

Specializations overview

The list of the key classes that are specialized can be found here

Use Glove

The library can be used either:

  • Option 1 : by adding a single header to a qmake or cmake project

    • Does not require compilation of Glove.
  • Option 2 : by compiling and installing includes and compiled binaries,

    • then use the installed components in a CMake project

The second option allows parsimonious include of headers and faster compilation of the code.

Single header (option 1)

The file glove.h available in release can be simply included in sources. The management of Qt can be disabled by using the macro GLOVE_DISABLE_QT.

To enable the json management, the macro GLOVE_ENABLE_JSON must be defined.

To enable the management of boost containers, the macro GLOVE_ENABLE_BOOST must be defined.

#define GLOVE_DISABLE_QT // Option to disable Qt management
#define GLOVE_ENABLE_JSON // Option to enable Json management
#define GLOVE_ENABLE_BOOST // Option to enable boost containers management
#include "glove.h"

The file glove.h must be added to the CMake or qmake .pro file.

An example project using the single header is proposed here.

Installation and CMake use (option 2)

The installation only requires CMake and Qt to be installed.

Windows / Visual Studio
Option 1 : CMake command line

At the root of the library, using PowerShell:

mkdir build
cd build
cmake .. -G "Visual Studio 17 2022"
Option 2 : CMake GUI
  • In the field Where is the source code, select the root folder of the library. That is, where CMakeLists.txt is.
  • In the field Where to build the binaries, select the build folder (to create yourself).
  • Press Configure
  • Press Generate
Generated project

Open Glove.sln, and compile the INSTALL target. The library will install to build/install.

Linux
  • The default installation path is /usr/local.
    • The library will install in:
      • /usr/local/lib/glove
      • /usr/local/include/glove
  • The default build type is Release if -DCMAKE_BUILD_TYPE is not specified.

At the root of the library:

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make install
  • The make install command may require sudo make install depending on privileges to install the library in /usr/local/.
  • To install at a specific location, use cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/path/where/to/install
  • For instance cmake .. -DCMAKE_INSTALL_PREFIX:PATH=. will install the library in the current build directory under ./install
Examples

After compilation, all the executable examples using the library can be found in the directory build/samples.

Usage

Library location
Windows

Set the environment variable GLOVE_ROOT as the path where the library was installed. That is, in the example above, build/install. For this purpose, in the search field of Windows, select "Environment variables". Then in the User variables part, press New.

Linux

If -DCMAKE_INSTALL_PREFIX:PATH=/path/where/to/install was used at CMake generation, then it is required to set the environment variable GLOVE_ROOT as the path where the library was installed. For instance, build/install. For this purpose, edit the file ~/.bashrc by adding the line: export GLOVE_ROOT=/path/where/to/install. The full path must be set (i.e. not relative to the library build directory).

CMake configuration of a project using Glove

An example project using the installed library is proposed here.

Find library

Copy CMake/FindGlove.cmake to a folder named /CMake/CMakeModules at the root of your CMake project. In the CMakeLists.txt, add where to look for FindGlove.cmake by setting

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake/CMakeModules")

Then set:

find_package(Glove)
Include

In CMake's INCLUDE_DIRECTORIES, add ${GLOVE_INCLUDE_DIRS}.

Link
foreach(lib ${GLOVE_LIBRARIES})
    target_link_libraries(${PROJECT_NAME} optimized ${lib})
endforeach()
foreach(lib ${GLOVE_LIBRARIES_DEBUG})
    target_link_libraries(${PROJECT_NAME} debug ${lib})
endforeach()

License

The library is licensed as GNU GPLv3. Dual licensing with commercial license is possible on demand.