Index: kstars/fitsviewer/fitsdata.h =================================================================== --- kstars/fitsviewer/fitsdata.h +++ kstars/fitsviewer/fitsdata.h @@ -73,7 +73,7 @@ { Q_OBJECT public: - explicit FITSSkyObject(SkyObject *skyObject, int xPos, int yPos); + explicit FITSSkyObject(SkyObject *object, int xPos, int yPos); SkyObject *skyObject(); int x(); int y(); @@ -89,14 +89,14 @@ class FITSData { public: - explicit FITSData(FITSMode mode = FITS_NORMAL); + explicit FITSData(FITSMode fitsMode = FITS_NORMAL); explicit FITSData(const FITSData *other); ~FITSData(); /* Loads FITS image, scales it, and displays it in the GUI */ - bool loadFITS(const QString &filename, bool silent = true); + bool loadFITS(const QString &inFilename, bool silent = true); /* Save FITS */ - int saveFITS(const QString &filename); + int saveFITS(const QString &newFilename); /* Rescale image lineary from image_buffer, fit to window if desired */ int rescale(FITSZoom type); /* Calculate stats */ Index: kstars/fitsviewer/fitsdata.cpp =================================================================== --- kstars/fitsviewer/fitsdata.cpp +++ kstars/fitsviewer/fitsdata.cpp @@ -36,7 +36,8 @@ #include #endif -#include +#include +#include #include @@ -98,7 +99,7 @@ if (objList.count() > 0) qDeleteAll(objList); - if (fptr) + if (fptr != nullptr) { fits_close_file(fptr, &status); @@ -117,7 +118,7 @@ qDeleteAll(starCenters); starCenters.clear(); - if (fptr) + if (fptr != nullptr) { fits_close_file(fptr, &status); @@ -154,7 +155,7 @@ fits_report_error(stderr, status); fits_get_errstatus(status, error_status); errMessage = i18n("Could not open file %1. Error %2", filename, QString::fromUtf8(error_status)); - if (silent == false) + if (!silent) KSNotification::error(errMessage, i18n("FITS Open")); qCCritical(KSTARS_FITS) << errMessage; return false; @@ -165,7 +166,7 @@ fits_report_error(stderr, status); fits_get_errstatus(status, error_status); errMessage = i18n("Could not locate image HDU. Error %2", QString::fromUtf8(error_status)); - if (silent == false) + if (!silent) KSNotification::error(errMessage, i18n("FITS Open")); qCCritical(KSTARS_FITS) << errMessage; return false; @@ -176,7 +177,7 @@ fits_report_error(stderr, status); fits_get_errstatus(status, error_status); errMessage = i18n("FITS file open error (fits_get_img_param): %1", QString::fromUtf8(error_status)); - if (silent == false) + if (!silent) KSNotification::error(errMessage, i18n("FITS Open")); qCCritical(KSTARS_FITS) << errMessage; return false; @@ -185,7 +186,7 @@ if (stats.ndim < 2) { errMessage = i18n("1D FITS images are not supported in KStars."); - if (silent == false) + if (!silent) KSNotification::error(errMessage, i18n("FITS Open")); qCCritical(KSTARS_FITS) << errMessage; return false; @@ -229,7 +230,7 @@ break; default: errMessage = i18n("Bit depth %1 is not supported.", stats.bitpix); - if (silent == false) + if (!silent) KSNotification::error(errMessage, i18n("FITS Open")); qCCritical(KSTARS_FITS) << errMessage; return false; @@ -242,7 +243,7 @@ if (naxes[0] == 0 || naxes[1] == 0) { errMessage = i18n("Image has invalid dimensions %1x%2", naxes[0], naxes[1]); - if (silent == false) + if (!silent) KSNotification::error(errMessage, i18n("FITS Open")); qCCritical(KSTARS_FITS) << errMessage; return false; @@ -257,7 +258,7 @@ channels = naxes[2]; // Channels always set to #1 if we are not required to process 3D Cubes - if (Options::auto3DCube() == false) + if (!Options::auto3DCube()) channels = 1; //image_buffer = new float[stats.samples_per_channel * channels]; @@ -276,12 +277,12 @@ flipVCounter = 0; long nelements = stats.samples_per_channel * channels; - if (fits_read_img(fptr, data_type, 1, nelements, 0, imageBuffer, &anynull, &status)) + if (fits_read_img(fptr, data_type, 1, nelements, nullptr, imageBuffer, &anynull, &status)) { char errmsg[512]; fits_get_errstatus(status, errmsg); errMessage = i18n("Error reading image: %1", QString(errmsg)); - if (silent == false) + if (!silent) KSNotification::error(errMessage, i18n("FITS Open")); fits_report_error(stderr, status); qCCritical(KSTARS_FITS) << errMessage; @@ -333,7 +334,7 @@ // Remove first otherwise copy will fail below if file exists QFile::remove(finalFileName); - if (QFile::copy(filename, finalFileName) == false) + if (!QFile::copy(filename, finalFileName)) { qCCritical(KSTARS_FITS()) << "FITS: Failed to copy " << filename << " to " << finalFileName; fptr = nullptr; @@ -466,7 +467,7 @@ if (flipHCounter % 2 != 0 || flipVCounter % 2 != 0) mirror = 1; - if (rot || mirror) + if ((rot != 0) || (mirror != 0)) rotWCSFITS(rot, mirror); rotCounter = flipHCounter = flipVCounter = 0; @@ -551,7 +552,7 @@ status = 0; - if (fptr && refresh == false) + if ((fptr != nullptr) && !refresh) { if (fits_read_key_dbl(fptr, "DATAMIN", &(stats.min[0]), nullptr, &status) == 0) nfound++; @@ -618,7 +619,7 @@ template QPair FITSData::getParitionMinMax(uint32_t start, uint32_t stride) { - T *buffer = reinterpret_cast(imageBuffer); + auto *buffer = reinterpret_cast(imageBuffer); T min = std::numeric_limits::max(); T max = std::numeric_limits::min(); @@ -735,7 +736,7 @@ uint32_t m_n = 2; double m_oldM = 0, m_newM = 0, m_oldS = 0, m_newS = 0; - T *buffer = reinterpret_cast(imageBuffer); + auto *buffer = reinterpret_cast(imageBuffer); uint32_t end = start + stride; for (uint32_t i = start; i < end; i++) @@ -1012,7 +1013,7 @@ uint32_t offset = subX + subY * dataWidth; // #2 Create new buffer - uint8_t *buffer = new uint8_t[size * BBP]; + auto *buffer = new uint8_t[size * BBP]; // If there is no offset, copy whole buffer in one go if (offset == 0) memcpy(buffer, data->getImageBuffer(), size * BBP); @@ -1031,7 +1032,7 @@ } // #3 Create new FITSData to hold it - FITSData *boundedImage = new FITSData(); + auto *boundedImage = new FITSData(); boundedImage->stats.width = subW; boundedImage->stats.height = subH; boundedImage->stats.bitpix = data->stats.bitpix; @@ -1118,7 +1119,7 @@ if (maxID > 10 && totalMassRatio < 1.5) return 0; - Edge *center = new Edge; + auto *center = new Edge; center->width = -1; center->x = masses[maxRegionID].massX / masses[maxRegionID].totalMass + 0.5; center->y = masses[maxRegionID].massY / masses[maxRegionID].totalMass + 0.5; @@ -1133,8 +1134,8 @@ for (float theta = 0; theta < 2 * M_PI; theta += (2 * M_PI) / 36.0) { - int testX = center->x + cos(theta) * r; - int testY = center->y + sin(theta) * r; + int testX = center->x + std::cos(theta) * r; + int testY = center->y + std::sin(theta) * r; // if out of bound, break; if (testX < 0 || testX >= subW || testY < 0 || testY >= subH) @@ -1169,7 +1170,7 @@ double FSum = 0, HF = 0, TF = 0; const double resolution = 1.0 / 20.0; - int cen_y = round(center->y); + int cen_y = std::round(center->y); double rightEdge = center->x + center->width / 2.0; double leftEdge = center->x - center->width / 2.0; @@ -1291,7 +1292,7 @@ float massX = 0, massY = 0, totalMass = 0; - T *buffer = reinterpret_cast(imageBuffer); + auto *buffer = reinterpret_cast(imageBuffer); // TODO replace magic number with something more useful to understand double threshold = stats.mean[0] * Options::focusThreshold() / 100.0; @@ -1312,7 +1313,7 @@ qCDebug(KSTARS_FITS) << "FITS: Weighted Center is X: " << massX / totalMass << " Y: " << massY / totalMass; - Edge *center = new Edge; + auto *center = new Edge; center->width = -1; center->x = massX / totalMass + 0.5; center->y = massY / totalMass + 0.5; @@ -1333,8 +1334,8 @@ for (float theta = 0; theta < 2 * M_PI; theta += (2 * M_PI) / 10.0) { - int testX = center->x + cos(theta) * r; - int testY = center->y + sin(theta) * r; + int testX = center->x + std::cos(theta) * r; + int testY = center->y + std::sin(theta) * r; // if out of bound, break; if (testX < subX || testX > subW || testY < subY || testY > subH) @@ -1375,7 +1376,7 @@ double FSum = 0, HF = 0, TF = 0, min = stats.min[0]; const double resolution = 1.0 / 20.0; - int cen_y = round(center->y); + int cen_y = std::round(center->y); double rightEdge = center->x + center->width / 2.0; double leftEdge = center->x - center->width / 2.0; @@ -1476,7 +1477,7 @@ int pixVal = 0; int minimumEdgeCount = MINIMUM_EDGE_LIMIT; - T *buffer = reinterpret_cast(imageBuffer); + auto *buffer = reinterpret_cast(imageBuffer); double JMIndex = 100; #ifndef KSTARS_LITE @@ -1589,7 +1590,7 @@ float center = avg / sum + 0.5; if (center > 0) { - int i_center = floor(center); + int i_center = std::floor(center); // Check if center is 10% or more brighter than edge, if not skip if (((buffer[i_center + (i * stats.width)] - min) / @@ -1607,7 +1608,7 @@ (buffer[i_center + (i * stats.width) - starDiameter / 2] - min)) << " located at X: " << center << " Y: " << i + 0.5; - Edge *newEdge = new Edge(); + auto *newEdge = new Edge(); newEdge->x = center; newEdge->y = i + 0.5; @@ -1735,7 +1736,7 @@ if (cen_count >= cen_limit) { // We detected a centroid, let's init it - Edge *rCenter = new Edge(); + auto *rCenter = new Edge(); rCenter->x = avg_x / sum; rCenter->y = avg_y / sum; @@ -1749,8 +1750,8 @@ double HF = 0; double FSum = 0; - cen_x = (int)floor(rCenter->x); - cen_y = (int)floor(rCenter->y); + cen_x = (int)std::floor(rCenter->x); + cen_y = (int)std::floor(rCenter->y); if (cen_x < 0 || cen_x > stats.width || cen_y < 0 || cen_y > stats.height) { @@ -1808,7 +1809,7 @@ for (auto ¢er : starCenters) lsum += (center->width - width_avg) * (center->width - width_avg); - sdev = (sqrt(lsum / (starCenters.count() - 1))) * 4; + sdev = (std::sqrt(lsum / (starCenters.count() - 1))) * 4; // Reject stars > 4 * stddev foreach (Edge *center, starCenters) @@ -1832,7 +1833,7 @@ // It is more consistent. // TODO: Try to test this under using a real CCD. - if (starCenters.size() == 0) + if (starCenters.empty()) return -1; if (type == HFR_MAX) @@ -1874,13 +1875,13 @@ double FITSData::getHFR(int x, int y) { - if (starCenters.size() == 0) + if (starCenters.empty()) return -1; for (int i = 0; i < starCenters.count(); i++) { - if (fabs(starCenters[i]->x - x) <= starCenters[i]->width / 2 && - fabs(starCenters[i]->y - y) <= starCenters[i]->width / 2) + if (std::fabs(starCenters[i]->x - x) <= starCenters[i]->width / 2 && + std::fabs(starCenters[i]->y - y) <= starCenters[i]->width / 2) { return starCenters[i]->HFR; } @@ -1896,9 +1897,9 @@ double dataMin = stats.min[0], dataMax = stats.max[0]; - if (min && *min != -1) + if ((min != nullptr) && *min != -1) dataMin = *min; - if (max && *max != -1) + if ((max != nullptr) && *max != -1) dataMax = *max; switch (type) @@ -2000,9 +2001,9 @@ return; } - if (min) + if (min != nullptr) *min = dataMin; - if (max) + if (max != nullptr) *max = dataMax; } @@ -2046,7 +2047,7 @@ double coeff = 0; if (type == FITS_LOG) - coeff = max / log(1 + max); + coeff = max / std::log(1 + max); else if (type == FITS_SQRT) coeff = max / sqrt(max); @@ -2072,7 +2073,7 @@ // Run threads futures.append(QtConcurrent::map(runningBuffer, (runningBuffer+((i == (nThreads-1)) ? fStride : tStride)), [min,max,coeff](T & a) { - a = qBound(min,static_cast(round(coeff * log(1 + qBound(min, a, max)))),max); + a = qBound(min,static_cast(round(coeff * std::log(1 + qBound(min, a, max)))),max); })); runningBuffer += tStride; @@ -2156,7 +2157,7 @@ case FITS_MEDIAN: { uint8_t BBP = stats.bytesPerPixel; - T *extension = new T[(width + 2) * (height + 2)]; + auto *extension = new T[(width + 2) * (height + 2)]; // Check memory allocation if (!extension) return; @@ -2531,7 +2532,7 @@ if (starCenters.count() == 0) return; - Edge *pEdge = new Edge(); + auto *pEdge = new Edge(); pEdge->x = *x; pEdge->y = *y; pEdge->width = 1; @@ -2564,7 +2565,7 @@ return false; } - if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs))) + if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs)) != 0) { free(header); lastError = QString("wcspih ERROR %1: %2.").arg(status).arg(wcshdr_errmsg[status]); @@ -2573,7 +2574,7 @@ free(header); - if (wcs == 0) + if (wcs == nullptr) { //fprintf(stderr, "No world coordinate systems found.\n"); lastError = i18n("No world coordinate systems found."); @@ -2587,7 +2588,7 @@ return false; } - if ((status = wcsset(wcs))) + if ((status = wcsset(wcs)) != 0) { lastError = QString("wcsset error %1: %2.").arg(status).arg(wcs_errmsg[status]); return false; @@ -2628,7 +2629,7 @@ return false; } - if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs))) + if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs)) != 0) { free(header); lastError = QString("wcspih ERROR %1: %2.").arg(status).arg(wcshdr_errmsg[status]); @@ -2637,7 +2638,7 @@ free(header); - if (wcs == 0) + if (wcs == nullptr) { //fprintf(stderr, "No world coordinate systems found.\n"); lastError = i18n("No world coordinate systems found."); @@ -2651,7 +2652,7 @@ return false; } - if ((status = wcsset(wcs))) + if ((status = wcsset(wcs)) != 0) { lastError = QString("wcsset error %1: %2.").arg(status).arg(wcs_errmsg[status]); return false; @@ -2676,7 +2677,7 @@ pixcrd[0] = j; pixcrd[1] = i; - if ((status = wcsp2s(wcs, 1, 2, &pixcrd[0], &imgcrd[0], &phi, &theta, &world[0], &stat[0]))) + if ((status = wcsp2s(wcs, 1, 2, &pixcrd[0], &imgcrd[0], &phi, &theta, &world[0], &stat[0])) != 0) { lastError = QString("wcsp2s error %1: %2.").arg(status).arg(wcs_errmsg[status]); } @@ -2710,7 +2711,7 @@ int stat[2]; double imgcrd[2], worldcrd[2], pixcrd[2], phi[2], theta[2]; - if (wcs == 0) + if (wcs == nullptr) { lastError = i18n("No world coordinate systems found."); return false; @@ -2719,7 +2720,7 @@ worldcrd[0] = wcsCoord.ra0().Degrees(); worldcrd[1] = wcsCoord.dec0().Degrees(); - if ((status = wcss2p(wcs, 1, 2, &worldcrd[0], &phi[0], &theta[0], &imgcrd[0], &pixcrd[0], &stat[0]))) + if ((status = wcss2p(wcs, 1, 2, &worldcrd[0], &phi[0], &theta[0], &imgcrd[0], &pixcrd[0], &stat[0])) != 0) { lastError = QString("wcss2p error %1: %2.").arg(status).arg(wcs_errmsg[status]); return false; @@ -2747,7 +2748,7 @@ int stat[2]; double imgcrd[2], phi, pixcrd[2], theta, world[2]; - if (wcs == 0) + if (wcs == nullptr) { lastError = i18n("No world coordinate systems found."); return false; @@ -2756,7 +2757,7 @@ pixcrd[0] = wcsPixelPoint.x(); pixcrd[1] = wcsPixelPoint.y(); - if ((status = wcsp2s(wcs, 1, 2, &pixcrd[0], &imgcrd[0], &phi, &theta, &world[0], &stat[0]))) + if ((status = wcsp2s(wcs, 1, 2, &pixcrd[0], &imgcrd[0], &phi, &theta, &world[0], &stat[0])) != 0) { lastError = QString("wcsp2s error %1: %2.").arg(status).arg(wcs_errmsg[status]); return false; @@ -2801,7 +2802,7 @@ SkyMapComposite *map = KStarsData::Instance()->skyComposite(); wcs_point *wcs_coord = getWCSCoord(); - if (wcs_coord) + if (wcs_coord != nullptr) { int size = width * height; @@ -2833,7 +2834,7 @@ world[0] = object->ra0().Degrees(); world[1] = object->dec0().Degrees(); - if ((status = wcss2p(wcs, 1, 2, &world[0], &phi, &theta, &imgcrd[0], &pixcrd[0], &stat[0]))) + if ((status = wcss2p(wcs, 1, 2, &world[0], &phi, &theta, &imgcrd[0], &pixcrd[0], &stat[0])) != 0) { fprintf(stderr, "wcsp2s ERROR %d: %s.\n", status, wcs_errmsg[status]); } @@ -2955,8 +2956,8 @@ return false; } - T *rotBuffer = reinterpret_cast(rotimage); - T *buffer = reinterpret_cast(imageBuffer); + auto *rotBuffer = reinterpret_cast(rotimage); + auto *buffer = reinterpret_cast(imageBuffer); /* Mirror image without rotation */ if (rotate < 45 && rotate > -45) @@ -3205,7 +3206,7 @@ status = 0; /* Negate rotation angle if mirrored */ - if (mirror) + if (mirror != 0) { if (!fits_read_key_dbl(fptr, "CROTA1", &ctemp1, comment, &status)) fits_update_key_dbl(fptr, "CROTA1", -ctemp1, WCS_DECIMALS, comment, &status); @@ -3284,7 +3285,7 @@ if (!fits_read_key_dbl(fptr, "CRPIX1", &ctemp1, comment, &status) && !fits_read_key_dbl(fptr, "CRPIX2", &ctemp2, comment, &status)) { - if (mirror) + if (mirror != 0) { if (angle == 0) fits_update_key_dbl(fptr, "CRPIX1", naxis1 - ctemp1, WCS_DECIMALS, comment, &status); @@ -3330,7 +3331,7 @@ if (!fits_read_key_dbl(fptr, "CDELT1", &ctemp1, comment, &status) && !fits_read_key_dbl(fptr, "CDELT2", &ctemp2, comment, &status)) { - if (mirror) + if (mirror != 0) { if (angle == 0) fits_update_key_dbl(fptr, "CDELT1", -ctemp1, WCS_DECIMALS, comment, &status); @@ -3382,7 +3383,7 @@ fits_read_key_dbl(fptr, "CD2_1", &ctemp3, comment, &status); fits_read_key_dbl(fptr, "CD2_2", &ctemp4, comment, &status); status = 0; - if (mirror) + if (mirror != 0) { if (angle == 0) { @@ -3457,7 +3458,6 @@ } } - return; } uint8_t *FITSData::getImageBuffer() @@ -3535,7 +3535,7 @@ bayerBuffer = imageBuffer; - if (fits_read_img(fptr, data_type, 1, stats.samples_per_channel, 0, bayerBuffer, &anynull, &status)) + if (fits_read_img(fptr, data_type, 1, stats.samples_per_channel, nullptr, bayerBuffer, &anynull, &status)) { char errmsg[512]; fits_get_errstatus(status, errmsg); @@ -3564,7 +3564,7 @@ dc1394error_t error_code; int rgb_size = stats.samples_per_channel * 3 * stats.bytesPerPixel; - uint8_t *destinationBuffer = new uint8_t[rgb_size]; + auto *destinationBuffer = new uint8_t[rgb_size]; if (destinationBuffer == nullptr) { @@ -3635,10 +3635,10 @@ dc1394error_t error_code; int rgb_size = stats.samples_per_channel * 3 * stats.bytesPerPixel; - uint8_t *destinationBuffer = new uint8_t[rgb_size]; + auto *destinationBuffer = new uint8_t[rgb_size]; - uint16_t *buffer = reinterpret_cast(bayerBuffer); - uint16_t *dstBuffer = reinterpret_cast(destinationBuffer); + auto *buffer = reinterpret_cast(bayerBuffer); + auto *dstBuffer = reinterpret_cast(destinationBuffer); if (destinationBuffer == nullptr) { @@ -4085,7 +4085,7 @@ { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" - T *buffer = (T*)getImageBuffer(); + auto *buffer = (T*)getImageBuffer(); #pragma GCC diagnostic pop const T limit = std::numeric_limits::max(); T bMin = dataMin < 0 ? 0 : dataMin; @@ -4117,7 +4117,7 @@ /* Fill in pixel values using indexed map, linear scale */ for (int j = 0; j < h; j++) { - QRgb *scanLine = reinterpret_cast((image.scanLine(j))); + auto *scanLine = reinterpret_cast((image.scanLine(j))); for (int i = 0; i < w; i++) { @@ -4141,7 +4141,7 @@ FITSData data; bool rc = data.loadFITS(filename); - if (rc == false) + if (!rc) return fitsImage; data.getMinMax(&min, &max); @@ -4410,7 +4410,7 @@ { int x=0,y=0,w=stats.width,h=stats.height, maxRadius=50; - if (boundary.isNull() == false) + if (!boundary.isNull()) { x = boundary.x(); y = boundary.y(); @@ -4419,7 +4419,7 @@ maxRadius = w; } - float *data = new float[w*h]; + auto *data = new float[w*h]; switch (stats.bitpix) { @@ -4471,21 +4471,21 @@ // #1 Background estimate status = sep_background(&im, 64, 64, 3, 3, 0.0, &bkg); - if (status) goto exit; + if (status != 0) goto exit; // #2 Background evaluation imback = (float *)malloc((w * h)*sizeof(float)); status = sep_bkg_array(bkg, imback, SEP_TFLOAT); - if (status) goto exit; + if (status != 0) goto exit; // #3 Background substraction status = sep_bkg_subarray(bkg, im.data, im.dtype); - if (status) goto exit; + if (status != 0) goto exit; // #4 Source Extraction // Note that we set deblend_cont = 1.0 to turn off deblending. status = sep_extract(&im, 2*bkg->globalrms, SEP_THRESH_ABS, 10, conv, 3, 3, SEP_FILTER_CONV, 32, 1.0, 1, 1.0, &catalog); - if (status) goto exit; + if (status != 0) goto exit; #if 0 // #4 Aperture photometry @@ -4510,7 +4510,7 @@ // Get HFR sep_flux_radius(&im, catalog->x[i], catalog->y[i], maxRadius, 5, 0, &flux, requested_frac, 2, flux_fractions, &flux_flag); - Edge *center = new Edge(); + auto *center = new Edge(); center->x = catalog->x[i]+x+0.5; center->y = catalog->y[i]+y+0.5; center->val = catalog->peak[i]; @@ -4548,7 +4548,7 @@ free(area); free(flag); - if (status) + if (status != 0) { char errorMessage[512]; sep_get_errmsg(status, errorMessage); @@ -4562,7 +4562,7 @@ template void FITSData::getFloatBuffer(float *buffer, int x, int y, int w, int h) { - T *rawBuffer = reinterpret_cast(imageBuffer); + auto *rawBuffer = reinterpret_cast(imageBuffer); float *floatPtr = buffer; Index: kstars/fitsviewer/fitshistogram.h =================================================================== --- kstars/fitsviewer/fitshistogram.h +++ kstars/fitsviewer/fitshistogram.h @@ -50,7 +50,7 @@ double getJMIndex() const; protected: - void showEvent(QShowEvent *); + void showEvent(QShowEvent *event); public slots: void applyScale(); @@ -109,7 +109,7 @@ long dim[2]; } stats; - bool calculateDelta(uint8_t *buffer); + bool calculateDelta(const uint8_t *buffer); bool reverseDelta(); void saveStats(double min, double max, double stddev, double mean, double median, double SNR); void restoreStats(); Index: kstars/fitsviewer/fitshistogram.cpp =================================================================== --- kstars/fitsviewer/fitshistogram.cpp +++ kstars/fitsviewer/fitshistogram.cpp @@ -31,7 +31,7 @@ FITSHistogram::FITSHistogram(QWidget *parent) : QDialog(parent) { ui = new histogramUI(this); - tab = static_cast(parent); + tab = dynamic_cast(parent); customPlot = ui->histogramPlot; @@ -73,9 +73,10 @@ connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(checkRangeLimit(QCPRange))); } -void FITSHistogram::showEvent(QShowEvent *) +void FITSHistogram::showEvent(QShowEvent *event) { - syncGUI(); + Q_UNUSED(event) + syncGUI(); } void FITSHistogram::constructHistogram() @@ -132,7 +133,7 @@ uint16_t fits_w = 0, fits_h = 0; FITSData *image_data = tab->getView()->getImageData(); - T *buffer = reinterpret_cast(image_data->getImageBuffer()); + auto *buffer = reinterpret_cast(image_data->getImageBuffer()); image_data->getDimensions(&fits_w, &fits_h); image_data->getMinMax(&fits_min, &fits_max); @@ -526,7 +527,7 @@ FITSHistogramCommand::FITSHistogramCommand(QWidget *parent, FITSHistogram *inHisto, FITSScale newType, double lmin, double lmax) { - tab = static_cast(parent); + tab = dynamic_cast(parent); type = newType; histogram = inHisto; min = lmin; @@ -538,7 +539,7 @@ delete[] delta; } -bool FITSHistogramCommand::calculateDelta(uint8_t *buffer) +bool FITSHistogramCommand::calculateDelta(const uint8_t *buffer) { FITSData *image_data = tab->getView()->getImageData(); @@ -546,7 +547,7 @@ int totalPixels = image_data->getSize() * image_data->getNumOfChannels(); unsigned long totalBytes = totalPixels * image_data->getBytesPerPixel(); - uint8_t *raw_delta = new uint8_t[totalBytes]; + auto *raw_delta = new uint8_t[totalBytes]; if (raw_delta == nullptr) { @@ -597,7 +598,7 @@ int totalPixels = size * channels; unsigned long totalBytes = totalPixels * image_data->getBytesPerPixel(); - uint8_t *output_image = new uint8_t[totalBytes]; + auto *output_image = new uint8_t[totalBytes]; if (output_image == nullptr) { @@ -605,7 +606,7 @@ return false; } - uint8_t *raw_delta = new uint8_t[totalBytes]; + auto *raw_delta = new uint8_t[totalBytes]; if (raw_delta == nullptr) { @@ -673,7 +674,7 @@ } else { - uint8_t *buffer = new uint8_t[size * channels * BBP]; + auto *buffer = new uint8_t[size * channels * BBP]; if (buffer == nullptr) { Index: kstars/fitsviewer/fitsview.h =================================================================== --- kstars/fitsviewer/fitsview.h +++ kstars/fitsviewer/fitsview.h @@ -52,15 +52,15 @@ { Q_OBJECT public: - explicit FITSView(QWidget *parent = nullptr, FITSMode mode = FITS_NORMAL, FITSScale filter = FITS_NONE); + explicit FITSView(QWidget *parent = nullptr, FITSMode fitsMode = FITS_NORMAL, FITSScale filterType = FITS_NONE); ~FITSView(); typedef enum {dragCursor, selectCursor, scopeCursor, crosshairCursor } CursorMode; // Loads FITS image, scales it, and displays it in the GUI - bool loadFITS(const QString &filename, bool silent = true); + bool loadFITS(const QString &inFilename, bool silent = true); // Save FITS - int saveFITS(const QString &filename); + int saveFITS(const QString &newFilename); // Rescale image lineary from image_buffer, fit to window if desired int rescale(FITSZoom type); @@ -98,8 +98,8 @@ bool isTelescopeActive(); - void enterEvent(QEvent *); - void leaveEvent(QEvent *); + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); CursorMode getCursorMode(); void setCursorMode(CursorMode mode); void updateMouseCursor(); @@ -117,7 +117,7 @@ void setStarsEnabled(bool enable); // FITS Mode - void updateMode(FITSMode mode); + void updateMode(FITSMode fmode); FITSMode getMode() { return mode; } void setFilter(FITSScale newFilter) { filter = newFilter; } Index: kstars/fitsviewer/fitsview.cpp =================================================================== --- kstars/fitsviewer/fitsview.cpp +++ kstars/fitsviewer/fitsview.cpp @@ -42,8 +42,8 @@ grabGesture(Qt::PinchGesture); image_frame.reset(new FITSLabel(this)); - filter = filterType; - mode = fitsMode; + filter = filterType; + mode = fitsMode; setBackgroundRole(QPalette::Dark); @@ -130,9 +130,9 @@ cursorMode = mode; updateMouseCursor(); - if (mode==scopeCursor && imageHasWCS()) + if (mode == scopeCursor && imageHasWCS()) { - if(imageData->isWCSLoaded() == false && wcsWatcher.isRunning() == false) + if (!imageData->isWCSLoaded() && !wcsWatcher.isRunning()) { QFuture future = QtConcurrent::run(imageData, &FITSData::loadWCS); wcsWatcher.setFuture(future); @@ -142,7 +142,7 @@ void FITSView::resizeEvent(QResizeEvent *event) { - if (!imageData && noImageLabel) + if ((imageData == nullptr) && noImageLabel != nullptr) { noImageLabel->setPixmap( noImage.scaled(width() - 20, height() - 20, Qt::KeepAspectRatio, Qt::FastTransformation)); @@ -159,15 +159,17 @@ bool FITSView::loadFITS(const QString &inFilename, bool silent) { - if (floatingToolBar) + if (floatingToolBar != nullptr) + { floatingToolBar->setVisible(true); + } QProgressDialog fitsProg(this); bool setBayerParams = false; BayerParams param; - if (imageData && imageData->hasDebayer()) + if ((imageData != nullptr) && imageData->hasDebayer()) { setBayerParams = true; imageData->getBayerParams(¶m); @@ -198,7 +200,7 @@ qApp->processEvents(); } - if (imageData->loadFITS(inFilename, silent) == false) + if (!imageData->loadFITS(inFilename, silent)) return false; if (mode == FITS_NORMAL) @@ -228,14 +230,14 @@ { currentZoom = 100; - if (rescale(ZOOM_FIT_WINDOW)) + if (rescale(ZOOM_FIT_WINDOW) != 0) return false; firstLoad = false; } else { - if (rescale(ZOOM_KEEP_LEVEL)) + if (rescale(ZOOM_KEEP_LEVEL) != 0) return false; } @@ -253,7 +255,7 @@ setAlignment(Qt::AlignCenter); // Load WCS data now if selected and image contains valid WCS header - if (imageData->hasWCS() && Options::autoWCS() && (mode == FITS_NORMAL || mode == FITS_ALIGN) && wcsWatcher.isRunning() == false) + if (imageData->hasWCS() && Options::autoWCS() && (mode == FITS_NORMAL || mode == FITS_ALIGN) && !wcsWatcher.isRunning()) { QFuture future = QtConcurrent::run(imageData, &FITSData::loadWCS); wcsWatcher.setFuture(future); @@ -264,8 +266,9 @@ if (isVisible()) emit newStatus(QString("%1x%2").arg(image_width).arg(image_height), FITS_RESOLUTION); - if(showStarProfile){ - if(floatingToolBar) + if (showStarProfile) + { + if(floatingToolBar != nullptr) toggleProfileAction->setChecked(true); QTimer::singleShot(100 , this , SLOT(viewStarProfile())); //Need to wait till the Focus module finds stars, if its the Focus module. } @@ -326,11 +329,13 @@ return cursorMode; } -void FITSView::enterEvent(QEvent *) +void FITSView::enterEvent(QEvent *event) { - if (floatingToolBar && imageData) + Q_UNUSED(event) + + if ((floatingToolBar != nullptr) && (imageData != nullptr)) { - QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this); + auto *eff = new QGraphicsOpacityEffect(this); floatingToolBar->setGraphicsEffect(eff); QPropertyAnimation *a = new QPropertyAnimation(eff, "opacity"); a->setDuration(500); @@ -341,11 +346,13 @@ } } -void FITSView::leaveEvent(QEvent *) +void FITSView::leaveEvent(QEvent *event) { - if (floatingToolBar && imageData) + Q_UNUSED(event) + + if ((floatingToolBar != nullptr) && (imageData != nullptr)) { - QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this); + auto *eff = new QGraphicsOpacityEffect(this); floatingToolBar->setGraphicsEffect(eff); QPropertyAnimation *a = new QPropertyAnimation(eff, "opacity"); a->setDuration(500); @@ -393,7 +400,7 @@ imageData->getMinMax(&min, &max); } - T *buffer = reinterpret_cast(image_buffer); + auto *buffer = reinterpret_cast(image_buffer); if (min == max) { @@ -450,7 +457,7 @@ { futures.append(QtConcurrent::run([=]() { - QRgb *scanLine = reinterpret_cast((display_image->scanLine(j))); + auto *scanLine = reinterpret_cast((display_image->scanLine(j))); T *runningBufferR = buffer + j*image_width; T *runningBufferG = buffer + j*image_width + size; T *runningBufferB = buffer + j*image_width + size*2; @@ -518,7 +525,7 @@ double w = baseSize().width() - BASE_OFFSET; double h = baseSize().height() - BASE_OFFSET; - if (firstLoad == false) + if (!firstLoad) { w = viewport()->rect().width() - BASE_OFFSET; h = viewport()->rect().height() - BASE_OFFSET; @@ -618,7 +625,7 @@ void FITSView::ZoomToFit() { - if (display_image) + if (display_image != nullptr) { rescale(ZOOM_FIT_WINDOW); updateFrame(); @@ -639,7 +646,7 @@ else ok = displayPixmap.convertFromImage(*display_image); - if (ok == false) + if (!ok) return; QPainter painter(&displayPixmap); @@ -652,7 +659,7 @@ void FITSView::ZoomDefault() { - if (image_frame.get()) + if (image_frame != nullptr) { emit actionUpdated("view_zoom_out", true); emit actionUpdated("view_zoom_in", true); @@ -679,7 +686,7 @@ if (trackingBoxEnabled && getCursorMode() != FITSView::scopeCursor) drawTrackingBox(painter); - if (markerCrosshair.isNull() == false) + if (!markerCrosshair.isNull()) drawMarker(painter); if (showCrosshair) @@ -769,11 +776,11 @@ void FITSView::drawCrosshair(QPainter *painter) { float scale = (currentZoom / ZOOM_DEFAULT); - QPointF c = QPointF(image_width / 2 * scale, image_height / 2 * scale); - float midX = image_width / 2 * scale; - float midY = image_height / 2 * scale; - float maxX = image_width * scale; - float maxY = image_height * scale; + QPointF c = QPointF((qreal)image_width / 2 * scale, (qreal)image_height / 2 * scale); + float midX = (float)image_width / 2 * scale; + float midY = (float)image_height / 2 * scale; + float maxX = (float)image_width * scale; + float maxY = (float)image_height * scale; float r = 50 * scale; painter->setPen(QPen(QColor(KStarsData::Instance()->colorScheme()->colorNamed("TargetColor")))); @@ -842,7 +849,7 @@ bool FITSView::imageHasWCS() { - if (imageData) + if (imageData != nullptr) return imageData->hasWCS(); return false; } @@ -872,7 +879,7 @@ if (imageData->hasWCS()) { wcs_point *wcs_coord = imageData->getWCSCoord(); - if (wcs_coord) + if (wcs_coord != nullptr) { int size = image_width * image_height; double maxRA = -1000; @@ -893,13 +900,13 @@ if (dec < minDec) minDec = dec; } - int minDecMinutes = (int)(minDec * 12); //This will force the Dec Scale to 5 arc minutes in the loop - int maxDecMinutes = (int)(maxDec * 12); + auto minDecMinutes = (int)(minDec * 12); //This will force the Dec Scale to 5 arc minutes in the loop + auto maxDecMinutes = (int)(maxDec * 12); - int minRAMinutes = + auto minRAMinutes = (int)(minRA / 15.0 * 120.0); //This will force the scale to 1/2 minutes of RA in the loop from 0 to 50 degrees - int maxRAMinutes = (int)(maxRA / 15.0 * 120.0); + auto maxRAMinutes = (int)(maxRA / 15.0 * 120.0); double raConvert = 15 / 120.0; //This will undo the calculation above to retrieve the actual RA. double decConvert = 1.0 / 12.0; //This will undo the calculation above to retrieve the actual DEC. @@ -1196,14 +1203,14 @@ { showEQGrid = !showEQGrid; - if (imageData->isWCSLoaded() == false && wcsWatcher.isRunning() == false) + if (!imageData->isWCSLoaded() && !wcsWatcher.isRunning()) { QFuture future = QtConcurrent::run(imageData, &FITSData::loadWCS); wcsWatcher.setFuture(future); return; } - if (image_frame.get()) + if (image_frame != nullptr) updateFrame(); } @@ -1211,21 +1218,21 @@ { showObjects = !showObjects; - if (imageData->isWCSLoaded() == false && wcsWatcher.isRunning() == false) + if (!imageData->isWCSLoaded() && !wcsWatcher.isRunning()) { QFuture future = QtConcurrent::run(imageData, &FITSData::loadWCS); wcsWatcher.setFuture(future); return; } - if (image_frame.get()) + if (image_frame != nullptr) updateFrame(); } void FITSView::toggleStars() { toggleStars(!markStars); - if (image_frame.get()) + if (image_frame != nullptr) updateFrame(); } @@ -1345,7 +1352,7 @@ { markStars = enable; - if (markStars == true && imageData->areStarsSearched() == false) + if (markStars && !imageData->areStarsSearched()) { QApplication::setOverrideCursor(Qt::WaitCursor); emit newStatus(i18n("Finding stars..."), FITS_MESSAGE); @@ -1417,7 +1424,7 @@ int x0 = 0; int y0 = 0; double scale = (currentZoom / ZOOM_DEFAULT); - if (markerCrosshair.isNull() == false) + if (!markerCrosshair.isNull()) { x0 = markerCrosshair.x() * scale; y0 = markerCrosshair.y() * scale; @@ -1483,14 +1490,14 @@ bool FITSView::event(QEvent *event) { if (event->type() == QEvent::Gesture) - return gestureEvent(static_cast(event)); + return gestureEvent(dynamic_cast(event)); return QScrollArea::event(event); } bool FITSView::gestureEvent(QGestureEvent *event) { if (QGesture *pinch = event->gesture(Qt::PinchGesture)) - pinchTriggered(static_cast(pinch)); + pinchTriggered(dynamic_cast(pinch)); return true; } @@ -1541,21 +1548,21 @@ emit wcsToggled(hasWCS); - if (toggleEQGridAction) + if (toggleEQGridAction != nullptr) toggleEQGridAction->setEnabled(hasWCS); - if (toggleObjectsAction) + if (toggleObjectsAction != nullptr) toggleObjectsAction->setEnabled(hasWCS); - if (centerTelescopeAction) + if (centerTelescopeAction != nullptr) centerTelescopeAction->setEnabled(hasWCS); } void FITSView::createFloatingToolBar() { - if (floatingToolBar) + if (floatingToolBar != nullptr) return; floatingToolBar = new QToolBar(this); - QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this); + auto *eff = new QGraphicsOpacityEffect(this); floatingToolBar->setGraphicsEffect(eff); eff->setOpacity(0.2); floatingToolBar->setVisible(false); @@ -1653,7 +1660,7 @@ void FITSView::updateScopeButton() { - if (centerTelescopeAction) + if (centerTelescopeAction != nullptr) { if (getCursorMode() == FITSView::scopeCursor) { @@ -1699,7 +1706,7 @@ void FITSView::setStarsEnabled(bool enable) { markStars = enable; - if (floatingToolBar) + if (floatingToolBar != nullptr) { foreach (QAction *action, floatingToolBar->actions()) { Index: kstars/hips/hips.h =================================================================== --- kstars/hips/hips.h +++ kstars/hips/hips.h @@ -38,10 +38,7 @@ class pixCacheItem_t { public: - pixCacheItem_t() - { - image = nullptr; - } + pixCacheItem_t() = default; ~pixCacheItem_t() { @@ -50,7 +47,7 @@ delete image; } - QImage *image; + QImage *image { nullptr }; }; typedef struct Index: kstars/hips/hipsmanager.h =================================================================== --- kstars/hips/hipsmanager.h +++ kstars/hips/hipsmanager.h @@ -50,6 +50,7 @@ void done() { emit remove(m_key); + deleteLater(); } }; @@ -99,7 +100,7 @@ static HIPSManager * _HIPSManager; // Cache - PixCache m_cache; + PixCache m_cache; QSet m_downloadMap; void addToMemoryCache(pixCacheKey_t &key, pixCacheItem_t *item); Index: kstars/hips/hipsmanager.cpp =================================================================== --- kstars/hips/hipsmanager.cpp +++ kstars/hips/hipsmanager.cpp @@ -170,7 +170,7 @@ key.pix = pix / 4; pixCacheItem_t *item = getCacheItem(key); - if (item) + if (item != nullptr) { QImage *cacheImage = item->image; int size = m_currentTileWidth >> 1; @@ -189,7 +189,7 @@ return nullptr; } - if (item) + if (item != nullptr) { QImage *cacheImage = item->image; @@ -338,7 +338,7 @@ { m_downloadMap.remove(key); - pixCacheItem_t *item = new pixCacheItem_t; + auto *item = new pixCacheItem_t; item->image = new QImage(); if (item->image->loadFromData(data)) @@ -349,7 +349,6 @@ } else { - delete item->image; delete item; qCWarning(KSTARS) << "no image" << data; } @@ -362,7 +361,7 @@ } else { - RemoveTimer *timer = new RemoveTimer(); + auto *timer = new RemoveTimer(); timer->setKey(key); connect(timer, SIGNAL(remove(pixCacheKey_t&)), this, SLOT(removeTimer(pixCacheKey_t&))); } Index: tools/run_clang_tidy_static_code_analyzer.sh =================================================================== --- tools/run_clang_tidy_static_code_analyzer.sh +++ tools/run_clang_tidy_static_code_analyzer.sh @@ -4,10 +4,14 @@ ARGS3="-cert-msc30-c,-google-readability-todo,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-google-build-using-namespace" ARGS4="-misc-macro-parentheses,-modernize-use-using,-llvm-include-order,-readability-static-definition-in-anonymous-namespace" ARGS5="-cert-err58-cpp,-readability-else-after-return,-cppcoreguidelines-pro-bounds-pointer-arithmetic" -ARGS6="-cppcoreguidelines-pro-type-reinterpret-cast,-readability-redundant-member-init" +ARGS6="-cppcoreguidelines-pro-type-reinterpret-cast,-readability-redundant-member-init,-fuchsia-default-arguments" +ARGS7="-cppcoreguidelines-owning-memory,-hicpp-no-malloc,-hicpp-braces-around-statements,-hicpp-no-array-decay,-google-runtime-int" +# modernize-make-unique is skipped because we compile only with C++11 support +ARGS8="-readability-misleading-indentation,-hicpp-vararg,-modernize-make-unique,-hicpp-vararg,-cert-flp30-c" +ARGS9="-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-type-member-init,-hicpp-member-init" # Configure CMake -cmake -Bclang_tidy_build -H.. -DCMAKE_CXX_CLANG_TIDY:STRING="clang-tidy-4.0;$ARGS1,$ARGS2,$ARGS3,$ARGS4,$ARGS5,$ARGS6" \ - -DUNITY_BUILD=ON -DCMAKE_C_COMPILER=clang-4.0 -DCMAKE_CXX_COMPILER=clang++-4.0 $@ +cmake -Bclang_tidy_build -H.. -DCMAKE_CXX_CLANG_TIDY:STRING="clang-tidy-6.0;$ARGS1,$ARGS2,$ARGS3,$ARGS4,$ARGS5,$ARGS6,$ARGS7,$ARGS8,$ARGS9" \ + -DUNITY_BUILD=OFF -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $@ -make -C clang_tidy_build -j4 +make -C clang_tidy_build -j3