Example #1
1
void K3b::FillStatusDisplay::slotCustomSize()
{
    // allow the units to be translated
    QString gbS = i18n("GB");
    QString mbS = i18n("MB");
    QString minS = i18n("min");

    QLocale const locale = QLocale::system();

    // we certainly do not have BD- or HD-DVD-only projects
    QString defaultCustom;
    if( d->doc->supportedMediaTypes() & K3b::Device::MEDIA_CD_ALL ) {
        defaultCustom = d->showTime ? QString("74") + minS : QString("650") + mbS;
    }
    else {
        defaultCustom = locale.toString(4.4,'g',1) + gbS;
    }

    QRegExp rx( QString("(\\d+\\") + locale.decimalPoint() + "?\\d*)(" + gbS + '|' + mbS + '|' + minS + ")?" );
    QRegExpValidator validator( rx, this );
    bool ok;
    QString size = QInputDialog::getText( this,
                                          i18n("Custom Size"),
                                          i18n("<p>Please specify the size of the medium. Use suffixes <b>GB</b>,<b>MB</b>, "
                                               "and <b>min</b> for <em>gigabytes</em>, <em>megabytes</em>, and <em>minutes</em>"
                                               " respectively."),
                                          QLineEdit::Normal,
                                          defaultCustom,
                                          &ok );

    int validatorPos;
    if( ok && validator.validate( size, validatorPos ) ) {
        // determine size
        if( rx.exactMatch( size ) ) {
            QString valStr = rx.cap(1);
            if( valStr.endsWith( locale.decimalPoint() ) )
                valStr += '0';
            double val = locale.toDouble( valStr, &ok );
            if( ok ) {
                QString s = rx.cap(2);
                if( s == gbS )
                    val *= 1024*512;
                else if( s == mbS || (s.isEmpty() && !d->showTime) )
                    val *= 512;
                else
                    val *= 60*75;
                d->setCdSize( static_cast<int>( val ) );
            }
        }
    }
}
Example #2
0
/**
*@brief  Retourne la tolérance au blanc.
*@return QString - Valeur du champ.
*/
QString DockConf::getBlankSkip()
{
    QString res;
    QLocale localedecimalPoint;
    double value = double(blankSkipSpinBox->value())/100;
    res = QString::number(value,'f',2);
    #if defined(Q_OS_LINUX)
    return res.replace(",",localedecimalPoint.decimalPoint());
    #else
    return res.replace(".",localedecimalPoint.decimalPoint());
    #endif
}
Example #3
0
void Core::initLocale()
{
    QLocale systemLocale = QLocale();
#ifndef Q_OS_MAC
    setlocale(LC_NUMERIC, NULL);
#else
    setlocale(LC_NUMERIC_MASK, NULL);
#endif
    char *separator = localeconv()->decimal_point;
    if (QString::fromUtf8(separator) != QChar(systemLocale.decimalPoint())) {
        //qDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------";
        // HACK: There is a locale conflict, so set locale to C
        // Make sure to override exported values or it won't work
        qputenv("LANG", "C");
#ifndef Q_OS_MAC
        setlocale(LC_NUMERIC, "C");
#else
        setlocale(LC_NUMERIC_MASK, "C");
#endif
        systemLocale = QLocale::c();
    }

    systemLocale.setNumberOptions(QLocale::OmitGroupSeparator);
    QLocale::setDefault(systemLocale);
}
Example #4
0
QString formatLocFPNumber(double d)
{
	QString result = toqstr(formatFPNumber(d));
	QLocale loc;
	result.replace('.', loc.decimalPoint());
	return result;
}
Example #5
0
QString BitcoinUnits::format(int unit, qint64 n, bool fPlus)
{
    // Note: not using straight sprintf here because we do NOT want
    // localized number formatting.
    if(!valid(unit))
        return QString(); // Refuse to format invalid unit
    qint64 coin = factor(unit);
    int num_decimals = decimals(unit);
    qint64 n_abs = (n > 0 ? n : -n);
    qint64 quotient = n_abs / coin;
    qint64 remainder = n_abs % coin;
    QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');

    // Right-trim excess zeros after the decimal point
    int nTrim = 0;
    for (int i = remainder_str.size()-1; i>=2 && (remainder_str.at(i) == '0'); --i)
        ++nTrim;
    remainder_str.chop(nTrim);

    QString quotientString;

    if (n < 0) {
        quotient = -quotient;
    }
    else if ( n > 0 && fPlus ) {
        quotientString += "+";
    }

    QLocale local;
    return quotientString + local.toString(quotient) + local.decimalPoint() + remainder_str;
}
Example #6
0
QString DataFile::sampleToDateTimeString(int sample, InfoTable::TimeMode mode)
{
	QLocale locale;

	if (mode == InfoTable::TimeMode::size)
	{
		mode = infoTable.getTimeMode();
	}

	if (mode == InfoTable::TimeMode::samples)
	{
		return QString::number(sample);
	}
	else if (mode == InfoTable::TimeMode::offset)
	{
		QDateTime date = sampleToOffset(sample);
		return QString::number(date.date().day() - 1) + "d " + date.toString("hh:mm:ss" + QString(locale.decimalPoint()) + "zzz");
	}
	else if (mode == InfoTable::TimeMode::real)
	{
		return sampleToDate(sample).toString("d.M.yyyy hh:mm:ss" + QString(locale.decimalPoint()) + "zzz");
	}

	return QString();
}
MapValidator::QValidator::State MapValidator::validate(QString &s, int &i) const
{
    qDebug()<<"validating table input";
    if (s.isEmpty() || s == "-") {
        return QValidator::Intermediate;
    }

    QLocale locale;

    QChar decimalPoint = locale.decimalPoint();
    int charsAfterPoint = s.length() - s.indexOf(decimalPoint) -1;

    if (charsAfterPoint > decimals() && s.indexOf(decimalPoint) != -1) {
        return QValidator::Invalid;
    }

    bool ok;
    double d = locale.toDouble(s, &ok);

    if (ok && d >= bottom() && d <= top()) {
        return QValidator::Acceptable;
    } else {
        return QValidator::Invalid;
    }
}
Example #8
0
double LonLatParser::parseDouble(const QString& input)
{
    // Decide by decimalpoint if system locale or C locale should be tried.
    // Otherwise if first trying with a system locale when the string is in C locale,
    // the "." might be misinterpreted as thousands group separator and thus a wrong
    // value yielded
    QLocale locale = QLocale::system();
    return input.contains(locale.decimalPoint()) ? locale.toDouble(input) : input.toDouble();
}
void GuiParagraph::changed()
{
	QLocale loc;
	// We apply immediately, except if we have custom line spacing
	// with an intermediate result (trailing decimal separator) or
	// an invalid value (which might as well be intermediate)
	if (synchronizedViewCB->isChecked()
	    && (linespacing->currentIndex() != 4
		|| (!linespacingValue->text().endsWith(loc.decimalPoint())
		    && linespacingValue->hasAcceptableInput())))
		on_applyPB_clicked();
}
Example #10
0
QString QcNumberBox::stringForVal( double val )
{
  QLocale loc = locale();
  QString str = loc.toString( val, 'f', _maxDec );
  int i = str.indexOf( loc.decimalPoint() );
  if( i > -1 ) {
    QString dec = str.mid(i+1);
    while( dec.size() > _minDec && dec.endsWith('0') ) dec.chop(1);
    if( dec.isEmpty() )
      str = str.left(i);
    else
      str = str.left(i+1) + dec;
  }
  return str;
}
Example #11
0
QString Utility::compactFormatDouble(double value, int prec, const QString& unit)
{
    QLocale locale = QLocale::system();
    QChar decPoint = locale.decimalPoint();
    QString str = locale.toString(value, 'f', prec);
    while (str.endsWith('0') || str.endsWith(decPoint)) {
        if (str.endsWith(decPoint)) {
            str.chop(1);
            break;
        }
        str.chop(1);
    }
    if( !unit.isEmpty() )
        str += (QLatin1Char(' ')+unit);
    return str;
}
Example #12
0
QValidator::State LengthValidator::validate(QString & qtext, int &) const
{
	QLocale loc;
	bool ok;
	double d = loc.toDouble(qtext.trimmed(), &ok);
	// QLocale::toDouble accepts something like "1."
	// We don't.
	bool dp = qtext.endsWith(loc.decimalPoint());
	if (!ok) {
		// Fall back to C
		QLocale c(QLocale::C);
		d = c.toDouble(qtext.trimmed(), &ok);
		dp = qtext.endsWith(c.decimalPoint());
	}

	if (ok && unsigned_ && d < 0)
		return QValidator::Invalid;

	if (qtext.isEmpty() || (ok && !dp))
		return QValidator::Acceptable;

	string const text = fromqstr(qtext);

	if (glue_length_) {
		GlueLength gl;
		if (unsigned_ && gl.len().value() < 0)
			return QValidator::Invalid;
		return (isValidGlueLength(text, &gl)) ?
			QValidator::Acceptable : QValidator::Intermediate;
	}

	Length l;
	bool const valid_length = isValidLength(text, &l);
	if (!valid_length)
		return QValidator::Intermediate;

	if (no_bottom_)
		return QValidator::Acceptable;

	if (unsigned_ && l.value() < 0)
		return QValidator::Invalid;

	return b_.inPixels(100) <= l.inPixels(100) ?
		QValidator::Acceptable : QValidator::Intermediate;
}
QVariant KexiTextFormatter::fromString(const QString& text) const
{
    if (!d->field)
        return QVariant();

    switch (d->field->type()) {
    case KDbField::Text:
    case KDbField::LongText:
        return text;
    case KDbField::Byte:
    case KDbField::ShortInteger:
        return text.toShort();
//! @todo uint, etc?
    case KDbField::Integer:
        return text.toInt();
    case KDbField::BigInteger:
        return text.toLongLong();
    case KDbField::Boolean:
//! @todo temporary solution for booleans!
        return text == "1";
    case KDbField::Date:
        return d->dateFormatter->stringToVariant(text);
    case KDbField::Time:
        return d->timeFormatter->stringToVariant(text);
    case KDbField::DateTime:
        return KexiDateTimeFormatter::fromString(
                   *d->dateFormatter, *d->timeFormatter, text);
    case KDbField::Float:
    case KDbField::Double: {
        // replace custom decimal symbol with '.' as required by to{Float|Double}()
        QString fixedText(text);
        QLocale locale;
        fixedText.replace(locale.decimalPoint(), '.');
        if (d->field->type() == KDbField::Double)
            return fixedText.toDouble();
        return fixedText.toFloat();
    }
    default:
        break;
    }
    return text;
//! @todo more data types!
}
Example #14
0
QString UnitFormatter::format(const double value, QString unit)
{
    QLocale locale;
    QString result;
    ushort prefix;
    QTextStream out(&result);
    out.setLocale(locale);
    if(value>0.999999999){
        double aux = value;
        int multiplier = 0;
        while(aux>=1000){
            ++multiplier;
            aux=aux/1000;
        }
        prefix = BIG_PREFIXES[multiplier];
        out.setRealNumberPrecision(2);
        out.setNumberFlags(out.numberFlags() & ~QTextStream::ForcePoint);
        out.setRealNumberNotation(QTextStream::FixedNotation);
        out<<aux;
    }
    else {
        double aux = value;
        int divider = 0;
        if(aux>SMALLEST_VALUE){
            while(aux<0.999999999){
                ++divider;
                aux=aux*1000;
            }
        }
        prefix = SMALL_PREFIXES[divider];
        out.setRealNumberPrecision(2);
        out.setRealNumberNotation(QTextStream::FixedNotation);
        out<<aux;
    }
    removeTrailingZeros(result, locale.decimalPoint());
    if(prefix){
        out<<QChar(prefix);
    }
    if(unit!=0){
        out<<unit;
    }
    return result;
}
Example #15
0
QString formatDoubleForDisplay(double num, double decimalPlacesToDisplay)
{
    QLocale locale;
    QString withCommas = locale.toString(num, 'f');

    QString final;
    bool pastDecimalPoint = false;
    int numbersPastDecimalPoint = 0;
    for (int i = 0; i < withCommas.length(); ++i)
    {
        final += withCommas[i];

        if (pastDecimalPoint)
            ++numbersPastDecimalPoint;

        if (numbersPastDecimalPoint >= decimalPlacesToDisplay)
            return final;

        if (withCommas[i] == locale.decimalPoint())
            pastDecimalPoint = true;
    }
Example #16
0
Money parseMoney(const QString& input) {
    QString cleanInput = input;
    Money result = {0,0};

    // remove group separators
    QLocale locale = QLocale::system();
    cleanInput.remove(locale.groupSeparator());

    // convert to money
    QStringList parts = cleanInput.split(locale.decimalPoint());
    if (parts.count() == 1) {
       result.integ = parts[0].toInt();
    } else if (parts.count() == 2) {
       result.integ = parts[0].toInt();
       result.fract = parts[1].toInt() * 10;
    } else {
         // error, not a number
    }

    return result;
}
QString BitcoinUnits::format(int unit, qint64 n, int nColorIn,
                                           bool fPlus, bool localized)
{
    // Note: not using straight sprintf here because we do NOT want
    // localized number formatting.
    if(!valid(unit, nColorIn))
    {
        return QString(); // Refuse to format invalid unit
    }

    QLocale locale = QLocale::c();
    QString decimal(".");
    if (localized)
    {
         decimal = QString(locale.decimalPoint());
    }

    qint64 coin = factor(unit, nColorIn);
    int num_decimals = decimals(unit, nColorIn);
    qint64 n_abs = (n > 0 ? n : -n);
    qint64 quotient = n_abs / coin;
    qint64 remainder = n_abs % coin;
    QString quotient_str = QString::number(quotient);
    QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');

    // Right-trim excess zeros after the decimal point
    int nTrim = 0;
    for (int i = remainder_str.size()-1; i>=2 && (remainder_str.at(i) == '0'); --i)
        ++nTrim;
    remainder_str.chop(nTrim);

    if (localized)
    {
       QChar thousands = locale.groupSeparator();
       int N(quotient_str.size());
       for (int i = 3; i < N; ++i)
       {
           if (i % 3 == 0)
           {
               quotient_str.insert(N - i, thousands);
           }
       }
    }
    if (n < 0)
        quotient_str.insert(0, '-');
    else if (fPlus && n > 0)
        quotient_str.insert(0, '+');
    if (DECIMALS[nColorIn] == 0)
    {
        // if (remainder != 0)
        // {
        //     printf("Remainder for atomic currency is nonzero: %" PRId64, remainder);
        // }
        return quotient_str;
    }
    else
    {
        if (localized)
        {
            QChar thousandths(' ');
            int N(remainder_str.size());
            int j = 0;
            for (int i = 3; i < N; ++i)
            {
                if (i % 3 == 0)
                {
                    remainder_str.insert(i + j, thousandths);
                    ++j;
                }
            }
        }
        return quotient_str + decimal + remainder_str;
    }
}
Example #18
0
void sysLocale::sSave()
{
  if (_code->text().trimmed().length() == 0)
  {
    QMessageBox::critical( this, tr("Cannot Save Locale"),
                           tr("<p>You must enter a Code for this Locale before "
                              "you may save it.") );
    _code->setFocus();
    return;
  }

  q.prepare( "SELECT locale_id "
             "FROM locale "
             "WHERE ( (locale_id<>:locale_id)"
             " AND (UPPER(locale_code)=UPPER(:locale_code)) );");
  q.bindValue(":locale_id", _localeid);
  q.bindValue(":locale_code", _code->text().trimmed());
  q.exec();
  if (q.first())
  {
    QMessageBox::critical( this, tr("Cannot Create Locale"),
			   tr( "A Locale with the entered code already exists."
			       "You may not create a Locale with this code." ) );
    _code->setFocus();
    return;
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  QLocale sampleLocale = generateLocale();

  if (_mode == cNew)
  {
    q.prepare( "INSERT INTO locale "
               "( locale_id, locale_code, locale_descrip,"
               "  locale_lang_id, locale_country_id, "
               "  locale_dateformat, locale_timeformat, locale_timestampformat,"
	       "  locale_intervalformat, locale_qtyformat,"
               "  locale_curr_scale,"
               "  locale_salesprice_scale, locale_purchprice_scale,"
               "  locale_extprice_scale, locale_cost_scale,"
               "  locale_qty_scale, locale_qtyper_scale,"
               "  locale_uomratio_scale, locale_percent_scale, "
               "  locale_comments, "
               "  locale_error_color, locale_warning_color,"
               "  locale_emphasis_color, locale_altemphasis_color,"
               "  locale_expired_color, locale_future_color) "
               "VALUES "
               "( :locale_id, :locale_code, :locale_descrip,"
               "  :locale_lang_id, :locale_country_id,"
               "  :locale_dateformat, :locale_timeformat, :locale_timestampformat,"
	       "  :locale_intervalformat, :locale_qtyformat,"
               "  :locale_curr_scale,"
               "  :locale_salesprice_scale, :locale_purchprice_scale,"
               "  :locale_extprice_scale, :locale_cost_scale,"
               "  :locale_qty_scale, :locale_qtyper_scale,"
               "  :locale_uomratio_scale, :local_percent_scale, "
               "  :locale_comments,"
               "  :locale_error_color, :locale_warning_color,"
               "  :locale_emphasis_color, :locale_altemphasis_color,"
               "  :locale_expired_color, :locale_future_color);" );
  }
  else if ( (_mode == cEdit) || (_mode == cCopy) )
    q.prepare( "UPDATE locale "
                "SET locale_code=:locale_code,"
                "    locale_descrip=:locale_descrip,"
                "    locale_lang_id=:locale_lang_id,"
                "    locale_country_id=:locale_country_id,"
                "    locale_dateformat=:locale_dateformat,"
                "    locale_timeformat=:locale_timeformat,"
                "    locale_timestampformat=:locale_timestampformat,"
                "    locale_intervalformat=:locale_intervalformat,"
                "    locale_qtyformat=:locale_qtyformat,"
		"    locale_curr_scale=:locale_curr_scale,"
                "    locale_salesprice_scale=:locale_salesprice_scale,"
                "    locale_purchprice_scale=:locale_purchprice_scale,"
                "    locale_extprice_scale=:locale_extprice_scale,"
                "    locale_cost_scale=:locale_cost_scale,"
                "    locale_qty_scale=:locale_qty_scale,"
                "    locale_qtyper_scale=:locale_qtyper_scale,"
                "    locale_uomratio_scale=:locale_uomratio_scale,"
                "    locale_percent_scale=:locale_percent_scale,"
                "    locale_comments=:locale_comments,"
                "    locale_error_color=:locale_error_color,"
                "    locale_warning_color=:locale_warning_color,"
                "    locale_emphasis_color=:locale_emphasis_color,"
                "    locale_altemphasis_color=:locale_altemphasis_color,"
                "    locale_expired_color=:locale_expired_color,"
                "    locale_future_color=:locale_future_color "
                "WHERE (locale_id=:locale_id);" );

  q.bindValue(":locale_id",                _localeid);
  q.bindValue(":locale_code",              _code->text());
  q.bindValue(":locale_descrip",           _description->text());
  q.bindValue(":locale_lang_id",           _language->id());
  q.bindValue(":locale_country_id",        _country->id());
  q.bindValue(":locale_curr_scale",        _currencyScale->text());
  q.bindValue(":locale_salesprice_scale",  _salesPriceScale->text());
  q.bindValue(":locale_purchprice_scale",  _purchPriceScale->text());
  q.bindValue(":locale_extprice_scale",    _extPriceScale->text());
  q.bindValue(":locale_cost_scale",        _costScale->text());
  q.bindValue(":locale_qty_scale",         _qtyScale->text());
  q.bindValue(":locale_qtyper_scale",      _qtyPerScale->text());
  q.bindValue(":locale_uomratio_scale",    _uomRatioScale->text());
  q.bindValue(":locale_percent_scale",     _percentScale->text());
  q.bindValue(":locale_comments",          _comments->toPlainText());
  q.bindValue(":locale_error_color",       _error->text());
  q.bindValue(":locale_warning_color",     _warning->text());
  q.bindValue(":locale_emphasis_color",    _emphasis->text());
  q.bindValue(":locale_altemphasis_color", _alternate->text());
  q.bindValue(":locale_expired_color",     _expired->text());
  q.bindValue(":locale_future_color",      _future->text());
  q.bindValue(":locale_dateformat",     convert(sampleLocale.dateFormat(QLocale::ShortFormat)));
  q.bindValue(":locale_timeformat",     convert(sampleLocale.timeFormat(QLocale::ShortFormat)));
  q.bindValue(":locale_timestampformat",convert(sampleLocale.dateFormat(QLocale::ShortFormat)) +
                                  " " + convert(sampleLocale.timeFormat(QLocale::ShortFormat)));
  q.bindValue(":locale_intervalformat", convert(sampleLocale.timeFormat(QLocale::ShortFormat).remove("ap", Qt::CaseInsensitive)));
  q.bindValue(":locale_qtyformat",      QString(sampleLocale.decimalPoint()) +
                                        QString(sampleLocale.negativeSign()) +
                                        QString(sampleLocale.groupSeparator()));
  q.exec();
  if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  done(_localeid);
}
Example #19
0
	/// \brief Converts string containing value and (prefix+)unit to double (Counterpart to Helper::valueToString).
	/// \param text The text containing the value and its unit.
	/// \param unit The base unit of the value.
	/// \param ok Pointer to a success-flag, true on success, false on error.
	/// \return Decoded value.
	double stringToValue(const QString &text, Unit unit, bool *ok) {
		// Check if the text is empty
		int totalSize = text.size();
		if(!totalSize){
			if(ok)
				*ok = false;
			return 0.0;
		}
		
		// Split value and unit apart
		int valueSize = 0;
		QLocale locale;
		bool decimalFound = false;
		bool exponentFound = false;
		if(text[valueSize] == locale.negativeSign())
			++valueSize;
		for(; valueSize < text.size(); ++valueSize) {
			QChar character = text[valueSize];
			
			if(character.isDigit()) {
			}
			else if(character == locale.decimalPoint() && decimalFound == false && exponentFound == false) {
				decimalFound = true;
			}
			else if(character == locale.exponential() && exponentFound == false) {
				exponentFound = true;
				if(text[valueSize + 1] == locale.negativeSign())
					++valueSize;
			}
			else {
				break;
			}
		}
		QString valueString = text.left(valueSize);
		bool valueOk = false;
		double value = valueString.toDouble(&valueOk);
		if(!valueOk) {
			if(ok)
				*ok = false;
			return value;
		}
		QString unitString = text.right(text.size() - valueSize).trimmed();
		
		if(ok)
			*ok = true;
		switch(unit) {
			case UNIT_VOLTS: {
				// Voltage string decoding
				if(unitString.startsWith('\265'))
					return value * 1e-6;
				else if(unitString.startsWith('m'))
					return value * 1e-3;
				else
					return value;
			}
			case UNIT_DECIBEL:
				// Power level string decoding
				return value;
			
			case UNIT_SECONDS:
				// Time string decoding
				if(unitString.startsWith('p'))
					return value * 1e-12;
				else if(unitString.startsWith('n'))
					return value * 1e-9;
				else if(unitString.startsWith('\265'))
					return value * 1e-6;
				else if(unitString.startsWith("min"))
					return value * 60;
				else if(unitString.startsWith('m'))
					return value * 1e-3;
				else if(unitString.startsWith('h'))
					return value * 3600;
				else
					return value;
			
			case UNIT_HERTZ:
				// Frequency string decoding
				if(unitString.startsWith('k'))
					return value * 1e3;
				else if(unitString.startsWith('M'))
					return value * 1e6;
				else if(unitString.startsWith('G'))
					return value * 1e9;
				else
					return value;
			
			case UNIT_SAMPLES:
				// Sample count string decoding
				if(unitString.startsWith('k'))
					return value * 1e3;
				else if(unitString.startsWith('M'))
					return value * 1e6;
				else if(unitString.startsWith('G'))
					return value * 1e9;
				else
					return value;
			
			default:
				if(ok)
					*ok = false;
				return value;
		}
	}
ParameterValueValidator::ParameterValueValidator(const QString& unit, QObject *parent) :
    QRegExpValidator(parent), _unit(unit)
{
    QLocale locale;
    /*This regex allows some flexibility when using fractions. if not, the user would be unable to change a value from
     * 1/4W to 1W because it would be invalid when the 4 is deleted.
     */
    QString exp=QString("^-?\\d+/?\\d*([kKMGTPEZYmunpfazy\\x{03BC}]|\\%1)?\\d*[kKMGTPEZYmunpfazy\\x{03BC}]?").arg(locale.decimalPoint());
    if(unit.isEmpty()) {
        exp.append('$');
    }
    else {
        exp.append(unit).append("?$");
    }
    QRegExp regExp(exp, Qt::CaseSensitive, QRegExp::RegExp2);
    setRegExp(regExp);
}
Example #21
0
bool InitSystem(void)
{
	setlocale(LC_ALL, "");
	systemData.locale = QLocale::system();
	systemData.locale.setNumberOptions(QLocale::OmitGroupSeparator);
	QLocale::setDefault(systemData.locale);

	QTextStream out(stdout);

	systemData.homedir = QDir::homePath() + QDir::separator();

#ifdef WIN32 /* WINDOWS */
  systemData.sharedDir = (QDir::currentPath() + QDir::separator());
#else
	systemData.sharedDir = QString(SHARED_DIR) + QDir::separator();
#endif  /* WINDOWS */

	//logfile
#ifdef WIN32 /* WINDOWS */
	systemData.logfileName = systemData.homedir + "mandelbulber_log.txt";
#else
	systemData.logfileName = systemData.homedir + ".mandelbulber_log.txt";
#endif
	FILE *logfile = fopen(systemData.logfileName.toUtf8().constData(), "w");
	fclose(logfile);

	out << "Mandelbulber " << MANDELBULBER_VERSION_STRING << ", build date: " << QString(__DATE__) << "\n";
	out << "Log file name: " << systemData.logfileName << endl;
	WriteLogString("Mandelbulber version", QString(MANDELBULBER_VERSION_STRING));
	WriteLogString("Mandelbulber compilation date", QString(__DATE__) + " " + QString(__TIME__));

	//detecting number of CPU cores
	systemData.numberOfThreads = get_cpu_count();
	//NR_THREADS = 1;

	printf("Detected %d CPUs\n", systemData.numberOfThreads);
	WriteLogDouble("CPUs detected", systemData.numberOfThreads);

#ifdef ONETHREAD //for debugging
	NR_THREADS = 1;
#endif

	//data directory location
#ifdef WIN32 /* WINDOWS */
	systemData.dataDirectory = systemData.homedir  + "mandelbulber" + QDir::separator();
#else
	systemData.dataDirectory = systemData.homedir  + ".mandelbulber" + QDir::separator();
#endif
	out << "Default data directory: " << systemData.dataDirectory << endl;
	WriteLogString("Default data directory", systemData.dataDirectory);

	systemData.thumbnailDir = systemData.dataDirectory + "thumbnails" + QDir::separator();

	systemData.autosaveFile = systemData.dataDirectory + ".autosave.fract";

	//*********** temporary set to false ************
	systemData.noGui = false;

	systemData.lastSettingsFile = systemData.dataDirectory + "settings" + QDir::separator() + QString("settings.fract");
	systemData.lastImageFile = systemData.dataDirectory + "images" + QDir::separator() + QString("image.jpg");
	systemData.lastImagePaletteFile = systemData.sharedDir + "textures" + QDir::separator() + QString("colour palette.jpg");

	QLocale systemLocale = QLocale::system();
	systemData.decimalPoint = systemLocale.decimalPoint();
	WriteLogString("Decimal point", QString(systemData.decimalPoint));

	systemData.supportedLanguages.insert("en_EN", "English");
	systemData.supportedLanguages.insert("pl_PL", "Polski");
	systemData.supportedLanguages.insert("de_DE", "Deutsch");
	systemData.supportedLanguages.insert("it_IT", "Italiano");

	//get number of columns of console
#ifdef WIN32
	systemData.terminalWidth = 80;
#else
	handle_winch(-1);
#endif

	return true;
}
Example #22
0
/*!
 * \fn EDSBPrecio::keyPressEvent ( QKeyEvent * event )
 * \param evento
 */
void EDSBPrecio::keyPressEvent( QKeyEvent * event )
{
 if( event->key() == Qt::Key_Period
  && event->modifiers().testFlag( Qt::KeypadModifier ) )
 {
     // Convierto el ingreso en una coma
     QLocale locale;
     int pos_cursor = this->lineEdit()->cursorPosition();
     int pos_coma = this->lineEdit()->text().indexOf( "," );
     if( pos_coma != -1 && pos_cursor < pos_coma ) {
         this->lineEdit()->setText( this->lineEdit()->text().remove( pos_cursor, abs( pos_coma-pos_cursor ) ) );
     }
     this->lineEdit()->setText( this->lineEdit()->text().split( "," ).first().replace( ",", "" ).append( locale.decimalPoint() ) );
     event->accept();
 } else {
       QDoubleSpinBox::keyPressEvent( event );
 }
}