Skip to content

Commit

Permalink
Updated deprecated sprintf() in copyimpl.cpp
Browse files Browse the repository at this point in the history
Converted sprintf to use QString().arg(). And other general code cleaning.
  • Loading branch information
alanspencer committed Apr 14, 2020
1 parent 70f0749 commit 2cf2a93
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 73 deletions.
Binary file modified .DS_Store
Binary file not shown.
179 changes: 106 additions & 73 deletions SPIERSedit/src/copyingimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
#include <QListWidget>
#include <QFileDialog>
#include <QShortcut>
//#include <zlib.h>


/**
* @brief CopyingImpl::CopyingImpl
* @param parent
* @param f
*/
CopyingImpl::CopyingImpl(QWidget *parent, Qt::WindowFlags f)
: QDialog(parent, f)
{
Expand All @@ -50,6 +53,10 @@ CopyingImpl::CopyingImpl(QWidget *parent, Qt::WindowFlags f)

}

/**
* @brief CopyingImpl::closeEvent
* @param event
*/
void CopyingImpl::closeEvent(QCloseEvent *event)
{
// in case close button hit
Expand All @@ -59,7 +66,11 @@ void CopyingImpl::closeEvent(QCloseEvent *event)
event->accept();
}


/**
* @brief CopyingImpl::Copy
* @param source
* @param dest
*/
void CopyingImpl::Copy(QDir source, QDir dest)
{
//this does file copying
Expand Down Expand Up @@ -176,15 +187,16 @@ void CopyingImpl::Copy(QDir source, QDir dest)

}

/**
* @brief CopyingImpl::MakeNewSegFiles create new files - snum is the new segment index (add 1 for filename index)
* @param snum
*/
void CopyingImpl::MakeNewSegFiles(int snum)
//create new files - snum is the new segment index (add 1 for filename index)
{
show();
this->setWindowTitle("Creating Files...");
copying = true;
progressBar->setMaximum(Files.count());

int lastsep, lastdot;
progressBar->setMaximum(Files.count());

QImage tempimage(fwidth, fheight, QImage::Format_Indexed8);

Expand All @@ -195,23 +207,20 @@ void CopyingImpl::MakeNewSegFiles(int snum)

tempimage.setColorTable(ctable);
tempimage.setColor(0, 1);

tempimage.fill(0);

int lastsep, lastdot;
for (int i = 0; i < Files.count(); i++)
{
QString Fname = Files.at(i);
lastsep = qMax(Fname.lastIndexOf("\\"), Fname.lastIndexOf("/")); //this is last separator in path
lastdot = Fname.lastIndexOf(".");
QString sfname = Fname.left(lastsep);
QString actfn = Fname.mid(lastsep + 1, lastdot - lastsep - 1);
QString temp = "/" + SettingsFileName + "/" + "s";
QString t2;
t2.sprintf("%d_", snum + 1);
temp.append(t2);
temp.append(actfn);
temp.append(".bmp");
sfname.append(temp);

QString sfname = QString("%1/%2/s%3_%4.bmp")
.arg(Fname.left(lastsep))
.arg(SettingsFileName)
.arg(snum + 1)
.arg(Fname.mid(lastsep + 1, lastdot - lastsep - 1));

tempimage.save(sfname);
progressBar->setValue(i);
Expand All @@ -222,6 +231,10 @@ void CopyingImpl::MakeNewSegFiles(int snum)
return;
}

/**
* @brief CopyingImpl::DeleteSegments
* @param list
*/
void CopyingImpl::DeleteSegments(QList <int> list)
{
//1. Assemble a before and after list
Expand Down Expand Up @@ -260,16 +273,13 @@ void CopyingImpl::DeleteSegments(QList <int> list)
QString Fname = FullFiles.at(i);
lastsep = qMax(Fname.lastIndexOf("\\"), Fname.lastIndexOf("/")); //this is last separator in path
lastdot = Fname.lastIndexOf(".");
QString sfname = Fname.left(lastsep);
QString actfn = Fname.mid(lastsep + 1, lastdot - lastsep - 1);
QString temp = "/" + SettingsFileName + "/" + "s";
QString t2;
t2.sprintf("%d_", seg + 1);
temp.append(t2);
temp.append(actfn);

//temp.append(".bmp");
sfname.append(temp); //sfname is now from name WITHOUT extension
// sfname is now from name WITHOUT extension
QString sfname = QString("%1/%2/s%3_%4")
.arg(Fname.left(lastsep))
.arg(SettingsFileName)
.arg(seg + 1)
.arg(Fname.mid(lastsep + 1, lastdot - lastsep - 1));

bool png = false;
QFile oldfile(sfname + ".bmp");
Expand All @@ -287,22 +297,25 @@ void CopyingImpl::DeleteSegments(QList <int> list)
}
else
{
//rename
// Rename
int lastsep, lastdot;
QString Fname = FullFiles.at(i);
lastsep = qMax(Fname.lastIndexOf("\\"), Fname.lastIndexOf("/")); //this is last separator in path
lastdot = Fname.lastIndexOf(".");
QString sfname2 = Fname.left(lastsep);
QString actfn = Fname.mid(lastsep + 1, lastdot - lastsep - 1);
QString temp = "/" + SettingsFileName + "/" + "s";
QString t2;
t2.sprintf("%d_", ToSegs[seg] + 1);
temp.append(t2);
temp.append(actfn); // temp.append(".bmp");
sfname2.append(temp); //sfname2 is now to name
if (png) sfname2.append(".png");
else sfname2.append(".bmp");
if (!oldfile.rename(sfname2)) Error("Failed to rename segment file from " + sfname + " to " + sfname2);

QString sfname2 = QString("%1/%2/s%3_%4")
.arg(Fname.left(lastsep))
.arg(SettingsFileName)
.arg(ToSegs[seg] + 1)
.arg(Fname.mid(lastsep + 1, lastdot - lastsep - 1));

if (png)
sfname2.append(".png");
else
sfname2.append(".bmp");

if (!oldfile.rename(sfname2))
Error("Failed to rename segment file from " + sfname + " to " + sfname2);
}
}
}
Expand Down Expand Up @@ -351,6 +364,10 @@ void CopyingImpl::DeleteSegments(QList <int> list)
close();
}

