QWidget* SongAttributeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { CellEditor* editor = NULL; QString classname = QString("%1Editor").arg(editorType(index)); if (Creatable::category(classname) != "CellEditor") { if (classname != "Editor") { // default to StringEditor without warning WARNING << "Unknown editor widget \"" << classname << "\"."; } classname = "StringEditor"; } editor = static_cast<CellEditor*>( Creatable::create( classname ) ); editor->setParent(parent); editor->setStyleOption(option); editor->setIndex(index); editor->setModel(SongAttributeDelegate::parent()->proxyModel()); editor->setCurrentData( proxyModel()->data( index, Qt::EditRole ) ); editor->polish(); editor->setFocus(); return editor; }
bool ctConfigToolDoc::DoOpen(wxSimpleHtmlTag* tag, ctConfigItem* parent) { ctConfigItem* newItem = NULL; if (tag->NameIs(wxT("setting"))) { wxSimpleHtmlAttribute* attr = tag->FindAttribute(wxT("type")); if (attr) { ctConfigType type = ctTypeUnknown; wxString typeStr(attr->GetValue()); if (typeStr == wxT("group")) type = ctTypeGroup; else if (typeStr == wxT("option-group") || typeStr == wxT("check-group")) type = ctTypeCheckGroup; else if (typeStr == wxT("radio-group")) type = ctTypeRadioGroup; else if (typeStr == wxT("bool-check")) type = ctTypeBoolCheck; else if (typeStr == wxT("bool-radio")) type = ctTypeBoolRadio; else if (typeStr == wxT("string")) type = ctTypeString; else if (typeStr == wxT("integer")) type = ctTypeInteger; else { wxLogError(wxT("Unknown type %s"), (const wxChar*) typeStr); } if (type != ctTypeUnknown) { newItem = new ctConfigItem(parent, type, wxT("")); newItem->InitProperties(); if (!parent) SetTopItem(newItem); } } } wxSimpleHtmlTag* childTag = tag->GetChildren(); while (childTag) { if (childTag->GetType() == wxSimpleHtmlTag_Open) { if (childTag->GetName() == wxT("setting")) { DoOpen(childTag, newItem); } else if (childTag->GetName() == wxT("name")) { if (newItem) { wxString name(childTag->GetNext()->GetTagText()); newItem->SetName(name); } } else if (childTag->GetName() == wxT("active")) { if (newItem) newItem->SetActive(GetHtmlBoolValue(childTag->GetNext()->GetTagText())); } else if (childTag->GetName() == wxT("enabled")) { if (newItem) newItem->Enable(GetHtmlBoolValue(childTag->GetNext()->GetTagText())); } else { if (newItem) { ctProperty* prop = newItem->GetProperties().FindProperty(childTag->GetName()); if (!prop) { // A custom property, else an obsolete // property that we should ignore. wxString isCustom; if (childTag->GetAttributeValue(isCustom, wxT("custom")) && isCustom == wxT("true")) { prop = new ctProperty; wxString name(childTag->GetName()); wxString type(wxT("string")); wxString choices; wxString editorType(wxT("string")); wxString description(wxT("")); childTag->GetAttributeValue(type, wxT("type")); childTag->GetAttributeValue(type, wxT("editor-type")); childTag->GetAttributeValue(type, wxT("choices")); childTag->GetAttributeValue(description, wxT("description")); if (type == wxT("bool")) prop->GetVariant() = wxVariant(false, name); else if (type == wxT("double")) prop->GetVariant() = wxVariant((double) 0.0, name); else if (type == wxT("long")) prop->GetVariant() = wxVariant((long) 0, name); else prop->GetVariant() = wxVariant(wxT(""), name); prop->SetDescription(description); prop->SetCustom(true); prop->SetEditorType(editorType); if (!choices.IsEmpty()) { wxArrayString arr; ctConfigItem::StringToArray(choices, arr); prop->SetChoices(arr); } newItem->GetProperties().AddProperty(prop); } } if (prop) { if (prop->GetVariant().GetType() == wxT("string")) prop->GetVariant() = childTag->GetNext()->GetTagText(); else if (prop->GetVariant().GetType() == wxT("long")) prop->GetVariant() = (long) GetHtmlIntegerValue(childTag->GetNext()->GetTagText()); else if (prop->GetVariant().GetType() == wxT("bool")) prop->GetVariant() = GetHtmlBoolValue(childTag->GetNext()->GetTagText()); else if (prop->GetVariant().GetType() == wxT("double")) prop->GetVariant() = (double) GetHtmlDoubleValue(childTag->GetNext()->GetTagText()); } } } } childTag = childTag->GetNext(); } return true; }