forked from qt-creator/qt-creator
Wizards: Add support for QSharedData.
This commit is contained in:
@@ -77,7 +77,8 @@ class QTCREATOR_UTILS_EXPORT NewClassWidget : public QWidget
|
|||||||
Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true)
|
Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true)
|
||||||
Q_ENUMS(ClassType)
|
Q_ENUMS(ClassType)
|
||||||
public:
|
public:
|
||||||
enum ClassType { NoClassType, ClassInheritsQObject, ClassInheritsQWidget };
|
enum ClassType { NoClassType, ClassInheritsQObject, ClassInheritsQWidget,
|
||||||
|
SharedDataClass };
|
||||||
|
|
||||||
explicit NewClassWidget(QWidget *parent = 0);
|
explicit NewClassWidget(QWidget *parent = 0);
|
||||||
~NewClassWidget();
|
~NewClassWidget();
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>418</width>
|
<width>431</width>
|
||||||
<height>291</height>
|
<height>291</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -68,6 +68,11 @@
|
|||||||
<string>Inherits QWidget</string>
|
<string>Inherits QWidget</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Based on QSharedData</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
|
@@ -262,12 +262,20 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
|
|||||||
headerStr << '\n';
|
headerStr << '\n';
|
||||||
Utils::writeIncludeFileDirective(baseClass, true, headerStr);
|
Utils::writeIncludeFileDirective(baseClass, true, headerStr);
|
||||||
}
|
}
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
||||||
|
headerStr << '\n';
|
||||||
|
Utils::writeIncludeFileDirective(QLatin1String("QSharedDataPointer"), true, headerStr);
|
||||||
|
}
|
||||||
|
|
||||||
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList, QString(), headerStr);
|
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList, QString(), headerStr);
|
||||||
|
|
||||||
|
const QString sharedDataClass = unqualifiedClassName + QLatin1String("Data");
|
||||||
|
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass)
|
||||||
|
headerStr << '\n' << "class " << sharedDataClass << ";\n";
|
||||||
|
|
||||||
// Class declaration
|
// Class declaration
|
||||||
headerStr << '\n';
|
headerStr << '\n' << namespaceIndent << "class " << unqualifiedClassName;
|
||||||
headerStr << namespaceIndent << "class " << unqualifiedClassName;
|
|
||||||
if (!baseClass.isEmpty())
|
if (!baseClass.isEmpty())
|
||||||
headerStr << " : public " << baseClass << "\n";
|
headerStr << " : public " << baseClass << "\n";
|
||||||
else
|
else
|
||||||
@@ -284,8 +292,21 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
|
|||||||
headerStr << "explicit " << unqualifiedClassName << '(' << parentQObjectClass
|
headerStr << "explicit " << unqualifiedClassName << '(' << parentQObjectClass
|
||||||
<< " *parent = 0);\n";
|
<< " *parent = 0);\n";
|
||||||
}
|
}
|
||||||
|
// Copy/Assignment for shared data classes.
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
||||||
|
headerStr << namespaceIndent << indent
|
||||||
|
<< unqualifiedClassName << "(const " << unqualifiedClassName << "&);\n"
|
||||||
|
<< namespaceIndent << indent
|
||||||
|
<< unqualifiedClassName << "& operator=(const " << unqualifiedClassName << "&);\n"
|
||||||
|
<< namespaceIndent << indent
|
||||||
|
<< '~' << unqualifiedClassName << "();\n";
|
||||||
|
}
|
||||||
if (defineQObjectMacro)
|
if (defineQObjectMacro)
|
||||||
headerStr << '\n' << namespaceIndent << "signals:\n\n" << namespaceIndent << "public slots:\n\n";
|
headerStr << '\n' << namespaceIndent << "signals:\n\n" << namespaceIndent << "public slots:\n\n";
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
||||||
|
headerStr << '\n' << namespaceIndent << "private:\n"
|
||||||
|
<< namespaceIndent << indent << "QSharedDataPointer<" << sharedDataClass << "> data;\n";
|
||||||
|
}
|
||||||
headerStr << namespaceIndent << "};\n";
|
headerStr << namespaceIndent << "};\n";
|
||||||
|
|
||||||
Utils::writeClosingNameSpaces(namespaceList, QString(), headerStr);
|
Utils::writeClosingNameSpaces(namespaceList, QString(), headerStr);
|
||||||
@@ -293,17 +314,29 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
|
|||||||
headerStr << '\n';
|
headerStr << '\n';
|
||||||
headerStr << "#endif // "<< guard << '\n';
|
headerStr << "#endif // "<< guard << '\n';
|
||||||
|
|
||||||
|
|
||||||
// == Source file ==
|
// == Source file ==
|
||||||
QTextStream sourceStr(source);
|
QTextStream sourceStr(source);
|
||||||
sourceStr << license;
|
sourceStr << license;
|
||||||
Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr);
|
Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr);
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass)
|
||||||
|
Utils::writeIncludeFileDirective(QLatin1String("QSharedData"), true, sourceStr);
|
||||||
|
|
||||||
Utils::writeOpeningNameSpaces(namespaceList, QString(), sourceStr);
|
Utils::writeOpeningNameSpaces(namespaceList, QString(), sourceStr);
|
||||||
|
// Private class:
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
||||||
|
sourceStr << '\n' << namespaceIndent << "class " << sharedDataClass
|
||||||
|
<< " : public QSharedData {\n"
|
||||||
|
<< namespaceIndent << "public:\n"
|
||||||
|
<< namespaceIndent << "};\n";
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
sourceStr << '\n' << namespaceIndent ;
|
sourceStr << '\n' << namespaceIndent;
|
||||||
if (parentQObjectClass.isEmpty()) {
|
if (parentQObjectClass.isEmpty()) {
|
||||||
sourceStr << unqualifiedClassName << "::" << unqualifiedClassName << "()\n";
|
sourceStr << unqualifiedClassName << "::" << unqualifiedClassName << "()";
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass)
|
||||||
|
sourceStr << " : data(new " << sharedDataClass << ')';
|
||||||
|
sourceStr << '\n';
|
||||||
} else {
|
} else {
|
||||||
sourceStr << unqualifiedClassName << "::" << unqualifiedClassName
|
sourceStr << unqualifiedClassName << "::" << unqualifiedClassName
|
||||||
<< '(' << parentQObjectClass << " *parent) :\n"
|
<< '(' << parentQObjectClass << " *parent) :\n"
|
||||||
@@ -311,7 +344,25 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
|
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
|
||||||
|
if (params.classType == Utils::NewClassWidget::SharedDataClass) {
|
||||||
|
// Copy
|
||||||
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "(const "
|
||||||
|
<< unqualifiedClassName << " &rhs) : data(rhs.data)\n"
|
||||||
|
<< namespaceIndent << "{\n" << namespaceIndent << "}\n\n";
|
||||||
|
// Assignment
|
||||||
|
sourceStr << namespaceIndent << unqualifiedClassName << " &"
|
||||||
|
<< unqualifiedClassName << "::operator=(const " << unqualifiedClassName << " &rhs)\n"
|
||||||
|
<< namespaceIndent << "{\n"
|
||||||
|
<< namespaceIndent << indent << "if (this != &rhs)\n"
|
||||||
|
<< namespaceIndent << indent << indent << "data.operator=(rhs.data);\n"
|
||||||
|
<< namespaceIndent << indent << "return *this;\n"
|
||||||
|
<< namespaceIndent << "}\n\n";
|
||||||
|
// Destructor
|
||||||
|
sourceStr << namespaceIndent << unqualifiedClassName << "::~"
|
||||||
|
<< unqualifiedClassName << "()\n"
|
||||||
|
<< namespaceIndent << "{\n"
|
||||||
|
<< namespaceIndent << "}\n";
|
||||||
|
}
|
||||||
Utils::writeClosingNameSpaces(namespaceList, QString(), sourceStr);
|
Utils::writeClosingNameSpaces(namespaceList, QString(), sourceStr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user