示例#1
0
Register::Register() //contrustor
{
    
    InventoryItem shirt("shirt", 5.50, 10); //creates an instance of InventoryItem called shirt. The inventory has 10 shirts for $5.50 each
    InventoryItem pants("pants", 12.50, 10); //creates an instance of InventoryItem called pants. The inventory has 10 shirts for $12.50 each
    InventoryItem skirt("skirt", 15.50, 10); //creates an instance of InventoryItem called skirt. The inventory has 10 skirt for $15.50 each
    InventoryItem shoes("shoes", 20.00, 10); //creates an instance of InventoryItem called skirt. The inventory has 10 skirt for $20.00 each
    inventory[0] = shirt; //makes the first index of the inventory array the shirt object
    inventory[1] = pants; //makes the second index of the inventory array the pants object
    inventory[2] = skirt; //makes the third index of the inventory array the skirt object
    inventory[3] = shoes; //makes the fourth index of the inventory array the shoes object
}
示例#2
0
void tdRenderer::render(QByteArray ba)
{
    bufreset(m_buffer);
    QWebElement element = m_body.findFirst(".__tmp__");

    const char *data = ba.data();
    uint beg = 0;
    size_t e = ba.size();
    int prevsize = 0;
    int pos = m_fframe;

    while (beg < e) {
        const char *offs = data + beg;
        int n = td_markdown_render(m_buffer, (const uint8_t *) offs,
                                   e - beg, m_markdown);

        QByteArray bytes((const char *) m_buffer->data + prevsize, m_buffer->size - prevsize);

        m_sizes.insert(pos, n);
        m_indices.insert(pos++, m_index);

        if (m_pants) {
            bufreset(m_tmpbuffer);
            sdhtml_smartypants(m_tmpbuffer, (const uint8_t *) bytes.constData(), bytes.size());
            QByteArray pants((const char *) m_tmpbuffer->data, m_tmpbuffer->size);
            element.appendInside(pants);
        } else {
            element.appendInside(bytes);
        }

        QWebElementCollection children = element.findAll("*");
        QString klassName = "__" % QString::number(m_index++) % "__";
        QWebElementCollection::const_iterator i = children.constBegin();
        for (; i != children.constEnd(); ++i) {
            QWebElement e = *i;
            e.addClass(klassName);
            if (!e.parent().hasClass(klassName))
                element.prependOutside(e.takeFromDocument());
        }
        if (m_body.findFirst("." % klassName).isNull())
            element.prependOutside("<span class=\"" % klassName % "\"></span>");

        beg += n;
        prevsize = m_buffer->size;
    }
    element.takeFromDocument();
}