/**
* @brief CopyingImpl::GenerateLinear
* @param SliceSelectorList
*/
void CopyingImpl::GenerateLinear(QListWidget *SliceSelectorList)
{
int c = SliceSelectorList->selectedItems().count();
Expand All @@ -371,7 +388,10 @@ void CopyingImpl::GenerateLinear(QListWidget *SliceSelectorList)
if (c > 1) close();
}


/**
* @brief CopyingImpl::GeneratePoly
* @param SliceSelectorList
*/
void CopyingImpl::GeneratePoly(QListWidget *SliceSelectorList)
{
int c = SliceSelectorList->selectedItems().count();
Expand All @@ -391,6 +411,10 @@ void CopyingImpl::GeneratePoly(QListWidget *SliceSelectorList)
if (c > 1) close();
}

/**
* @brief CopyingImpl::GenerateRange
* @param SliceSelectorList
*/
void CopyingImpl::GenerateRange(QListWidget *SliceSelectorList)
{
int c = SliceSelectorList->selectedItems().count();
Expand All @@ -413,8 +437,9 @@ void CopyingImpl::GenerateRange(QListWidget *SliceSelectorList)
if (c > 1) close();
}



/**
* @brief CopyingImpl::GenerateAllLinear
*/
void CopyingImpl::GenerateAllLinear()
{

Expand All @@ -436,6 +461,9 @@ void CopyingImpl::GenerateAllLinear()
close();
}

/**
* @brief CopyingImpl::GenerateAllBlank
*/
void CopyingImpl::GenerateAllBlank()
{

Expand All @@ -457,7 +485,12 @@ void CopyingImpl::GenerateAllBlank()
close();
}


/**
* @brief CopyingImpl::ReverseStretches
* @param stretches
* @param Sstart
* @param Sstop
*/
void CopyingImpl::ReverseStretches(QList <double> *stretches, int Sstart, int Sstop)
{
int n;
Expand All @@ -477,6 +510,11 @@ void CopyingImpl::ReverseStretches(QList <double> *stretches, int Sstart, int Ss
}
}

