bool TvShowProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { QVariant leftData = sourceModel()->data(left,this->sortRole()); QVariant rightData = sourceModel()->data(right,this->sortRole()); if(leftData.type() == QVariant::Date) { QDate ldate(leftData.toDate()); QDate rdate(rightData.toDate()); if (!ldate.isValid()) { return false; } else if (!rdate.isValid()) { return true; } else { return ldate < rdate; } } else { qDebug() << "ProxyModel::lessThan: incoming data was not a QDate"; return false; } }
// Method to store satellite data in this class' data map void SatDataReader::loadData(void) throw(FFStreamError, gpstk::StringUtils::StringException) { // Do this until end-of-file reached or something else happens while(1) { try { std::string line; formattedGetLine(line, true); // If line is too long, we throw an exception if (line.size()>255) { FFStreamError e("Line too long"); GPSTK_THROW(e); } // Let's find and strip comments, wherever they are if( StringUtils::firstWord(line)[0] == '#' ) { formattedGetLine(line, true); } std::string::size_type idx = line.find('#'); if( !(idx == std::string::npos) ) { line = line.substr(0, idx); } // We erase the header (first line) if( StringUtils::firstWord(line) == "Launch" ) { formattedGetLine(line, true); } // Remove trailing and leading blanks line = StringUtils::strip(line); // Skip blank lines if (line.size()==0) { continue; } // Let's start to get data out of file // Launch date string ldate(StringUtils::stripFirstWord(line)); // Deactivation date string ddate(StringUtils::stripFirstWord(line)); // GPS number string gnumber(StringUtils::stripFirstWord(line)); // PRN number string prn(StringUtils::stripFirstWord(line)); // Block tipe string block(StringUtils::upperCase( StringUtils::stripFirstWord(line))); // Get satellite id. If it doesn't fit GPS or Glonass, it is // marked as unknown SatID sat(StringUtils::asInt(prn),SatID::systemUnknown); // Let's identify satellite system if(block[0] == 'I') { sat.system = SatID::systemGPS; } else { if (block.substr(0, 3) == "GLO") { sat.system = SatID::systemGlonass; } } // Declare the structure to store data SatDataReader::svData data; data.block = block; data.gpsNumber = StringUtils::asInt(gnumber); // Get launch date in a proper format if(ldate[0] != '0') { ldate = StringUtils::translate(ldate, "-", " "); scanTime(data.launchDate, ldate, "%Y %m %d"); } // Get deactivation date in a proper format if(ddate[0] != '0') { ddate = StringUtils::translate(ddate, "-", " "); scanTime(data.deactivationDate, ddate, "%Y %m %d"); } // It's not a good way!!! data.launchDate.setTimeSystem(TimeSystem::Any); data.deactivationDate.setTimeSystem(TimeSystem::Any); // Insert data in data map setData(sat, data); } // End of try block catch (EndOfFile& e) { // Close this data stream (*this).close(); return; } catch (...) { // Close this data stream (*this).close(); return; } } // End of while(1) } // End of method 'SatDataReader::loadData()'