コード例 #1
0
ファイル: TableModelView.cpp プロジェクト: jessezwd/Natron
void
TableView::setHorizontalHeaderLabels(const QStringList &labels)
{
    TableItem *item = 0;

    for (int i = 0; i < _imp->model->columnCount() && i < labels.count(); ++i) {
        item = _imp->model->horizontalHeaderItem(i);
        if (!item) {
            item = _imp->model->createItem();
            setHorizontalHeaderItem(i, item);
        }
        item->setText( labels.at(i) );
    }
}
コード例 #2
0
ファイル: KeyValueTable.cpp プロジェクト: mobius3/douml
void KeyValuesTable::updateThisFromNode(HaveKeyValueData *hv, bool isReadOnly)
{

    if (!isReadOnly)
    {
        if(numCols() == 2)
            insertColumns(2);
        horizontalHeader()->setLabel(2, TR("do"));
    }
    else
    {
        if(numCols() == 3)
            removeColumn(2);
    }

    int index;
    int sup = 0;
    if(hv)
        sup = hv->get_n_keys();
    int rowCount = numRows();
    for (index = rowCount - 1; index > sup; index -= 1)
        removeRow(index);

    if (isReadOnly)
    {
        for (index = 0; index < sup; index += 1)
        {
            TableItem * tiKey = nullptr;
            TableItem * tiValue = nullptr;
            QString s = toUnicode(hv->get_value(index));
            int n = s.count('\n');

            if(index == numRows() || numRows() == 0)
            {
                tiKey = new TableItem(this, Q3TableItem::Never,
                                      toUnicode(hv->get_key(index)));
                tiValue = new TableItem(this, Q3TableItem::Never, s);
                setItem(index, 0, tiKey);
                setItem(index, 1, tiValue);
            }
            else
            {
                tiKey = dynamic_cast<TableItem*>(item(index, 0));
                tiKey->setText(hv->get_key(index));
                tiValue = dynamic_cast<TableItem*>(item(index, 1));
                tiValue->setText(s);
            }
            tiKey->setReplaceable(FALSE);
            tiValue->setReplaceable(FALSE);


            if (n != 0)
            {
                // note : adjustRow(index) does nothing
                setRowHeight(index, rowHeight(index) * (n + 1));
            }
        }
    }
    else
    {
        props.setAutoDelete(TRUE);

        QStringList items;

        for (index = 0; index < sup; index += 1)
        {
            QString k = toUnicode(hv->get_key(index));
            QString v = toUnicode(hv->get_value(index));
            QStringList * psl = props[k];

            setText(index, 0, k);

            if (psl != 0)
                setItem(index, 1, new ComboItem(this, v, *psl, FALSE));

            if ((k.contains(':') == 2) &&
                    ProfiledStereotypes::enumerated(k, items)) {
                psl = new QStringList(items);
                props.insert(k, psl);
                setItem(index, 1, new ComboItem(this, v, *psl, FALSE));
            }
            else
                setItem(index, 1, new MLinesItem(this, v));

            setText(index, 2, QString());
            setRowStretchable(index, TRUE);
        }

        if(index == numRows())
            insertRows(numRows());
        setText(index, 0, QString());
        setItem(index, 1, new MLinesItem(this, QString()));
        setText(index, 2, QString());
        setRowStretchable(index, TRUE);
    }

    horizontalHeader()->setResizeEnabled(TRUE, 0);  //setColumnStretchable (0, TRUE);
    setColumnStretchable(1, TRUE);

    if (! isReadOnly) {
        adjustColumn(2);
        setColumnStretchable(2, FALSE);
    }



}