/**
* @brief CopyingImpl::DoIHaveChildren
* @param parent
* @return
*/
bool CopyingImpl::DoIHaveChildren(int parent)
//Yes, I do!
{
Expand All @@ -489,32 +527,11 @@ bool CopyingImpl::DoIHaveChildren(int parent)
return false;
}

//OLD VERSION (QByteArray QList)
/*
void CopyingImpl::WriteSPVData(QList <QByteArray *> fullarray, QVector<double>*TrigArray, int TrigCount, QDataStream *out)
//output data to the file
{
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
//do a count of on pixels in fullarray
(*out)<<fullarray.count(); //commence with number of fullarrays to decompress - though should know this already
for (int i=0; i<fullarray.count(); i++)
{
(*out)<<fullarray[i]->size()-4;
//Strip off 4 byte header and write
out->writeRawData((fullarray[i]->constData())+4,fullarray[i]->size()-4);
}
//and output any triangles
(*out)<<TrigCount;
for (int z=0; z<TrigCount; z++)
(*out) <<(*TrigArray)[z];
}
*/


/**
* @brief CopyingImpl::MaskCopy
* @param fromfile
* @param mw
*/
void CopyingImpl::MaskCopy(int fromfile, MainWindowImpl *mw)
{
bool IsShow = false;
Expand Down Expand Up @@ -575,6 +592,11 @@ void CopyingImpl::MaskCopy(int fromfile, MainWindowImpl *mw)
}
}

/**
* @brief CopyingImpl::MaskCopy2
* @param fromfile
* @param mw
*/
void CopyingImpl::MaskCopy2(int fromfile, MainWindowImpl *mw) //this is copy from selected TO currentfile
{
QList <QTreeWidgetItem *> selitems = mw->MasksTreeWidget->selectedItems();
Expand Down Expand Up @@ -602,6 +624,10 @@ void CopyingImpl::MaskCopy2(int fromfile, MainWindowImpl *mw) //this is copy fro
}
}

/**
* @brief CopyingImpl::CurvesToMasks
* @param mw
*/
void CopyingImpl::CurvesToMasks(MainWindowImpl *mw) //create a mask from a curve
{
QList <QTreeWidgetItem *> selitems = mw->CurvesTreeWidget->selectedItems();
Expand Down Expand Up @@ -670,7 +696,10 @@ void CopyingImpl::CurvesToMasks(MainWindowImpl *mw) //create a mask from a curve
}
}


/**
* @brief CopyingImpl::CompressAllWorkingFiles
* @param level
*/
void CopyingImpl::CompressAllWorkingFiles(int level)
{
int before = FileCompressionLevel;
Expand Down Expand Up @@ -702,6 +731,10 @@ void CopyingImpl::CompressAllWorkingFiles(int level)
copying = false;
}

/**
* @brief CopyingImpl::CompressAllSourceFiles
* @param level
*/
void CopyingImpl::CompressAllSourceFiles(int level)
{
show();
Expand Down Expand Up @@ -761,9 +794,6 @@ void CopyingImpl::CompressAllSourceFiles(int level)

if (level == 0) imageGS.save(sfname, "BMP", 0);
if (level == 1) imageGS.save(sfname, "PNG", 50);
if (level == 2) imageGS.save(sfname, "JPG", 100);
// image=image.convertToFormat(QImage::Format_Indexed8);
// if (!(image.isGrayscale())) qDebug()<<"Ooops, conversion somehow didn't produce a greyscale";
}
else
{
Expand Down Expand Up @@ -806,6 +836,10 @@ void CopyingImpl::CompressAllSourceFiles(int level)
WriteSettings();
}

/**
* @brief CopyingImpl::Apply3DBrush
* @param button
*/
void CopyingImpl::Apply3DBrush(int button)
{
show();
Expand Down Expand Up @@ -892,5 +926,4 @@ void CopyingImpl::Apply3DBrush(int button)
copying = false;
LoadAllData(CurrentFile);
Brush.resize(Brush_Size, 2, 0);

}

0 comments on commit 2cf2a93

Please sign in to comment.