PropertyItem* PropertyItemFromQObject::buildPropertyItem( const QObject *object, QMetaProperty &qmprop, PropertyItem *parent ) { PropertyItem * prop = 0; if(!qmprop.isWritable()&&_skipRO) return prop; if ( _itemFactory && qmprop.read( object ).isValid()) { QString key = qmprop.read( object ).typeName(); PropertyItemProvider *itemProvider = _itemFactory->get <PropertyItemProvider>( key ); if ( itemProvider == 0 ) //on tente de recuperer le provider par defaut itemProvider = _itemFactory->get <PropertyItemProvider>( PropertyItemDefaultFactory::K_DEFAULT_KEY ); if ( itemProvider != 0 ) prop = itemProvider->fromQVariant( qmprop.name(), qmprop.read( object ), parent ); } //si 0 c'est que la creation depuis la factory a echoue if ( prop == 0 ) { //on cree par defaut prop = new PropertyItem( qmprop.name(), parent ); prop->setData( qmprop.read( object ) ); } prop->setValueHolder( new PropertyItemQPropertyValueHolder(qmprop,const_cast<QObject*>(object))); return prop; }
void PropertyEditor::updatetEditorMode(const App::Property& prop) { // check if the parent object is selected std::string editor = prop.getEditorName(); if (editor.empty()) return; bool hidden = prop.testStatus(App::Property::Hidden); bool readOnly = prop.testStatus(App::Property::ReadOnly); int column = 1; int numRows = propertyModel->rowCount(); for (int i=0; i<numRows; i++) { QModelIndex item = propertyModel->index(i, column); PropertyItem* propItem = static_cast<PropertyItem*>(item.internalPointer()); if (propItem && propItem->hasProperty(&prop)) { setRowHidden (i, QModelIndex(), hidden); propItem->updateData(); if (item.isValid()) { updateItemEditor(!readOnly, column, item); dataChanged(item, item); } break; } } }
void PropertyItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { if (!index.isValid()) return; PropertyItem *childItem = static_cast<PropertyItem*>(index.internalPointer()); QVariant data = childItem->editorData(editor); model->setData(index, data, Qt::EditRole); }
QVariant PropertyModel::data ( const QModelIndex & index, int role ) const { if (!index.isValid()) return QVariant(); PropertyItem *item = static_cast<PropertyItem*>(index.internalPointer()); return item->data(index.column(), role); }
int PropertyModel::rowCount(const QModelIndex & parentIndex) const { if (parentIndex.column() > 0) return 0; PropertyItem * item = parentIndex.isValid() ? retrieveItem(parentIndex) : m_root; return item->childCount(); }
QModelIndex PropertyModel::parent(const QModelIndex & index) const { PropertyItem * item = index.isValid() ? retrieveItem(index) : m_root; if (!item->hasParent()) return QModelIndex(); return createIndex(item->parent()); }
QModelIndex PropertyModel::index(int row, int column, const QModelIndex & parentIndex) const { if (!hasIndex(row, column, parentIndex)) return QModelIndex(); PropertyItem * item = parentIndex.isValid() ? retrieveItem(parentIndex) : m_root; return createIndex(item->at(row), column); }
PropertyRenderer *PropertyDelegate::getRendererFor( const QModelIndex & index ) const { if ( _factory == 0 ) return 0; PropertyItem * data = toItem( index ); if ( data == 0 ) return 0; QString renderer = ( index.column() == 0 ) ? data->nameRenderer() : data->valueRenderer(); return ( renderer == "" ) ? 0 : _factory->get<PropertyRenderer>( renderer ); }
void PropertyRendererPixmap::paintProperty ( QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index ) { static const int i = 16; PropertyItem *data = modelIndexToData( index ); if ( data == 0 ) return ; QRect rect = option.rect; QRect pixRec = QRect( rect.left() + i / 2, rect.top() + ( rect.height() - i ) / 2, i, i ); QPixmap pix = getPixmapFromQVariant( data->data() ); painter->drawPixmap( pixRec, pix ); }
ScreenProperties::ScreenProperties(QWidget *parent) : PropertyTree(parent) { PropertyItem *section = insertSection(tr("Screen")); width = new PropertyItem(0); height = new PropertyItem(0); section->appendRow(tr("width"), width); section->appendRow(tr("height"), height); }
void CXmlPropertyList::toggleOpen( QListViewItem *i ) { if ( !i ) return; PropertyItem *pi = (PropertyItem*)i; if ( pi->hasSubItems() ) { pi->setOpen( !pi->isOpen() ); } else { pi->toggle(); } }
void PropertyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (!index.isValid()) return; QVariant data = index.data(Qt::EditRole); PropertyItem *childItem = static_cast<PropertyItem*>(index.internalPointer()); editor->blockSignals(true); childItem->setEditorData(editor, data); editor->blockSignals(false); return; }
void CXmlPropertyList::itemPressed( QListViewItem *i, const QPoint &p, int c ) { if ( !i ) return; PropertyItem *pi = (PropertyItem*)i; if ( !pi->hasSubItems() ) return; if ( c == 0 && viewport()->mapFromGlobal( p ).x() < 20 ) toggleOpen( i ); }
int PropertyModel::rowCount ( const QModelIndex & parent ) const { PropertyItem *parentItem; if (!parent.isValid()) parentItem = rootItem; else parentItem = static_cast<PropertyItem*>(parent.internalPointer()); return parentItem->childCount(); }
QModelIndex PropertyModel::parent ( const QModelIndex & index ) const { if (!index.isValid()) return QModelIndex(); PropertyItem *childItem = static_cast<PropertyItem*>(index.internalPointer()); PropertyItem *parentItem = childItem->parent(); if (parentItem == rootItem) return QModelIndex(); return createIndex(parentItem->row(), 0, parentItem); }
void PropertyItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const { QStyleOptionViewItem option = opt; PropertyItem *property = static_cast<PropertyItem*>(index.internalPointer()); if (property && property->isSeparator()) { QColor color = option.palette.color(QPalette::BrightText); QObject* par = parent(); if (par) { QVariant value = par->property("groupTextColor"); if (value.canConvert<QColor>()) color = value.value<QColor>(); } option.palette.setColor(QPalette::Text, color); option.font.setBold(true); option.state &= ~QStyle::State_Selected; } if (index.column() == 1) { option.state &= ~QStyle::State_Selected; } option.state &= ~QStyle::State_HasFocus; if (property && property->isSeparator()) { QBrush brush = option.palette.dark(); QObject* par = parent(); if (par) { QVariant value = par->property("groupBackground"); if (value.canConvert<QBrush>()) brush = value.value<QBrush>(); } painter->fillRect(option.rect, brush); } QPen savedPen = painter->pen(); QItemDelegate::paint(painter, option, index); QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt, qobject_cast<QWidget*>(parent()))); painter->setPen(QPen(color)); if (index.column() == 1 || !(property && property->isSeparator())) { int right = (option.direction == Qt::LeftToRight) ? option.rect.right() : option.rect.left(); painter->drawLine(right, option.rect.y(), right, option.rect.bottom()); } painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom()); painter->setPen(savedPen); }
QModelIndex PropertyModel::index ( int row, int column, const QModelIndex & parent ) const { PropertyItem *parentItem; if (!parent.isValid()) parentItem = rootItem; else parentItem = static_cast<PropertyItem*>(parent.internalPointer()); PropertyItem *childItem = parentItem->child(row); if (childItem) return createIndex(row, column, childItem); else return QModelIndex(); }
QStringList PropertyModel::propertyPathFromIndex(const QModelIndex& index) const { QStringList path; if (index.isValid()) { PropertyItem* item = static_cast<PropertyItem*>(index.internalPointer()); if (!item->isSeparator()) { do { path.push_front(item->propertyName()); item = item->parent(); } while (item != this->rootItem && item != 0); } } return path; }
Qt::ItemFlags PropertyModel::flags(const QModelIndex & index) const { if (!index.isValid()) return 0; PropertyItem * item = retrieveItem(index); Qt::ItemFlags flags = Qt::ItemIsSelectable; if (index.column() == 1 && item->property()->isValue() && !item->isReadOnly()) flags |= Qt::ItemIsEditable; if (item->isEnabled()) flags |= Qt::ItemIsEnabled; return flags; }
void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const { QTreeView::drawBranches(painter, rect, index); QStyleOptionViewItem opt = viewOptions(); PropertyItem *property = static_cast<PropertyItem*>(index.internalPointer()); if (property && property->isSeparator()) { painter->fillRect(rect, opt.palette.dark()); //} else if (selectionModel()->isSelected(index)) { // painter->fillRect(rect, opt.palette.brush(QPalette::Highlight)); } //QPen savedPen = painter->pen(); //QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt)); //painter->setPen(QPen(color)); //painter->drawLine(rect.x(), rect.bottom(), rect.right(), rect.bottom()); //painter->setPen(savedPen); }
QModelIndex PropertyModel::propertyIndexFromPath(const QStringList& path) const { QModelIndex parent; for (QStringList::const_iterator it = path.begin(); it != path.end(); ++it) { int rows = this->rowCount(parent); for (int i=0; i<rows; i++) { QModelIndex index = this->index(i, 0, parent); if (index.isValid()) { PropertyItem* item = static_cast<PropertyItem*>(index.internalPointer()); if (item->propertyName() == *it) { parent = index; break; } } } } return parent; }
QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & index ) const { if (!index.isValid()) return 0; PropertyItem *childItem = static_cast<PropertyItem*>(index.internalPointer()); if (!childItem) return 0; QWidget* editor = childItem->createEditor(parent, this, SLOT(valueChanged())); if (editor) // Make sure the editor background is painted so the cell content doesn't show through editor->setAutoFillBackground(true); if (editor && childItem->isReadOnly()) editor->setDisabled(true); else if (editor && this->pressed) editor->setFocus(); this->pressed = false; return editor; }
foreach(const Property property, component()->propertyMap()) { if(property.isVisible()) { bool newlyCreated = false; //Create new property item if it doesn't exist. if(!m_propertyItemsMap.contains(property.name())) { PropertyItem *item = new PropertyItem(property.name(), schematicScene()); QFont font = item->font(); if(font.pointSize() != m_pointSize) { font.setPointSize(m_pointSize); item->setFont(font); } m_propertyItemsMap.insert(property.name(), item); newlyCreated = true; } PropertyItem *item = m_propertyItemsMap[property.name()]; visibleItemsCount++; QList<QGraphicsItem*> _children = QGraphicsItemGroup::children(); if(!_children.isEmpty()) { //Place the new item at bottom, properly aligned with group. QPointF itemPos = mapToScene(boundingRect().bottomLeft()); itemPos.rx() -= item->boundingRect().left(); item->setPos(itemPos); } else { savePos.rx() -= item->boundingRect().left(); item->setPos(savePos); } addToGroup(item); if(newlyCreated) { item->updateValue(); } } else { // Delete item if it existed before as it is being hidden now. if(m_propertyItemsMap.contains(property.name())) { PropertyItem *item = m_propertyItemsMap[property.name()]; m_propertyItemsMap.remove(property.name()); delete item; } } }
void PropertyModel::buildUp(const std::map<std::string, std::vector<App::Property*> >& props) { // fill up the listview with the properties rootItem->reset(); // sort the properties into their groups std::map<std::string, std::vector<std::vector<App::Property*> > > propGroup; std::map<std::string, std::vector<App::Property*> > ::const_iterator jt; for (jt = props.begin(); jt != props.end(); ++jt) { App::Property* prop = jt->second.front(); const char* group = prop->getGroup(); std::string grp = group ? group : "Base"; propGroup[grp].push_back(jt->second); } std::map<std::string, std::vector<std::vector<App::Property*> > > ::const_iterator kt; for (kt = propGroup.begin(); kt != propGroup.end(); ++kt) { // set group item PropertyItem* group = static_cast<PropertyItem*>(PropertySeparatorItem::create()); group->setParent(rootItem); rootItem->appendChild(group); group->setPropertyName(QString::fromAscii(kt->first.c_str())); // setup the items for the properties std::vector<std::vector<App::Property*> >::const_iterator it; for (it = kt->second.begin(); it != kt->second.end(); ++it) { App::Property* prop = it->front(); QString editor = QString::fromAscii(prop->getEditorName()); if (!editor.isEmpty()) { Base::BaseClass* item = 0; try { item = static_cast<Base::BaseClass*>(Base::Type:: createInstanceByName(prop->getEditorName(),true)); } catch (...) { } if (!item) { qWarning("No property item for type %s found\n", prop->getEditorName()); continue; } if (item->getTypeId().isDerivedFrom(PropertyItem::getClassTypeId())) { PropertyItem* child = (PropertyItem*)item; child->setParent(rootItem); rootItem->appendChild(child); child->setPropertyName(QString::fromAscii(prop->getName())); child->setPropertyData(*it); } } } } reset(); }
void CXmlPropertyList::resetProperty() { if ( !currentItem() ) return; PropertyItem *i = (PropertyItem*)currentItem(); if ( !MetaDataBase::isPropertyChanged( editor->widget(), i->PropertyItem::name() ) ) return; QString pn( tr( "Reset '%1' of '%2'" ).arg( i->name() ).arg( editor->widget()->name() ) ); SetPropertyCommand *cmd = new SetPropertyCommand( pn, editor->formWindow(), editor->widget(), editor, i->name(), i->value(), WidgetFactory::defaultValue( editor->widget(), i->name() ), WidgetFactory::defaultCurrentItem( editor->widget(), i->name() ), i->currentItem(), TRUE ); cmd->execute(); editor->formWindow()->commandHistory()->addCommand( cmd, FALSE ); if ( i->hasSubItems() ) i->initChildren(); }
bool PropertyModel::setData(const QModelIndex& index, const QVariant & value, int role) { if (!index.isValid()) return false; // we check whether the data has really changed, otherwise we ignore it if (role == Qt::EditRole) { PropertyItem *item = static_cast<PropertyItem*>(index.internalPointer()); QVariant data = item->data(index.column(), role); if (data.type() == QVariant::Double && value.type() == QVariant::Double) { // since we store some properties as floats we get some round-off // errors here. Thus, we use an epsilon here. double d = data.toDouble(); double v = value.toDouble(); if (fabs(d-v) > FLT_EPSILON) return item->setData(value); } else if (data != value) return item->setData(value); } return true; }
QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & index ) const { if (!index.isValid()) return 0; PropertyItem *childItem = static_cast<PropertyItem*>(index.internalPointer()); if (!childItem) return 0; QWidget* editor = childItem->createEditor(parent, this, SLOT(valueChanged())); if (editor) // Make sure the editor background is painted so the cell content doesn't show through editor->setAutoFillBackground(true); if (editor && childItem->isReadOnly()) editor->setDisabled(true); else if (editor /*&& this->pressed*/) { // We changed the way editor is activated in PropertyEditor (in response // of signal activated and clicked), so now we should grab focus // regardless of "pressed" or not (e.g. when activated by keyboard // enter) editor->setFocus(); } this->pressed = false; return editor; }
int PropertyModel::columnCount(const QModelIndex & parentIndex) const { PropertyItem * item = parentIndex.isValid() ? retrieveItem(parentIndex) : m_root; return item->hasChildren() ? 2 : 0; }
void CXmlPropertyList::refetchData() { QListViewItemIterator it( this ); for ( ; it.current(); ++it ) { PropertyItem *i = (PropertyItem*)it.current(); if ( !i->propertyParent() ) setPropertyValue( i ); if ( i->hasSubItems() ) i->initChildren(); bool changed = MetaDataBase::isPropertyChanged( editor->widget(), i->name() ); if ( ( i->name() == "layoutSpacing" || i->name() == "layoutMargin" ) ) { if ( i->value().toString() != "-1" ) i->setChanged( TRUE, FALSE ); else i->setChanged( FALSE, FALSE ); } else if ( changed != i->isChanged() ) i->setChanged( changed, FALSE ); } updateEditorSize(); }
Qt::ItemFlags PropertyModel::flags(const QModelIndex &index) const { PropertyItem *item = static_cast<PropertyItem*>(index.internalPointer()); return item->flags(index.column()); }