Posts

Showing posts from April, 2020

QTreeView and QTableView dynamic changes

Image
Dynamically adding items to  QTreeView  and  QTableView Create the UI as follows, with the treeview on the left hand side and the table view on the right hand side. Notes The header file contains the models and the selection models for the tree view and the table view: QStandardItemModel * treeViewModel ; QItemSelectionModel * treeViewSelectionModel ; QItemSelectionModel * tableSelectionModel ; QStandardItemModel * tableModel ; In the .cpp file, the tree view models and table view models are set as the models for the selection models. treeViewSelectionModel -> setModel ( treeViewModel ) ; tableSelectionModel -> setModel ( tableModel ) ; The following code illustrates how to dynamically add a new row to the treeview. void MainWindow :: updateTreeView ( ) { QStandardItem * newRow = new QStandardItem ( QString ( "inserted row" ) ) ; QList < QStandardItem * > newRows ; newRows . append ( newRow ) ; auto f

Autolayout notes

Image
Notes on using AutoLayout When using AutoLayout in building iOS applications, use container views and temporarily set their background color to something visiible. Here is an example of laying out two "sections" of the screen proportionally without using vertical stack views. First screenshot below is the view hierarchy: Next screenshot shows the Main storyboard: Next up are the superview constraints: The explanation of some constraints follows: ButtonsView.top = PictureView.bottom+2 gives a gap of 2 points between the ButtonsView top and PictureView bottom bottom = ButtonsView.bottom  constrains the bottom of the ButtonsView to "hug" the bottom of the topmost view Here are the  ButtonsView  constraints: The height of the  ButtonsView  is constrained to 100 so that the  PictureView  can take up the remaining space. The buttons stackview is constrained to be centered vertically and horizontally within the  ButtonsView . Here are

RESTful API

RESTful API REST stands for  Representational State Transfer  and is an architecture for building Web APIs. The HTTP(s) verbs it uses are GET POST PUT PATCH DELETE Here is a complete example of implementing a RESTful API for a database that stores some articles: const express = require ( "express" ) ; const bodyParser = require ( "body-parser" ) ; const ejs = require ( "ejs" ) ; const mongoose = require ( "mongoose" ) ; const app = express ( ) ; app . set ( 'view engine' , 'ejs' ) ; app . use ( bodyParser . urlencoded ( { extended : true } ) ) ; const wikiSchema = { title : String , content : String } ; const Article = mongoose . model ( "article" , wikiSchema ) ; function sendExistingArticles ( res ) { Article . find ( { } , function ( err , articles ) { if ( ! err ) { res . send ( articles ) ; } else {

EJS

EJS EJS is a templating engine that can be used with  express.js . To use EJS, one has to set the view engine like so: app . set ( 'view engine' , 'ejs' ) ; This assumes the ejs files are in a folder called  views . Here is the EJS file: <!DOCTYPE html> < html lang = " en " > < head > < meta charset = " UTF-8 " > < meta name = " viewport " content = " width=device-width, initial-scale=1.0 " > < title > Todo List </ title > </ head > < body > < h1 > <%= kindOfDay %> </ h1 > <!-- substitute date into kindOfDay--> < ul > <% for (let index = 0; index < newListItems.length; index++) { %> <!-- newListItems passed in from app.js--> <% const element = newListItems[index]; %> < li > <%= element %> </ li > <%} %> </ ul >