c++_snippets.html qt5_snippets_basics.html


Snippets from/for Qt5.8 and Javascript

Nur ein paar wichtige Klassen und Methoden, die ich immer mal brauche - hier als Erinnerungsstütze...

QFileSystemModel

Example: Insert common file system path into treeview ...
  QFileSystemModel *model = new QFileSystemModel;
  model->setRootPath( sMyRootDir );
  model->setReadOnly( true );

  uiTreeView->setModel( model );

  uiTreeView->setRootIndex( model->index( sMyRootDir ) );

Example: Insert data and use DecorationRole to set the color information ...
    QFile file( "D:/mydata.cht" );
    if ( !file.open( QFile::ReadOnly | QFile::Text ) )
        return;

    QTextStream stream( &file );
    QString line;

    model->removeRows( 0, model->rowCount( QModelIndex() ), QModelIndex() );
    treeview->setModel( model );

    int row = 0;
    do {
        line = stream.readLine();

        if ( !line.isEmpty() )
        {
            model->insertRows( row, 1, QModelIndex() );

            QStringList lData = line.split( ",", QString::SkipEmptyParts );
            model->setData( model->index( row, 0, QModelIndex() ), lData.value(0) );
            model->setData( model->index( row, 1, QModelIndex() ), lData.value(1) );
            model->setData( model->index( row, 0, QModelIndex() ), QColor( lData.value(2) ), Qt::DecorationRole );
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            row++;
        }
    }
    while ( !line.isEmpty() );

    file.close();

Some Javascript Information ...

Example: Use a map in a web page ...(replace { with < and } with >!!!)
...
{link rel="stylesheet" href="./dist/leaflet.css"/}
{link rel="stylesheet" href="./screen.css"/}
{script type="text/javascript" src="./build/deps.js"}{/script}
{script src="./leaflet-src.js">{/script}
{/HEAD}
...
{div id="map" style="width: 700px; height: 700px; border: 1px solid #ccc"}{/div}

{script src="data_zugspitze.js">{/script}
{script}
	var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
		osmAttrib = '© OpenStreetMap contributors',
		osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib});


	for (var i = 0, latlngs = [], len = route.length; i < len; i++) {
		latlngs.push(new L.LatLng(route[i][0], route[i][1]));
	}
	var path = new L.Polyline(latlngs);

	var map = new L.Map('map', {layers: [osm]});

	map.fitBounds(new L.LatLngBounds(latlngs));
	
	var zugspitze_Icon = new L.Icon({iconUrl: 'zugspitze.svg'});
	var seefeld_Icon = new L.Icon({iconUrl: 'seefeld.svg'});

	var marker = L.marker([47.42,10.99]);
	marker.addTo(map);
	
	var marker2 = L.marker([47.32,11.18]);
	marker2.addTo(map);
		
	var begin = new L.Marker(latlngs[0]);
	var end = new L.Marker(latlngs[len - 1]);

	
	map.addLayer(begin);
	map.addLayer(end);
	map.addLayer(path);
{/script}

Example: JSON file data_zugspitze.js looks like this:
var route = [[47.25,11.32],[47.25,11.22],[47.26,11.20],[47.29,11.16],[47.38,11.16],
            [47.42,11.15],[47.43,11.15],[47.45,11.15],[47.50,11.28],[47.55,11.40],[47.65,11.55]];

next time more about: D3D.JS,SceneJs,ExtJS ...