Script for generating Qt property

I wish QtCreator had some helpful utilities like this one. It’s just boring to write generic getter/setter stuff for properties by hand.

cls = "BulletQMLBody"
names = ["velocityX", "velocityY", "velocityZ", "angleVelocityX", "angleVelocityY", "angleVelocityZ"]
names = ["float "+x for x in names]

HEADER_TEMPLATE = """
Q_PROPERTY(float %(NAME)s READ %(NAME)s WRITE %(SETTER)s)
%(TYPE)s %(NAME)s();
void %(SETTER)s(const %(TYPE)s %(NAME)s);
%(TYPE)s m_%(NAME)s;"""

IMPL_TEMPLATE = """
%(TYPE)s %(CLASS)s::%(NAME)s()
{
    return m_%(NAME)s;
}

void %(CLASS)s::%(SETTER)s(const %(TYPE)s %(NAME)s)
{
    m_%(NAME)s = %(NAME)s;
}"""

def getData(aCls,aType,aName):
    return    {
    "CLASS": aCls,
    "TYPE" : aType,
    "NAME": aName,
    "SETTER" : "set" + aName[0].upper() + aName[1:]
    }
def genHeader(*args):
    return HEADER_TEMPLATE % getData(*args)

def genImpl(*args):
    return IMPL_TEMPLATE % getData(*args)

for n in names:
    t,n = n.split();
    print genHeader(cls, t, n)
for n in names:
    t,n = n.split()
    print genImpl(cls, t, n)

Output:

Q_PROPERTY(float velocityX READ velocityX WRITE setVelocityX)
float velocityX();
void setVelocityX(const float velocityX);
float m_velocityX;

...

float BulletQMLBody::velocityX()
{
    return m_velocityX;
}

void BulletQMLBody::setVelocityX(const float velocityX)
{
    m_velocityX = velocityX;
}
...

Disabling cross-domain security check for AJAX development in Google Chrome

This tip is for those who need to test Javascript / HTML5 web application functionality against a production server from their local HTML and Javascript files (not localhost).

Start Google Chrome with no security from command lin, OSX:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security

Start Google Chrome from command line, Ubuntu/Linux:

chromium-browser --disable-web-security
After this cross-domain AJAX requests work.

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+