bool QComposeInputContext::filterEvent(const QEvent *event) { // if there were errors when generating the compose table input // context should not try to filter anything, simply return false if ((m_tableState & TableGenerator::NoErrors) != TableGenerator::NoErrors) return false; QKeyEvent *keyEvent = (QKeyEvent *)event; // should pass only the key presses if (keyEvent->type() != QEvent::KeyPress) { return false; } int keyval = keyEvent->key(); int keysym = 0; if (ignoreKey(keyval)) return false; QString text = keyEvent->text(); if (!composeKey(keyval) && text.isEmpty()) return false; keysym = keyEvent->nativeVirtualKey(); int nCompose = 0; while (m_composeBuffer[nCompose] != 0 && nCompose < QT_KEYSEQUENCE_MAX_LEN) nCompose++; if (nCompose == QT_KEYSEQUENCE_MAX_LEN) { reset(); nCompose = 0; } m_composeBuffer[nCompose] = keysym; // check sequence if (checkComposeTable()) return true; return false; }
void query(int iThread, const TC_DBConf & conf, map<string,string>& mSqlPart, map<string, vector<double> > &result, string &sRes, QueryParam &queryParam,string &sPolicy) { string sUid = mSqlPart.find("uid")->second; TLOGDEBUG("queryData " << sUid << "thread iIndex:" << iThread << endl); int64_t tStart = TNOWMS; try { //dateFrom =>> 20111120 string dateFrom = mSqlPart["date1"]; string dateTo = mSqlPart["date2"]; //tflagFrom =>> 2360 string tflagFrom = mSqlPart["tflag1"]; string tflagTo = mSqlPart["tflag2"]; // 输入tflag 条件检查 if (dateFrom.length() != 8 || dateTo.length() != 8 || tflagFrom.length() != 4 || tflagTo.length() != 4 || TC_Common::isdigit(tflagFrom) == false || TC_Common::isdigit(tflagTo) == false) { sRes += "ret:-1|iDb:" + TC_Common::tostr(iThread) + "|wrong tflag:" + tflagFrom + "-" + tflagTo + "\n"; TLOGERROR("query sUid:" << sUid << sRes << endl); queryParam._run_result = -1; queryParam._atomic.inc(); if(queryParam._atomic.get() == queryParam._run_times) { TC_ThreadLock::Lock lock(queryParam._monitor); queryParam._monitor.notifyAll(); } return ; } //groupCond =>> "where slave_name like 'MTTsh2.BrokerServer' and f_tflag >='0000' and f_tflag <='2360' and f_date = '20111120'" string whereCond = mSqlPart["whereCond"]; string::size_type position; if((position =whereCond.find("policy")) != string::npos) { string temp = whereCond.substr(position); if((position =whereCond.find("Avg")) != string::npos) { sPolicy = "Avg"; } else if((position =whereCond.find("Max")) != string::npos) { sPolicy = "Max"; } else if((position =whereCond.find("Min")) != string::npos) { sPolicy = "Min"; } else { sPolicy = "NULL"; } } //groupCond =>> "group by f_date, f_tflag" string groupCond = mSqlPart["groupCond"]; //sumField =>> "succ_count, timeout_count"; string sumField = mSqlPart["sumField"]; //groupField =>> "f_date, f_tflag" string groupField = mSqlPart["groupField"]; //selectCond =>> "succ_count, timeout_count, f_date, f_tflag" string selectCond = sumField +"," + groupField; //日期格式20111019 string::size_type pos = string::npos; string tmpDate = "f_date"; if ((pos = selectCond.find(tmpDate, 0)) != string::npos) { selectCond.replace(pos, tmpDate.length(), "DATE_FORMAT( f_date, '%Y%m%d') as f_date"); } string sDbName = mSqlPart["dataid"]; string ignoreKey(""); vector<string> vGroupField = TC_Common::sepstr<string>(groupField, ", "); vector<string> vSumField = TC_Common::sepstr<string>(sumField, ", "); TC_Mysql tcMysql; TC_DBConf tcDbConf = conf; /*if(bFlag) { tcDbConf = g_app.getDbInfo(iThread); } else { tcDbConf = g_app.getDbInfo(iThread); }*/ tcDbConf._database = sDbName; tcMysql.init(tcDbConf); string sTbNamePre = tcDbConf._database + "_"; string sTbName(""); string sSql(""); //select range by f_date and f_tflag for(string day = dateFrom; day <= dateTo; day = dateInc(day)) { for(string tflag = tflagFrom; tflag <= tflagTo && (tflag.substr(0,2) < "24"); tflag = tFlagInc(tflag)) { //table name:tars_2012060723 sTbName = sTbNamePre + day + tflag.substr(0,2); sSql = "select " + selectCond + " from " + sTbName + " " + ignoreKey + whereCond + " order by null;"; tars::TC_Mysql::MysqlData res = tcMysql.queryRecord(sSql); TLOGINFO(sUid << "res.size:" << res.size() << "|sSql:" << sSql << endl); // result is key:value pair; //sKey 由groupby生成 //value由index生成 //int64_t t2Start = TNOWMS; for(size_t iRow = 0; iRow < res.size(); iRow++) { string sKey = ""; for(size_t j = 0; j < vGroupField.size(); j++) { sKey += sKey.empty()?"":","; sKey += res[iRow][vGroupField[j]]; } map<string,vector<double> >::iterator itResult = result.find(sKey); if (itResult != result.end()) { vector<double>& data = itResult->second; for (size_t j = 0; j < vSumField.size() && j < data.size(); j++) { data.push_back(TC_Common::strto<double>(res[iRow][vSumField[j]]));// 相同key的值 求和 } } else { vector<double>& vRes = result[sKey]; for(size_t j = 0; j < vSumField.size(); j++) { vRes.push_back( TC_Common::strto<double>(res[iRow][vSumField[j]]));; } } TLOGINFO("query iDb:" << iThread <<" {"<< sKey << ":" << TC_Common::tostr(result[sKey]) << "}" << endl); } TLOGINFO("query iDb :" << iThread << " day:" << day <<" tflag:" << tflag << endl); } } //day sRes = "ret:0 iDb:" + TC_Common::tostr(iThread) + "\n"; //queryParam._atomic.inc(); } catch(TC_Mysql_Exception & ex) { sRes = "ret:-1|iDb:" + TC_Common::tostr(iThread) + string("|exception:") + ex.what() + "\n"; TLOGERROR("query sUid:" << sUid << "query:" << sRes << endl); queryParam._run_result = -1; //queryParam._atomic.inc(); } catch(exception & ex) { sRes = "ret:-1|iDb:" + TC_Common::tostr(iThread) + string("|exception:") + ex.what() + "\n"; TLOGERROR("query sUid:" << sUid << "query:" << sRes << endl); queryParam._run_result = -1; //queryParam._atomic.inc(); } int64_t tEnd = TNOWMS; TLOGDEBUG("query sUid:" << sUid << "exit query iDb:" << iThread <<"|timecost(ms):" << (tEnd - tStart) << "|res:" << sRes << endl); queryParam._atomic.inc(); if(queryParam._atomic.get() == queryParam._run_times) { { TC_ThreadLock::Lock lock(queryParam._monitor); queryParam._monitor.notifyAll(); } TLOGDEBUG("query sUid:" << sUid << "notify query finish." << endl); } }