本文整理汇总了C++中CodeGenerationPolicy::getOverwritePolicy方法的典型用法代码示例。如果您正苦于以下问题:C++ CodeGenerationPolicy::getOverwritePolicy方法的具体用法?C++ CodeGenerationPolicy::getOverwritePolicy怎么用?C++ CodeGenerationPolicy::getOverwritePolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGenerationPolicy
的用法示例。
在下文中一共展示了CodeGenerationPolicy::getOverwritePolicy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: overwritableName
/**
* Check if a file named "name" with extension "ext" already exists.
* @param concept the package
* @param name the name of the file
* @param ext the extension of the file
* @return the valid filename or null
*/
QString SimpleCodeGenerator::overwritableName(UMLPackage* concept, const QString &name, const QString &ext)
{
CodeGenerationPolicy *commonPolicy = UMLApp::app()->commonPolicy();
QDir outputDir = commonPolicy->getOutputDirectory();
QString filename = name + ext;
if(!outputDir.exists(filename)) {
m_fileMap.insert(concept,filename);
return filename; //if not, "name" is OK and we have not much to to
}
int suffix;
QPointer<OverwriteDialogue> overwriteDialogue =
new OverwriteDialogue(filename, outputDir.absolutePath(),
m_applyToAllRemaining, kapp->activeWindow());
switch(commonPolicy->getOverwritePolicy()) { //if it exists, check the OverwritePolicy we should use
case CodeGenerationPolicy::Ok: //ok to overwrite file
break;
case CodeGenerationPolicy::Ask: //ask if we can overwrite
switch(overwriteDialogue->exec()) {
case KDialog::Yes: //overwrite file
if ( overwriteDialogue->applyToAllRemaining() ) {
commonPolicy->setOverwritePolicy(CodeGenerationPolicy::Ok);
} else {
m_applyToAllRemaining = false;
}
break;
case KDialog::No: //generate similar name
suffix = 1;
while (1) {
filename = name + "__" + QString::number(suffix) + ext;
if (!outputDir.exists(filename))
break;
suffix++;
}
if ( overwriteDialogue->applyToAllRemaining() ) {
commonPolicy->setOverwritePolicy(CodeGenerationPolicy::Never);
} else {
m_applyToAllRemaining = false;
}
break;
case KDialog::Cancel: //don't output anything
if ( overwriteDialogue->applyToAllRemaining() ) {
commonPolicy->setOverwritePolicy(CodeGenerationPolicy::Cancel);
} else {
m_applyToAllRemaining = false;
}
delete overwriteDialogue;
return QString();
break;
}
break;
case CodeGenerationPolicy::Never: //generate similar name
suffix = 1;
while (1) {
filename = name + "__" + QString::number(suffix) + ext;
if (!outputDir.exists(filename))
break;
suffix++;
}
break;
case CodeGenerationPolicy::Cancel: //don't output anything
delete overwriteDialogue;
return QString();
break;
}
m_fileMap.insert(concept, filename);
delete overwriteDialogue;
return filename;
}