/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the Qt Designer of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** ** ** ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "q3listview_extrainfo.h" #include #include #include #include #include QT_BEGIN_NAMESPACE inline QHash propertyMap(const QList &properties) // ### remove me { QHash map; for (int i=0; iattributeName(), p); } return map; } Q3ListViewExtraInfo::Q3ListViewExtraInfo(Q3ListView *widget, QDesignerFormEditorInterface *core, QObject *parent) : QObject(parent), m_widget(widget), m_core(core) {} QWidget *Q3ListViewExtraInfo::widget() const { return m_widget; } QDesignerFormEditorInterface *Q3ListViewExtraInfo::core() const { return m_core; } bool Q3ListViewExtraInfo::saveUiExtraInfo(DomUI *ui) { Q_UNUSED(ui); return false; } bool Q3ListViewExtraInfo::loadUiExtraInfo(DomUI *ui) { Q_UNUSED(ui); return false; } bool Q3ListViewExtraInfo::saveWidgetExtraInfo(DomWidget *ui_widget) { // ### finish me Q3ListView *listView = qobject_cast(widget()); Q_ASSERT(listView != 0); QList columns; Q3Header *header = listView->header(); for (int i=0; icount(); ++i) { DomColumn *c = new DomColumn(); QList properties; DomString *str = new DomString(); str->setText(header->label(i)); DomProperty *ptext = new DomProperty(); ptext->setAttributeName(QLatin1String("text")); ptext->setElementString(str); DomProperty *pclickable = new DomProperty(); pclickable->setAttributeName(QLatin1String("clickable")); pclickable->setElementBool(header->isClickEnabled(i) ? QLatin1String("true") : QLatin1String("false")); DomProperty *presizable = new DomProperty(); presizable->setAttributeName(QLatin1String("resizable")); presizable->setElementBool(header->isResizeEnabled(i) ? QLatin1String("true") : QLatin1String("false")); properties.append(ptext); properties.append(pclickable); properties.append(presizable); c->setElementProperty(properties); columns.append(c); } ui_widget->setElementColumn(columns); QList items; Q3ListViewItem *child = listView->firstChild(); while (child) { items.append(saveQ3ListViewItem(child)); child = child->nextSibling(); } ui_widget->setElementItem(items); return true; } bool Q3ListViewExtraInfo::loadWidgetExtraInfo(DomWidget *ui_widget) { Q3ListView *listView = qobject_cast(widget()); Q_ASSERT(listView != 0); Q3Header *header = listView->header(); QList columns = ui_widget->elementColumn(); for (int i=0; i properties = propertyMap(column->elementProperty()); DomProperty *text = properties.value(QLatin1String("text")); DomProperty *pixmap = properties.value(QLatin1String("pixmap")); DomProperty *clickable = properties.value(QLatin1String("clickable")); DomProperty *resizable = properties.value(QLatin1String("resizable")); QString txt = text->elementString()->text(); if (pixmap != 0) { DomResourcePixmap *pix = pixmap->elementPixmap(); QIcon icon(core()->iconCache()->resolveQrcPath(pix->text(), pix->attributeResource(), workingDirectory())); listView->addColumn(icon, txt); } else { listView->addColumn(txt); } if (clickable != 0) { header->setClickEnabled(clickable->elementBool() == QLatin1String("true"), header->count() - 1); } if (resizable != 0) { header->setResizeEnabled(resizable->elementBool() == QLatin1String("true"), header->count() - 1); } } if (ui_widget->elementItem().size()) { initializeQ3ListViewItems(ui_widget->elementItem()); } return true; } DomItem *Q3ListViewExtraInfo::saveQ3ListViewItem(Q3ListViewItem *item) const { DomItem *pitem = new DomItem(); QList properties; const int columnCount = static_cast(widget())->columns(); for (int i = 0; i < columnCount; ++i) { DomString *str = new DomString(); str->setText(item->text(i)); DomProperty *ptext = new DomProperty(); ptext->setAttributeName(QLatin1String("text")); ptext->setElementString(str); properties.append(ptext); } pitem->setElementProperty(properties); QList items; Q3ListViewItem *child = item->firstChild(); while (child) { items.append(saveQ3ListViewItem(child)); child = child->nextSibling(); } pitem->setElementItem(items); return pitem; } void Q3ListViewExtraInfo::initializeQ3ListViewItems(const QList &items, Q3ListViewItem *parentItem) { for (int i=0; i(widget())); int textCount = 0, pixCount = 0; QList properties = item->elementProperty(); for (int i=0; iattributeName() == QLatin1String("text")) __item->setText(textCount++, p->elementString()->text()); if (p->attributeName() == QLatin1String("pixmap")) { DomResourcePixmap *pix = p->elementPixmap(); QPixmap pixmap(core()->iconCache()->resolveQrcPath(pix->text(), pix->attributeResource(), workingDirectory())); __item->setPixmap(pixCount++, pixmap); } } if (item->elementItem().size()) { __item->setOpen(true); initializeQ3ListViewItems(item->elementItem(), __item); } } } Q3ListViewExtraInfoFactory::Q3ListViewExtraInfoFactory(QDesignerFormEditorInterface *core, QExtensionManager *parent) : QExtensionFactory(parent), m_core(core) {} QObject *Q3ListViewExtraInfoFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const { if (iid != Q_TYPEID(QDesignerExtraInfoExtension)) return 0; if (Q3ListView *w = qobject_cast(object)) return new Q3ListViewExtraInfo(w, m_core, parent); return 0; } QT_END_NAMESPACE