Пример #1
0
void SchemeDisplayWizard::accepted() {
    qDebug() << "void SchemeDisplayWizard::accepted()";
    qDebug() << "indicator" << field("indicator");
    qDebug() << "category" << field("category");
    QVector<QString> curves;
    auto schemes = getSchemes(scheme::fromString(field("category").toString()), mParasManager->getAbstractSchemeList(), curves);
    if(schemes.empty()) {
        QMessageBox::warning(
            this,
            tr("方案指标演示"),
            tr("没有可以演示的数据,放弃演示"),
            QMessageBox::Ok);
        return;
    }

    QWidget* widget = nullptr;
    int startYear = Config::config.Int("START_YEAR");
    int endYear = Config::config.Int("END_YEAR");
    if(field("category").toString().contains(tr("分龄"))) {
        widget = PyramidController::createPyramidController(curves, schemes, startYear, endYear);
    } else {
        auto indicators = getIndicators(schemes, field("indicator").toString());
        if(field("dispMode") == IndicatorSel::MAP_DISP_MODE) {
            widget = MapType1::makeMapType1(curves, indicators, startYear, endYear);
        } else {
            widget = SequenceController::createSequenceController(curves, indicators, startYear, endYear);
        }
    }
    widget->show();
}
bool LogicDetailParser::getTime(string& tempTime1, string& tempTime2, int& tempHours1, int& tempHours2){
	int hoursTimeCheck;
	int symbolledTimeCheck;
	int meridiemTimeCheck;
	int hours;
	string lowercaseText = textChangeLowercase(_taskDescription);
	getIndicators(lowercaseText);

	hoursTimeCheck = getHoursTime(lowercaseText, hours);
	if(hoursTimeCheck == ERROR)
		return false;
	else if(hoursTimeCheck == FOUND){
		tempHours1 = hours;
		tempTime1 = _time;
		_taskDescription = trimFoundText(_taskDescription, _time);
	}

	lowercaseText = textChangeLowercase(_taskDescription);
	getIndicators(lowercaseText);

	symbolledTimeCheck = getSymbolledTime(lowercaseText, hours);
	if(symbolledTimeCheck == ERROR)
		return false;
	else if(symbolledTimeCheck == FOUND){
		tempHours2 = hours;
		tempTime2 = _time;
		_taskDescription = trimFoundText(_taskDescription, _time);
	}

	if(symbolledTimeCheck == NOTFOUND){
		lowercaseText = textChangeLowercase(_taskDescription);
		getIndicators(lowercaseText);

		meridiemTimeCheck = getMeridiemTime(lowercaseText, hours);
		if(meridiemTimeCheck == ERROR)
			return false;
		else if(meridiemTimeCheck == FOUND){
			tempHours2 = hours;
			tempTime2 = _time;
			_taskDescription = trimFoundText(_taskDescription, _time);
		}
	}
	return true;
}
bool LogicDetailParser::parserHoursTime(string text, int& hours){
	while(_hrsPosition != NOTSTATED){
		if(_hrsPosition < POINTFOUR){}
		else if(isdigit(text[_hrsPosition - POINTFOUR]) && isdigit(text[_hrsPosition - POINTTHREE]) && isdigit(text[_hrsPosition - POINTTWO]) && isdigit(text[_hrsPosition - POINTONE])){
			hours = stoi(text.substr((_hrsPosition - POINTFOUR), POINTFOUR));
			_time = text.substr((_hrsPosition - POINTFOUR), POINTSEVEN);
			return true;
		}
		else if(_hrsPosition >= POINTFIVE){
			if(isdigit(text[_hrsPosition - POINTFIVE]) && isdigit(text[_hrsPosition - POINTFOUR]) && isdigit(text[_hrsPosition - POINTTHREE]) && isdigit(text[_hrsPosition - POINTTWO]) && (_hrsPosition - POINTONE) == SPACECODE){
				hours = stoi(text.substr((_hrsPosition - POINTFIVE), POINTFOUR));
				_time = text.substr((_hrsPosition - POINTFIVE), POINTEIGHT);
				return true;
			}
		}

		text = text.substr((_hrsPosition + POINTONE), (text.size() - (_hrsPosition + POINTONE)));
		getIndicators(text);
	}
	return false;
}
bool LogicDetailParser::parser(Task& task, string text, string operation){
	int dateCheck;
	int timeCheck;
	string tempDate;
	string lowercaseText = textChangeLowercase(text);

	_hoursFlag = false;
	_taskDescription = text;
	_time = CANNOTFIND;
	_date = CANNOTFIND;

	getIndicators(lowercaseText);

	if(_slashPosition == NOTSTATED && _hrsPosition == NOTSTATED &&
		_dotPosition == NOTSTATED && _colonPosition == NOTSTATED &&
		_amPosition == NOTSTATED && _pmPosition == NOTSTATED){
			task.setTaskDescription(text);
			return true;
	}

	if(_slashPosition != NOTSTATED){
		dateCheck = findDate(task, lowercaseText);
		if(dateCheck == ERROR)
			return false;
		else if(dateCheck == FOUND){
			tempDate = _date;
			_taskDescription = trimFoundText(_taskDescription, _date);

			lowercaseText = textChangeLowercase(_taskDescription);
			getIndicators(lowercaseText);

			dateCheck = findDate(task, lowercaseText);
			if(dateCheck == ERROR)
				return false;
			else if(dateCheck == FOUND)
				_taskDescription = trimFoundText(_taskDescription, _date);
			else if(dateCheck == NOTFOUND)
				setTaskDate(task, task.getStartDay(), task.getStartMonth(), task.getStartYear());
		}
	}
	_date = tempDate;

	if(!findTime(task, textChangeLowercase(text)))
		return false;

	removeUnwantedText();
	if(_taskDescription.size() != POINTZERO)
		task.setTaskDescription(_taskDescription);

	if(operation == "change"){
		if(task.getStartDay() == task.getEndDay() && _hoursFlag)
			task.setEndDay(task.getStartDay() + POINTONE);
		return true;
	}

	if(operation == "add"){
		if(task.getStartDay() == task.getEndDay() && _hoursFlag)
			task.setEndDay(task.getStartDay() + POINTONE);

		if (_time != CANNOTFIND && _date != CANNOTFIND){}
		else if (_time == CANNOTFIND){
			task.setStartTime(900);
			task.setEndTime(1800);
		}
		else if (_date == CANNOTFIND)
			setDate(task);
		else
			//floating
			return false;
	}
}
bool LogicDetailParser::parserDate(string text, int& day, int& month, int& year){
	int startPosition, endPosition;

	while(_slashPosition != NOTSTATED){
		if(_slashPosition == POINTZERO){}
		//date format: 1/1/11 or 11/1/11 or 1/1/1111 or 11/1/1111
		else if(_slashPosition + POINTFOUR <= text.size() - POINTONE){
			if(isdigit(text[_slashPosition - POINTONE]) && isdigit(text[_slashPosition + POINTONE]) && text[_slashPosition + POINTTWO] == SLASHCODE && isdigit(text[_slashPosition + POINTTHREE]) && isdigit(text[_slashPosition + POINTFOUR])){
				day = stoi(text.substr((_slashPosition - POINTONE), POINTONE));
				month = stoi(text.substr((_slashPosition + POINTONE), POINTONE));
				year = stoi(text.substr((_slashPosition + POINTTHREE), POINTTWO));
				startPosition = _slashPosition - POINTONE;
				endPosition = POINTSIX;
				if(_slashPosition == POINTONE){
					// check if year is written as 4 digits: x/x/xxxx
					if(_slashPosition + POINTSIX <= text.size() - POINTONE){
						if(text.size() - _slashPosition >= POINTSEVEN){
							if(isdigit(text[_slashPosition + POINTFIVE]) && isdigit(text[_slashPosition + POINTSIX])){
								year = stoi(text.substr((_slashPosition + POINTTHREE), POINTFOUR));
								endPosition = POINTEIGHT;
							}
						}
					}
				}
				else{ 
					// check if day is 2 digits: xx/x/xx or xx/x/xxxx
					if(_slashPosition + POINTFOUR <= text.size() - POINTONE){
						if(isdigit(text[_slashPosition - POINTTWO])){
							day = stoi(text.substr((_slashPosition - POINTTWO), POINTTWO));
							startPosition = _slashPosition - POINTTWO;
							endPosition = POINTSEVEN;
						}
					}
					// check if year is 4 digits: xx/x/xxxx or x/x/xxxx
					if(_slashPosition + POINTSIX <= text.size() - POINTONE){
						if(text.size() - _slashPosition >= POINTSEVEN){
							if(isdigit(text[_slashPosition + POINTFIVE]) && isdigit(text[_slashPosition + POINTSIX])){
								year = stoi(text.substr((_slashPosition + POINTTHREE), POINTFOUR));
								if(isdigit(text[_slashPosition - POINTTWO]))
									endPosition = POINTNINE;
								else
									endPosition = POINTEIGHT;
							}
						}
					}
				}
				_date = text.substr(startPosition, endPosition);
				return true;
			}
			// date format: 1/11/11 or 11/11/11 or 1/11/1111 or 11/11/1111
			else if(_slashPosition + POINTFIVE <= text.size() - POINTONE){
				if(text.size() - _slashPosition >= POINTSIX){
					if(isdigit(text[_slashPosition - POINTONE]) && isdigit(text[_slashPosition + POINTONE]) && isdigit(text[_slashPosition + POINTTWO]) && text[_slashPosition + POINTTHREE] == SLASHCODE && isdigit(text[_slashPosition + POINTFOUR]) && isdigit(text[_slashPosition + POINTFIVE])){
						day = stoi(text.substr((_slashPosition - POINTONE), POINTONE));
						month = stoi(text.substr((_slashPosition + POINTONE), POINTTWO));
						year = stoi(text.substr((_slashPosition + POINTFOUR), POINTTWO));
						startPosition = _slashPosition - POINTONE;
						endPosition = POINTSEVEN;

						if(_slashPosition == POINTONE){
							// check if year is written as 4 digits: x/xx/xxxx
							if(_slashPosition + POINTSEVEN <= text.size() - POINTONE){
								if(text.size() - _slashPosition >= POINTEIGHT){
									if(isdigit(text[_slashPosition + POINTSIX]) && isdigit(text[_slashPosition + POINTSEVEN])){
										year = stoi(text.substr((_slashPosition + POINTFOUR), POINTFOUR));
										endPosition = POINTNINE;
									}
								}
							}
						}
						else{ 
							// check if day is 2 digits: xx/xx/xx or xx/xx/xxxx
							if(_slashPosition + POINTFIVE <= text.size() - POINTONE){
								if(isdigit(text[_slashPosition - POINTTWO])){
									day = stoi(text.substr((_slashPosition - POINTTWO), POINTTWO));
									startPosition = _slashPosition - POINTTWO;
									endPosition = POINTEIGHT;
								}
							}
							// check if year is 4 digits: xx/xx/xxxx or x/xx/xxxx
							if(_slashPosition + POINTSEVEN <= text.size() - POINTONE){
								if(text.size() - _slashPosition >= POINTEIGHT){
									if(isdigit(text[_slashPosition + POINTSIX]) && isdigit(text[_slashPosition + POINTSEVEN])){
										year = stoi(text.substr((_slashPosition + POINTFOUR), POINTFOUR));
										if(isdigit(text[_slashPosition - POINTTWO]))
											endPosition = POINTTEN;
										else
											endPosition = POINTNINE;
									}
								}
							}
						}
						_date = text.substr(startPosition, endPosition);
						return true;
					}
				}
			}
		}
		text = text.substr((_slashPosition + POINTONE), (text.size() - (_slashPosition + POINTONE)));
		getIndicators(text);
	}
	return false;
}