fixed bug in NameDisambiguator, made label name checking more coherent between project loading / mesh loading / mesh creation

TO BE TESTED
This commit is contained in:
Marco Callieri mcallieri 2012-05-25 12:50:32 +00:00
parent ff0686e2ac
commit ecfeaee1d7
2 changed files with 31 additions and 12 deletions

View File

@ -140,24 +140,42 @@ void MeshDocument::setCurrentRaster( int i)
template <class LayerElement>
QString NameDisambiguator(QList<LayerElement*> &elemList, QString meshLabel )
{
QFileInfo info(meshLabel);
QString newName=info.fileName();
QString newName=meshLabel;
typename QList<LayerElement*>::iterator mmi;
for(mmi=elemList.begin(); mmi!=elemList.end(); ++mmi)
{
if((*mmi)->label() == newName)
if((*mmi)->label() == newName) // if duplicated name found
{
QFileInfo fi((*mmi)->label());
QString baseName = fi.baseName(); // all characters in the file up to the first '.' Eg "/tmp/archive.tar.gz" -> "archive"
int lastNum = baseName.right(1).toInt();
if( baseName.right(2).toInt() >= 10)
lastNum = baseName.right(2).toInt();
if(lastNum)
newName = baseName.left(baseName.length()-(lastNum<10?1:2))+QString::number(lastNum+1);
QString suffix = fi.suffix();
bool ok;
// if name ends with a number between parenthesis (XXX),
// it was himself a duplicated name, and we need to
// just increase the number between parenthesis
int numDisamb;
int startDisamb;
int endDisamb;
startDisamb = baseName.lastIndexOf("(");
endDisamb = baseName.lastIndexOf(")");
if((startDisamb!=-1)&&(endDisamb!=-1))
numDisamb = (baseName.mid((startDisamb+1),(endDisamb-startDisamb-1))).toInt(&ok);
else
newName = baseName+"_1";
if (info.suffix() != QString(""))
newName = newName + "." + info.suffix();
numDisamb = 0;
if(startDisamb!=-1)
newName = baseName.left(startDisamb)+ "(" + QString::number(numDisamb+1) + ")";
else
newName = baseName + "(" + QString::number(numDisamb+1) + ")";
if (suffix != QString(""))
newName = newName + "." + suffix;
// now recurse to see if the new name is free
newName = NameDisambiguator(elemList, newName);
}
}
return newName;

View File

@ -2065,7 +2065,8 @@ bool MainWindow::importMesh(QString fileName)
}
int mask = 0;
//MeshModel *mm= new MeshModel(gla->meshDoc);
MeshModel *mm=meshDoc()->addNewMesh(qPrintable(fileName),"");
QFileInfo info(fileName);
MeshModel *mm=meshDoc()->addNewMesh(qPrintable(fileName),info.fileName());
qb->show();
QTime t;t.start();
bool open = loadMesh(fileName,pCurrentIOPlugin,mm,mask,&prePar);