/** * @brief EditEntityDialog::EditEntityDialog * @param parent */ EditEntityDialog::EditEntityDialog(QWidget *parent) : QDialog(parent) , ui(new Ui::EditEntityDialog) , m_EditMethodDialog(new EditMethodDialog(this)) , m_CommandsStack(new QUndoStack(this)) , m_ComponentsModel(std::make_shared<models::ComponentsModel>(nullptr)) { ui->setupUi(this); for(auto &&pair : names) ui->cbType->addItem(pair.first, QVariant::fromValue(pair.second)); for (auto &&p : componentsNames) itemByName(p.first, ui->lstMembers)->setData(int(ComponentCustomRoles::Single), p.second); for (auto &&p : display) itemByName(p.first, ui->lstMembers)->setData(int(ComponentCustomRoles::Display), QVariant::fromValue(p.second)); ui->lstMembers->setCurrentRow(0); ui->viewMembers->setModel(m_ComponentsModel.get()); auto componentsEditDelegat = new ComponentsEditDelegate(this); connect(componentsEditDelegat, &ComponentsEditDelegate::editButtonClicked, this, &EditEntityDialog::onEditComponentClicked); connect(componentsEditDelegat, &ComponentsEditDelegate::deleteButtonClicked, this, &EditEntityDialog::onDeleteComponentClicked); ui->viewMembers->setItemDelegateForColumn(models::ComponentsModel::Buttons, componentsEditDelegat); connect(m_ComponentsModel.get(), &models::ComponentsModel::showButtons, [view = ui->viewMembers](auto &&indexes) { for (auto &&index: indexes) { Q_ASSERT(index.isValid()); view->openPersistentEditor(index); } }); m_SignatureEditDelegate = std::make_unique<SignatureEditDelegate>(); ui->viewMembers->setItemDelegateForColumn(models::ComponentsModel::ShortSignature, m_SignatureEditDelegate.get()); QHeaderView * header = ui->viewMembers->horizontalHeader(); header->setSectionResizeMode(models::ComponentsModel::ShortSignature, QHeaderView::Stretch); header->setSectionResizeMode(models::ComponentsModel::Buttons, QHeaderView::Fixed); ui->viewMembers->setColumnWidth(models::ComponentsModel::Buttons, componentsEditDelegat->size().width()); connect(ui->pbAccept, &QPushButton::clicked, this, &EditEntityDialog::onAccepted); connect(ui->pbReject, &QPushButton::clicked, this, &EditEntityDialog::onRejected); connect(ui->pbCreateScope, &QPushButton::clicked, this, &EditEntityDialog::needNewScope); connect(ui->pbNewComponent, &QPushButton::clicked, this, &EditEntityDialog::onNewComponentClicked); connect(ui->lstMembers, &QListWidget::currentItemChanged, this, &EditEntityDialog::onCurrentItemChange); connect(m_CommandsStack.data(), &QUndoStack::canRedoChanged, ui->tbRedo, &QToolButton::setEnabled); connect(m_CommandsStack.data(), &QUndoStack::canUndoChanged, ui->tbUndo, &QToolButton::setEnabled); connect(ui->tbRedo, &QToolButton::clicked, m_CommandsStack.data(), &QUndoStack::redo); connect(ui->tbUndo, &QToolButton::clicked, m_CommandsStack.data(), &QUndoStack::undo); }
u32 SimpleXP3::extractFileToDisk(const s8* archiveFileName, const s8* saveDir) { SIndexItem* pItem = itemByName(archiveFileName); if (!pItem) return XP3_NOSUCHFILE; return itemToFile(pItem,saveDir); }
bool fsRead(const char *File,void *&Data, size_t &Size) { char Buf[220]=""; Data=NULL;Size=0; TarBlock *B = itemByName(File,true,Buf); if (!B) return false; Data=B->Info.Data; Size=B->Info.Size; return true; }
u32 SimpleXP3::extractFileToMemory(const s8* archiveFileName, void* dst, u32 size_dst, u32* size_file) { SIndexItem* pItem = itemByName(archiveFileName); if (!pItem || !dst || size_dst < pItem->sizeUncompressed) return XP3_INVALIDARGUMENT; if (!itemToMemory(pItem, (u8*)dst)) return XP3_NOTOK; *size_file = pItem->sizeUncompressed; return XP3_OK; }
VibesGraphicsItem * VibesScene2D::addJsonShapeItem(const QJsonObject &shape) { // The graphics item that will be created (will be null if creation fails) VibesGraphicsItem * item = 0; // The group to which the item will belong (will be null if no group specified, or if group does not exist) VibesGraphicsGroup * group = 0; // Contruct a new object from given type string if (shape.contains("type")) { QString type = shape["type"].toString(); item = VibesGraphicsItem::newWithType(type); } // Find the object parent group if specified if (shape.contains("group")) { QString groupName = shape["group"].toString(); group = vibesgraphicsitem_cast<VibesGraphicsGroup*>( itemByName(groupName) ); } // Try to initialize item with JSON if (!item->setJson(shape, dimX(), dimY())) { // Cannot set item wth the provided Json, delete item delete item; item = 0; } /* else { // Item successufully initialized, update dimension _nbDim = qMax(_nbDim, vibesItem->dimension()); } */ // If the item has successfully been created and initialized, put it on the scene if (item) { this->addVibesItem(item); // If the item belongs to a group, add it to the group if (group) { group->addToGroup(item); } } return item; }
void VibesScene2D::setItemName(VibesGraphicsItem *item, QString name) { // Unname previous item with the same name if (VibesGraphicsItem *old_item = itemByName(name)) { // Nothing to do if the name already points to the good item if (old_item != item) return; // Unname previous item old_item->setName(QString()); } // Update named items list if (!name.isEmpty()) { _namedItems[name] = item; } // Update new item if needed if (item && item->name() != name) { item->setName(name); } }
bool LuaList::itemByName(const std::string& name, LuaContainer*& container) { return itemByName(QString::fromStdString(name), container); }
u32 SimpleXP3::addFileFromMemory(const s8* archiveFileName, void* src, u32 size_src, bool compress) { if (archiveFileName == 0) { return XP3_INVALIDARGUMENT; } if (!m_pFile) { return XP3_NOTOPEN; } bool isPlaceholder = src == 0 || size_src == 0;//file is 0 bytes placeholder u64 segmentStart = ftell(m_pFile); u64 compressedSize = size_src; bool isCompressed = false; if (!isPlaceholder) { //seek to end of archive to write the new file fseek(m_pFile, 0, SEEK_END); if (compress) { //try compression u64 bufferSize = compressBound(size_src); unique_buffer<u8> pCompressed = unique_buffer<u8>(bufferSize); s32 res = compress2(pCompressed.get(), &bufferSize, (u8*)src, size_src, ZLIB_LEVEL); if (res != Z_OK) { //write the file uncompressed, if compression failed WRITE_ARRAY_DYN(m_pFile, src, size_src);//fwrite(src,size_src,1,m_pFile); } else { WRITE_ARRAY_DYN(m_pFile, pCompressed.get(), size_src); //fwrite(pCompressed,bufferSize,1,m_pFile); compressedSize = bufferSize; isCompressed = true; } } else { WRITE_ARRAY_DYN(m_pFile, src, size_src); } } SIndexItem item; u64 utf8Len = strlen(archiveFileName) + 1; u64 utf16Len = utf8ToUtf16le((s8*)archiveFileName, item.fileName, utf8Len, sizeof(item.fileName)); item.lenFilename = utf16Len/2; item.flags = 0; //don't bother with protection flag item.sizeUncompressed = size_src; item.sizeCompressed = compressedSize; item.adlrChk = computeAdler32(src, size_src); item.sizeAdlr = sizeof(item.adlrChk); //add segment(s) //TODO: implement multi-segment stuff? if (!isPlaceholder) { SIndexSegment segment; segment.flags = isCompressed ? SEGM_COMPRESSED : 0; segment.dataPos = segmentStart; segment.sizeUncompressed = size_src; segment.sizeCompressed = compressedSize; item.bytesToNextSect = sizeof(item.flags) + sizeof(item.sizeUncompressed) + sizeof(item.sizeCompressed) + sizeof(item.lenFilename) + item.lenFilename * 2; item.segments.push_back(segment); } item.sizeSegments = item.segments.size() * SIndexSegment::size; item.size = sizeof(item.infoStr) + sizeof(item.bytesToNextSect) + sizeof(item.flags) + sizeof(item.sizeUncompressed) + sizeof(item.sizeCompressed) + sizeof(item.lenFilename) + utf16Len + sizeof(item.segmStr) + sizeof(item.sizeSegments) + item.sizeSegments + sizeof(item.adlrStr) + sizeof(item.sizeAdlr) + sizeof(item.adlrChk); //replace item, if a file with the same name is already in the index //otherwise simply add the new item SIndexItem* pExisting = itemByName(archiveFileName); if (pExisting) { *pExisting = item; } else { m_items.push_back(item); } return XP3_OK; }