void QtDesignerChild::formFileBufferChanged() { QDesignerFormWindowInterface* form = mHostWidget->formWindow(); QRect rect = form->geometry(); rect.moveTopLeft( QPoint() ); form->cursor()->setWidgetProperty( form->mainContainer(), "geometry", rect ); }
void DsgnRibbonStatusBarPlugin::widgetManaged(QWidget* widget) { if (widget->metaObject()->className() == QString("Qtitan::RibbonStatusBar")) { QDesignerFormWindowInterface* formWindow = static_cast<QDesignerFormWindowInterface *>(sender()); QDesignerFormEditorInterface* core = formWindow->core(); QDesignerContainerExtension* container = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), formWindow->mainContainer()); formWindow->unmanageWidget(widget); QUndoStack* stack = formWindow->commandHistory(); if (!stack->isClean()) { //This code check the InsertWidget command on the stack. const QUndoCommand* command = stack->command(stack->index()); if (command->childCount() == 0) return; } if (qobject_cast<QMainWindow *>(formWindow->mainContainer()) == 0) { QMessageBox::critical( formWindow->mainContainer(), tr("Can't add Ribbon StatusBar"), tr("You can add Ribbon StatusBar onto Qtitan::RibbonMainWindow or QMainWindow only.")); widget->deleteLater(); return; } for (int i = 0; i < container->count(); ++i) { QWidget* w = container->widget(i); if (w->metaObject()->className() == QString("Qtitan::RibbonStatusBar") || w->metaObject()->className() == QString("QStatusBar")) { QMessageBox::critical( formWindow->mainContainer(), tr("Can't add Ribbon StatusBar"), tr("Only one instance of the Ribbon StatusBar can be adding to the main form.")); widget->deleteLater(); return; } } container->addWidget(widget); formWindow->core()->metaDataBase()->add(widget); } }
bool CreateButtonGroupCommand::init(const ButtonList &bl) { if (bl.empty()) return false; QDesignerFormWindowInterface *fw = formWindow(); QButtonGroup *buttonGroup = new QButtonGroup(fw->mainContainer()); buttonGroup->setObjectName(QLatin1String("buttonGroup")); fw->ensureUniqueObjectName(buttonGroup); initialize(bl, buttonGroup); return true; }
bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName) { if (Designer::Constants::Internal::debug) qDebug() << "FormWindowEditor::open" << fileName; QDesignerFormWindowInterface *form = d->m_file.formWindow(); QTC_ASSERT(form, return false); if (fileName.isEmpty()) { setDisplayName(tr("untitled")); return true; } const QFileInfo fi(fileName); const QString absfileName = fi.absoluteFilePath(); QString contents; if (d->m_file.read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess) return false; form->setFileName(absfileName); #if QT_VERSION >= 0x050000 const QByteArray contentsBA = contents.toUtf8(); QBuffer str; str.setData(contentsBA); str.open(QIODevice::ReadOnly); if (!form->setContents(&str, errorString)) return false; #else form->setContents(contents); if (!form->mainContainer()) return false; #endif form->setDirty(fileName != realFileName); syncXmlEditor(contents); setDisplayName(fi.fileName()); d->m_file.setFileName(absfileName); d->m_file.setShouldAutoSave(false); if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>()) rh->updateResources(); emit changed(); return true; }
bool FormWindowEditor::open(const QString &fileName) { if (Designer::Constants::Internal::debug) qDebug() << "FormWindowEditor::open" << fileName; QDesignerFormWindowInterface *form = d->m_file.formWindow(); QTC_ASSERT(form, return false); if (fileName.isEmpty()) { setDisplayName(tr("untitled")); return true; } const QFileInfo fi(fileName); const QString absfileName = fi.absoluteFilePath(); QFile file(absfileName); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) return false; form->setFileName(absfileName); const QString contents = QString::fromUtf8(file.readAll()); form->setContents(contents); file.close(); if (!form->mainContainer()) return false; form->setDirty(false); syncXmlEditor(contents); setDisplayName(fi.fileName()); d->m_file.setFileName(absfileName); if (Internal::ResourceHandler *rh = qFindChild<Designer::Internal::ResourceHandler*>(form)) rh->updateResources(); emit changed(); return true; }
bool QtCreatorIntegration::navigateToSlot(const QString &objectName, const QString &signalSignature, const QStringList ¶meterNames, QString *errorMessage) { typedef QMap<int, Document::Ptr> DocumentMap; const Utils::FileName currentUiFile = FormEditorW::activeEditor()->document()->filePath(); #if 0 return Designer::Internal::navigateToSlot(currentUiFile.toString(), objectName, signalSignature, parameterNames, errorMessage); #endif // TODO: we should pass to findDocumentsIncluding an absolute path to generated .h file from ui. // Currently we are guessing the name of ui_<>.h file and pass the file name only to the findDocumentsIncluding(). // The idea is that the .pro file knows if the .ui files is inside, and the .pro file knows it will // be generating the ui_<>.h file for it, and the .pro file knows what the generated file's name and its absolute path will be. // So we should somehow get that info from project manager (?) const QFileInfo fi = currentUiFile.toFileInfo(); const QString uiFolder = fi.absolutePath(); const QString uicedName = "ui_" + fi.completeBaseName() + ".h"; // Retrieve code model snapshot restricted to project of ui file or the working copy. Snapshot docTable = CppTools::CppModelManager::instance()->snapshot(); Snapshot newDocTable; const Project *uiProject = SessionManager::projectForFile(currentUiFile); if (uiProject) { for (Snapshot::const_iterator i = docTable.begin(), ei = docTable.end(); i != ei; ++i) { const Project *project = SessionManager::projectForFile(i.key()); if (project == uiProject) newDocTable.insert(i.value()); } } else { const CppTools::WorkingCopy workingCopy = CppTools::CppModelManager::instance()->workingCopy(); const Utils::FileName configFileName = Utils::FileName::fromString(CppTools::CppModelManager::configurationFileName()); QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator(); while (it.hasNext()) { it.next(); const Utils::FileName &fileName = it.key(); if (fileName != configFileName) newDocTable.insert(docTable.document(fileName)); } } docTable = newDocTable; // take all docs, find the ones that include the ui_xx.h. // Sort into a map, putting the ones whose path closely matches the ui-folder path // first in case there are project subdirectories that contain identical file names. const QList<Document::Ptr> docList = findDocumentsIncluding(docTable, uicedName, true); // change to false when we know the absolute path to generated ui_<>.h file DocumentMap docMap; for (const Document::Ptr &d : docList) { const QFileInfo docFi(d->fileName()); docMap.insert(qAbs(docFi.absolutePath().compare(uiFolder, Qt::CaseInsensitive)), d); } if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << objectName << signalSignature << "Looking for " << uicedName << " returned " << docList.size(); if (docMap.isEmpty()) { *errorMessage = tr("No documents matching \"%1\" could be found.\nRebuilding the project might help.").arg(uicedName); return false; } QDesignerFormWindowInterface *fwi = FormEditorW::activeWidgetHost()->formWindow(); const QString uiClass = uiClassName(fwi->mainContainer()->objectName()); if (Designer::Constants::Internal::debug) qDebug() << "Checking docs for " << uiClass; // Find the class definition (ui class defined as member or base class) // in the file itself or in the directly included files (order 1). QString namespaceName; const Class *cl = 0; Document::Ptr doc; for (const Document::Ptr &d : qAsConst(docMap)) { LookupContext context(d, docTable); const ClassDocumentPtrPair cd = findClassRecursively(context, uiClass, 1u , &namespaceName); if (cd.first) { cl = cd.first; doc = cd.second; break; } } if (!cl) { *errorMessage = msgClassNotFound(uiClass, docList); return false; } Overview o; const QString className = namespaceName + o.prettyName(cl->name()); if (Designer::Constants::Internal::debug) qDebug() << "Found class " << className << doc->fileName(); const QString functionName = "on_" + objectName + '_' + signalSignature; const QString functionNameWithParameterNames = addParameterNames(functionName, parameterNames); if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << "Found " << uiClass << doc->fileName() << " checking " << functionName << functionNameWithParameterNames; int line = 0; Document::Ptr sourceDoc; if (Function *fun = findDeclaration(cl, functionName)) { sourceDoc = findDefinition(fun, &line); if (!sourceDoc) { // add function definition to cpp file sourceDoc = addDefinition(docTable, doc->fileName(), className, functionNameWithParameterNames, &line); } } else { // add function declaration to cl CppTools::WorkingCopy workingCopy = CppTools::CppModelManager::instance()->workingCopy(); const QString fileName = doc->fileName(); getParsedDocument(fileName, workingCopy, docTable); addDeclaration(docTable, fileName, cl, functionNameWithParameterNames); // add function definition to cpp file sourceDoc = addDefinition(docTable, fileName, className, functionNameWithParameterNames, &line); } if (!sourceDoc) { *errorMessage = tr("Unable to add the method definition."); return false; } // jump to function definition, position within code Core::EditorManager::openEditorAt(sourceDoc->fileName(), line + 2, indentation); return true; }
bool QtCreatorIntegration::navigateToSlot(const QString &objectName, const QString &signalSignature, const QStringList ¶meterNames, QString *errorMessage) { const EditorData ed = m_few->activeEditor(); QTC_ASSERT(ed, return false) const QString currentUiFile = ed.formWindowEditor->file()->fileName(); #if 0 return Designer::Internal::navigateToSlot(currentUiFile, objectName, signalSignature, parameterNames, errorMessage); #endif // TODO: we should pass to findDocumentsIncluding an absolute path to generated .h file from ui. // Currently we are guessing the name of ui_<>.h file and pass the file name only to the findDocumentsIncluding(). // The idea is that the .pro file knows if the .ui files is inside, and the .pro file knows it will // be generating the ui_<>.h file for it, and the .pro file knows what the generated file's name and its absolute path will be. // So we should somehow get that info from project manager (?) const QFileInfo fi(currentUiFile); const QString uicedName = QLatin1String("ui_") + fi.completeBaseName() + QLatin1String(".h"); // Retrieve code model snapshot restricted to project of ui file. const ProjectExplorer::Project *uiProject = ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForFile(currentUiFile); if (!uiProject) { *errorMessage = tr("Internal error: No project could be found for %1.").arg(currentUiFile); return false; } CPlusPlus::Snapshot docTable = CppModelManagerInterface::instance()->snapshot(); CPlusPlus::Snapshot newDocTable; for (CPlusPlus::Snapshot::iterator it = docTable.begin(); it != docTable.end(); ++it) { const ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForFile(it.key()); if (project == uiProject) newDocTable.insert(it.value()); } docTable = newDocTable; // take all docs, find the ones that include the ui_xx.h. QList<Document::Ptr> docList = findDocumentsIncluding(docTable, uicedName, true); // change to false when we know the absolute path to generated ui_<>.h file if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << objectName << signalSignature << "Looking for " << uicedName << " returned " << docList.size(); if (docList.isEmpty()) { *errorMessage = tr("No documents matching '%1' could be found.\nRebuilding the project might help.").arg(uicedName); return false; } QDesignerFormWindowInterface *fwi = ed.widgetHost->formWindow(); const QString uiClass = uiClassName(fwi->mainContainer()->objectName()); if (Designer::Constants::Internal::debug) qDebug() << "Checking docs for " << uiClass; // Find the class definition (ui class defined as member or base class) // in the file itself or in the directly included files (order 1). QString namespaceName; const Class *cl = 0; Document::Ptr doc; foreach (const Document::Ptr &d, docList) { const ClassDocumentPtrPair cd = findClassRecursively(docTable, d, uiClass, 1u , &namespaceName); if (cd.first) { cl = cd.first; doc = cd.second; break; } } if (!cl) { *errorMessage = msgClassNotFound(uiClass, docList); return false; } Overview o; const QString className = namespaceName + o.prettyName(cl->name()); if (Designer::Constants::Internal::debug) qDebug() << "Found class " << className << doc->fileName(); const QString functionName = QLatin1String("on_") + objectName + QLatin1Char('_') + signalSignature; const QString functionNameWithParameterNames = addParameterNames(functionName, parameterNames); if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << "Found " << uiClass << doc->fileName() << " checking " << functionName << functionNameWithParameterNames; int line = 0; Document::Ptr sourceDoc; if (Function *fun = findDeclaration(cl, functionName)) { sourceDoc = findDefinition(fun, &line); if (!sourceDoc) { // add function definition to cpp file sourceDoc = addDefinition(docTable, doc->fileName(), className, functionNameWithParameterNames, &line); } } else { // add function declaration to cl CppModelManagerInterface::WorkingCopy workingCopy = CppModelManagerInterface::instance()->workingCopy(); const QString fileName = doc->fileName(); getParsedDocument(fileName, workingCopy, docTable); addDeclaration(docTable, fileName, cl, functionNameWithParameterNames); // add function definition to cpp file sourceDoc = addDefinition(docTable, fileName, className, functionNameWithParameterNames, &line); } if (!sourceDoc) { *errorMessage = tr("Unable to add the method definition."); return false; } // jump to function definition, position within code TextEditor::BaseTextEditorWidget::openEditorAt(sourceDoc->fileName(), line + 2, indentation); return true; }
void RibbonStyleDsgnPlugin::widgetManaged(QWidget* widget) { QDesignerFormWindowInterface* formWindow = static_cast<QDesignerFormWindowInterface *>(sender()); QDesignerFormEditorInterface* core = formWindow->core(); QDesignerContainerExtension* container = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), formWindow->mainContainer()); if (widget->metaObject()->className() == QString("Qtitan::RibbonStyle")) { formWindow->unmanageWidget(widget); QUndoStack* stack = formWindow->commandHistory(); if (!stack->isClean()) { //This code check the InsertWidget command on the stack. const QUndoCommand* command = stack->command(stack->index()); if (command->childCount() == 0) return; } if (qobject_cast<QMainWindow *>(formWindow->mainContainer()) == 0) { QMessageBox::critical(formWindow->mainContainer(), tr("Can't add Ribbon Style"), tr("You can't drag-drop the style to this QWidget form. The style can be placed only onto the form of QMainWindow successor.")); widget->deleteLater(); return; } QWidget* widgetStyle = Q_NULL; for (int i = 0; i < container->count() && widgetStyle == Q_NULL; ++i) { QWidget* w = container->widget(i); if (w->metaObject()->className() == QString("Qtitan::OfficeStyle") || w->metaObject()->className() == QString("Qtitan::RibbonStyle")) widgetStyle = w; } if (widgetStyle && widgetStyle->metaObject()->className() == QString("Qtitan::RibbonStyle")) { QMessageBox::critical( formWindow->mainContainer(), tr("Can't add Ribbon Style"), tr("Only one instance of the Ribbon Style can be adding to the main form.")); widget->deleteLater(); return; } if (widgetStyle) { g_removeBlock = true; const QString description = tr("Delete '%1'").arg(widgetStyle->objectName()); formWindow->commandHistory()->beginMacro(description); DeleteStyleCommand* cmd = new DeleteStyleCommand(formWindow); cmd->init(widgetStyle); formWindow->commandHistory()->push(cmd); formWindow->commandHistory()->endMacro(); g_removeBlock = false; } container->addWidget(widget); formWindow->core()->metaDataBase()->add(widget); widget->setCursor(Qt::PointingHandCursor); } else if (DesignerMainWindowStyleContainer* styelContainer = dynamic_cast<DesignerMainWindowStyleContainer*>(container)) { if (QMainWindow* mainindow = static_cast<QMainWindow*>(styelContainer->mainWindow())) { if (Qtitan::CommonStyle* currentStyle = qobject_cast<Qtitan::CommonStyle*>(mainindow->style())) ::setChildStyle(widget, currentStyle); } } }
bool DsgnOfficeStyleWidget::event(QEvent* event) { bool res = QWidget::event(event); if (event->type() == QEvent::ParentChange) { if (DsgnOfficeStyle* desStyle = dynamic_cast<DsgnOfficeStyle *>(m_targetStyle)) desStyle->setParentStyle(parentWidget()); } else if (event->type() == QEvent::Hide && isHidden()) { QDesignerFormWindowInterface* formWindow = QDesignerFormWindowInterface::findFormWindow(parentWidget()); QDesignerFormEditorInterface* core = formWindow->core(); QDesignerContainerExtension* container = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), formWindow->mainContainer()); if (container->widget(container->count() - 1) == this) { container->remove(container->count() - 1); core->metaDataBase()->remove(this); formWindow->emitSelectionChanged(); } } return res; }