Example #1
0
void MainWindow::updateStatusBar()
{
    //std::cout << "update status bar\n";
    Spreadsheet *ss = static_cast<Spreadsheet *> (tabWidget ->currentWidget());
    locationLabel->setText(ss->currentLocation());
    formulaLabel->setText(ss->currentFormula());
}
Example #2
0
void Datapicker::exportView() const {
	Spreadsheet* s = currentSpreadsheet();
	if (s) {
		s->exportView();
	} else {
		m_image->exportView();
	}
}
Example #3
0
void Datapicker::printPreview() const {
	Spreadsheet* s = currentSpreadsheet();
	if (s) {
		s->printPreview();
	} else {
		m_image->printPreview();
	}
}
Example #4
0
int main() {
    std::cout << "1";
    Spreadsheet s;
    std::cout << "1";
    String st(1,2,"000");
    std::cout << "1";
    s.add(st);
    std::cout << "1";
}
Example #5
0
bool Datapicker::printPreview() const {
	Spreadsheet* s = currentSpreadsheet();
    bool ret;
	if (s) {
        ret = s->printPreview();
	} else {
        ret = m_image->printPreview();
	}
    return ret;
}
Example #6
0
bool Datapicker::exportView() const {
	Spreadsheet* s = currentSpreadsheet();
    bool ret;
	if (s) {
        ret = s->exportView();
	} else {
        ret = m_image->exportView();
	}
    return ret;
}
Example #7
0
void WorkbookView::showTabContextMenu(const QPoint& point) {
	QMenu* menu = 0;
	AbstractAspect* aspect = m_workbook->child<AbstractAspect>(m_tabWidget->currentIndex());
	Spreadsheet* spreadsheet = dynamic_cast<Spreadsheet*>(aspect);
	if (spreadsheet) {
		menu = spreadsheet->createContextMenu();
	} else {
		Matrix* matrix = dynamic_cast<Matrix*>(aspect);
		if (matrix)
			menu = matrix->createContextMenu();
	}

	if (menu)
		menu->exec(m_tabWidget->mapToGlobal(point));
}
Example #8
0
void TeX1Display::OutputASingleTeXCategory(
    const Spreadsheet & x,const Categories & cat,float ColumnWidth
      ) {
  const vector<GroebnerRule> & RULES = x.RULES();
  const VariableSet & knowns = cat.knowns();
  const VariableSet & unknowns = cat.unknowns();
  outputsource() << "\\rule[3pt]{" << ColumnWidth << "in}{.7pt}\\\\\n";
  outputsource() << "The expressions with unknown variables ";
  printTeXVariableSet(unknowns);
  
  outputsource() << "\\\\\n";

  outputsource() << "and knowns ";
  printTeXVariableSet(knowns);
  outputsource() << "\\smallskip\\\\\n";

  const list<int> & rules = cat.ruleNumbers();
  list<int>::const_iterator ww = rules.begin();
  const int sz = rules.size();
  for(int j=1;j<sz;++j,++ww) {
    printNotLastRule(RULES[*ww]);
   };
   if(sz!=1) {
    printLastRule(RULES[*ww]);
   };
   outputsource().flush();
};
Example #9
0
void MainWindow::sort()
{
    SortDialog dialog(this);
    Spreadsheet *ss = static_cast<Spreadsheet *> (tabWidget ->currentWidget());
    QTableWidgetSelectionRange range = ss -> selectedRange();
    dialog.setColumnRange('A' + range.leftColumn(), 'A' + range.rightColumn());
    if (dialog.exec())
    {
        SpreadsheetCompare compare;
        compare.keys[0] = dialog.primaryColumnCombo->currentIndex();
        compare.keys[1] = dialog.secondaryColumnCombo->currentIndex() - 1;
        compare.keys[2] = dialog.tertiaryColumnCombo->currentIndex() - 1;
        compare.ascending[0] = (dialog.primaryOrderCombo->currentIndex() == 0);
        compare.ascending[1] = (dialog.secondaryOrderCombo->currentIndex() == 0);
        compare.ascending[2] = (dialog.tertiaryOrderCombo->currentIndex() == 0);
        ss->sort(compare);
    }
}
Example #10
0
void TeX1Display::Build(const Categories & x,const Spreadsheet & y) {
  const vector<GroebnerRule> & RULES = y.RULES();
  const list<int> & L = x.ruleNumbers();
  const int sz = L.size();
  list<int>::const_iterator w = L.begin();
  for(int i=1;i<=sz;++i,++w) {
    int j = *w;
    GBStream << "j is:" << j << '\n';
    const GroebnerRule & r = RULES[j];
    outputsource().put(r);
    outputsource() << '\n';
  };
};
Example #11
0
void TeX1Display::OutputANumberCategoryForTeX(
     const Spreadsheet & x,int n,float ColumnWidth
    ) {
#if 0
  bool outputedHeader = false;
#endif
  const list<Categories> & C  = x.categories()[n];
  list<Categories>::const_iterator w = C.begin();
  const int sz = C.size();
  for(int i=1;i<=sz;++i,++w) {
    const Categories & temp = *w;
    OutputASingleTeXCategory(x,temp,ColumnWidth);
  };
};
Example #12
0
/*!
    reads the content of the file \c fileName to the data source \c dataSource or return as string for preview.
    Uses the settings defined in the data source.
*/
QString AsciiFilterPrivate::readData(const QString & fileName, AbstractDataSource* dataSource, AbstractFileFilter::ImportMode mode, int lines){
	QStringList dataString;

	QIODevice *device = KFilterDev::deviceForFile(fileName);
	if (!device->open(QIODevice::ReadOnly))
		return QString();

	QTextStream in(device);

	//TODO implement
	// if (transposed)
	//...

	//skip rows, if required
	for (int i=0; i<startRow-1; i++){
        //if the number of rows to skip is bigger then the actual number
		//of the rows in the file, then quit the function.
		if( in.atEnd() ) {
			if (mode==AbstractFileFilter::Replace) {
				//file with no data to be imported. In replace-mode clear the data source
				if(dataSource != NULL)
					dataSource->clear();
			}
			return QString();
		}

		in.readLine();
	}

	//parse the first row:
	//use the first row to determine the number of columns,
	//create the columns and use (optionaly) the first row to name them
	if( in.atEnd() ) {
		if (mode==AbstractFileFilter::Replace) {
			//file with no data to be imported. In replace-mode clear the data source
			if(dataSource != NULL)
				dataSource->clear();
		}
		return QString();
	}

	QString line = in.readLine();
	if( simplifyWhitespacesEnabled)
		line = line.simplified();

	// determine separator
	QString separator;
	QStringList lineStringList;
	if( separatingCharacter == "auto" ){
		QRegExp regExp("(\\s+)|(,\\s+)|(;\\s+)|(:\\s+)");
		lineStringList = line.split( regExp, QString::SplitBehavior(skipEmptyParts) );

		//determine the separator
		if (lineStringList.size()){
			int length1 = lineStringList.at(0).length();
			if (lineStringList.size()>1){
				int pos2 = line.indexOf(lineStringList.at(1),length1);
				separator = line.mid(length1, pos2-length1);
			}else {
				separator = line.right(line.length()-length1);
			}
		}
	}else {
		separator = separatingCharacter.replace(QLatin1String("TAB"), QLatin1String("\t"), Qt::CaseInsensitive);
		separator = separatingCharacter.replace(QLatin1String("SPACE"), QLatin1String(" "), Qt::CaseInsensitive);
		lineStringList = line.split( separator, QString::SplitBehavior(skipEmptyParts) );
	}
#ifdef QT_DEBUG
 	qDebug() << "separator '"<<separator << "'";
#endif

	if (endColumn == -1)
		endColumn = lineStringList.size(); //use the last available column index

	QStringList vectorNameList;
	if ( headerEnabled ){
		vectorNameList = lineStringList;
	}else{
		//create vector names out of the space separated vectorNames-string, if not empty
		if (!vectorNames.isEmpty()){
			vectorNameList = vectorNames.split(' ');
		}
	}

	//qDebug()<<"	vector names ="<<vectorNameList;

	int actualRows = AsciiFilter::lineNumber(fileName);	// data rows
	int actualEndRow;
	if (endRow == -1)
		actualEndRow = actualRows;
	else if (endRow > actualRows-1)
		actualEndRow = actualRows-1;
	else
		actualEndRow = endRow;
	int actualCols=endColumn-startColumn+1;

	if (headerEnabled)
		actualRows = actualEndRow-startRow;
	else
		actualRows = actualEndRow-startRow+1;
	if (lines == -1)
		lines=actualRows;

#ifdef QT_DEBUG
	qDebug()<<"	start column ="<<startColumn;
	qDebug()<<"	end column ="<<endColumn;
	qDebug()<<"	actual cols ="<<actualCols;
	qDebug()<<"	start row ="<<startRow;
	qDebug()<<"	end row ="<<actualEndRow;
	qDebug()<<"	actual rows ="<<actualRows;
	qDebug()<<"	lines ="<<lines;
#endif

	int currentRow=0; //indexes the position in the vector(column)
	int columnOffset=0; //indexes the "start column" in the spreadsheet. Starting from this column the data will be imported.
	//pointers to the actual data containers
	QVector<QVector<double>*> dataPointers;

	if(dataSource != NULL)
		columnOffset = dataSource->create(dataPointers, mode, actualRows, actualCols, vectorNameList);

	//header: import the values in the first line, if they were not used as the header (as the names for the columns)
	bool isNumber;
	if (!headerEnabled){
		for ( int n=0; n<actualCols; n++ ){
			if (n<lineStringList.size()) {
				const double value = lineStringList.at(n).toDouble(&isNumber);
				if (dataSource != NULL)
					isNumber ? dataPointers[n]->operator[](0) = value : dataPointers[n]->operator[](0) = NAN;
				else
					isNumber ? dataString<<QString::number(value)<<" " : dataString<<QLatin1String("NAN ");
			} else {
				if (dataSource != NULL)
					dataPointers[n]->operator[](0) = NAN;
				else
					dataString<<QLatin1String("NAN ");
			}
		}
		dataString<<"\n";
		currentRow++;
	}

	//Read the remainder of the file.
	for (int i=currentRow; i<qMin(lines,actualRows); i++){
		line = in.readLine();

		if(simplifyWhitespacesEnabled)
			line = line.simplified();

		//skip empty lines
		if (line.isEmpty())
			continue;

		if( line.startsWith(commentCharacter) == true ){
			currentRow++;
			continue;
		}

		lineStringList = line.split( separator, QString::SplitBehavior(skipEmptyParts) );

		// TODO : read strings (comments) or datetime too
		for ( int n=0; n<actualCols; n++ ){
			if (n<lineStringList.size()) {
				const double value = lineStringList.at(n).toDouble(&isNumber);
				if (dataSource != NULL)
					isNumber ? dataPointers[n]->operator[](currentRow) = value : dataPointers[n]->operator[](currentRow) = NAN;
				else
					isNumber ? dataString<<QString::number(value)<<" " : dataString<<QString("NAN ");
			} else {
				if (dataSource != NULL)
					dataPointers[n]->operator[](currentRow) = NAN;
				else
					dataString<<QLatin1String("NAN ");
			}
		}

		dataString<<"\n";
		currentRow++;
		emit q->completed(100*currentRow/actualRows);
	}

	if (!dataSource)
		return dataString.join("");

	//make everything undo/redo-able again
	//set the comments for each of the columns
	Spreadsheet* spreadsheet = dynamic_cast<Spreadsheet*>(dataSource);
	if (spreadsheet) {
		//TODO: generalize to different data types
		QString comment = i18np("numerical data, %1 element", "numerical data, %1 elements", headerEnabled ? currentRow : currentRow+1);
		for ( int n=startColumn; n<=endColumn; n++ ){
			Column* column = spreadsheet->column(columnOffset+n-startColumn);
			column->setComment(comment);
			column->setUndoAware(true);
			if (mode==AbstractFileFilter::Replace) {
				column->setSuppressDataChangedSignal(false);
				column->setChanged();
			}
		}
		spreadsheet->setUndoAware(true);
		return dataString.join("");
	}


	Matrix* matrix = dynamic_cast<Matrix*>(dataSource);
	if (matrix) {
		matrix->setSuppressDataChangedSignal(false);
		matrix->setChanged();
		matrix->setUndoAware(true);
	}

	return dataString.join("");
}
Example #13
0
//! Load from XML
bool DatapickerCurve::load(XmlStreamReader* reader) {
	Q_D(DatapickerCurve);

	if(!reader->isStartElement() || reader->name() != "datapickerCurve") {
		reader->raiseError(i18n("no dataPicker curve element found"));
		return false;
	}

	if (!readBasicAttributes(reader))
		return false;

	QString attributeWarning = i18n("Attribute '%1' missing or empty, default value is used");
	QXmlStreamAttributes attribs;
	QString str;

	while (!reader->atEnd()) {
		reader->readNext();
		if (reader->isEndElement() && reader->name() == "datapickerCurve")
			break;

		if (!reader->isStartElement())
			continue;

		if (reader->name() == "comment") {
			if (!readCommentElement(reader)) return false;
		} else if (reader->name() == "general") {
			attribs = reader->attributes();

			str = attribs.value("curveErrorType_X").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("curveErrorType_X"));
			else
				d->curveErrorTypes.x = ErrorType(str.toInt());

			str = attribs.value("curveErrorType_Y").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("curveErrorType_Y"));
			else
				d->curveErrorTypes.y = ErrorType(str.toInt());

			READ_COLUMN(posXColumn);
			READ_COLUMN(posYColumn);
			READ_COLUMN(posZColumn);
			READ_COLUMN(plusDeltaXColumn);
			READ_COLUMN(minusDeltaXColumn);
			READ_COLUMN(plusDeltaYColumn);
			READ_COLUMN(minusDeltaYColumn);

		} else if(reader->name() == "symbolProperties") {
			attribs = reader->attributes();

			str = attribs.value("pointRotationAngle").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointRotationAngle"));
			else
				d->pointRotationAngle = str.toFloat();

			str = attribs.value("pointOpacity").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointOpacity"));
			else
				d->pointOpacity = str.toFloat();

			str = attribs.value("pointSize").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointSize"));
			else
				d->pointSize = str.toFloat();

			str = attribs.value("pointStyle").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointStyle"));
			else
				d->pointStyle = (Symbol::Style)str.toInt();

			str = attribs.value("pointVisibility").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointVisibility"));
			else
				d->pointVisibility = (bool)str.toInt();

			READ_QBRUSH(d->pointBrush);
			READ_QPEN(d->pointPen);
		} else if(reader->name() == "errorBarProperties") {
			attribs = reader->attributes();

			str = attribs.value("pointErrorBarSize").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointErrorBarSize"));
			else
				d->pointErrorBarSize = str.toFloat();

			READ_QBRUSH(d->pointErrorBarBrush);
			READ_QPEN(d->pointErrorBarPen);
		} else if (reader->name() == "datapickerPoint") {
			DatapickerPoint* curvePoint = new DatapickerPoint("");
			curvePoint->setHidden(true);
			if (!curvePoint->load(reader)) {
				delete curvePoint;
				return false;
			} else {
				addChild(curvePoint);
				curvePoint->initErrorBar(curveErrorTypes());
			}
		} else if (reader->name() == "spreadsheet") {
			Spreadsheet* datasheet = new Spreadsheet(0, "spreadsheet", true);
			if (!datasheet->load(reader)) {
				delete datasheet;
				return false;
			} else {
				addChild(datasheet);
				m_datasheet = datasheet;
			}
		} else { // unknown element
			reader->raiseWarning(i18n("unknown element '%1'", reader->name().toString()));
			if (!reader->skipToEndElement()) return false;
		}
	}

	d->retransform();
	return true;
}
Example #14
0
//------------------------------------------------------------------------------
int main(int argc, char * const argv[])
{
  Options opt = GetOptions(argc, argv);

  // Log in
  SpreadsheetService service(opt.user, opt.password,
                             "xeckollc-thirteen-" + VERSION);

  // Get the spreadsheet we are interested in
  Spreadsheet spreadsheet;
  if(opt.spreadsheet_id.size()) {
    spreadsheet = service.GetSpreadsheet(opt.spreadsheet_id);
  } else {
    vector<Spreadsheet> sheets = service.GetSpreadsheets();
    int report_index = -1;
    for (int i=0; i < sheets.size(); ++i) {
      if(sheets[i].GetTitle() == opt.spreadsheet_name) {
        report_index = i;
        break;
      }
    }
    if(report_index < 0) {
      cerr << format("No spreadsheet named [%1%] found") %
           opt.spreadsheet_name << endl;
      return 1;
    }
    spreadsheet = sheets[report_index];
  }

  // Get the worksheet we are interested in. If we didn't specify one,
  // use the first one in the spreadsheet
  Worksheet worksheet;
  if(opt.worksheet_id.size()) {
    worksheet = spreadsheet.GetWorksheet(opt.worksheet_id);
  } else {
    vector<Worksheet> sheets = spreadsheet.GetWorksheets();
    if(opt.worksheet_name.size()) {
      int report_index = -1;
      for (int i=0; i < sheets.size(); ++i) {
        if(sheets[i].GetTitle() == opt.worksheet_name) {
          report_index = i;
          break;
        }
      }
      if(report_index < 0) {
        cerr << format("No worksheet named [%1%] found") %
             opt.worksheet_name << endl;
        return 1;
      }
      worksheet = sheets[report_index];
    } else {
      worksheet = sheets[0];
    }
  }

  // Get 2 columns of Cells from selected worksheet
  CellRange cells = worksheet.GetColumns(1, 2);

  // Parse the cells for the data
  map<string, int> on_air, off_air;
  State state = NONE;
  for (int row=cells.GetFirstRow(); row <= cells.GetLastRow(); ++row) {
    Cell *label_cell = cells.GetCell(row, 1);
    if(label_cell == NULL) {
      state = NONE;
      continue;
    }
    string label = label_cell->GetContent();
    if(!label.size()) {
      state = NONE;
      continue;
    }
    if(label == ON_AIR_HEADER) {
      state = ONAIR;
      continue;
    }
    if(label == OFF_AIR_HEADER) {
      state = OFFAIR;
      continue;
    }

    Cell *value_cell = cells.GetCell(row, 2);
    if(value_cell == NULL) {
      continue;
    }
    string value = value_cell->GetContent();
    int ivalue;
    try {
      ivalue = lexical_cast<int>(value.c_str());
    } catch(bad_lexical_cast &) {
      ivalue = 0;
    }
    switch (state) {
    case ONAIR:
      if(ivalue) {
        on_air[label] = ivalue;
      }
      break;

    case OFFAIR:
      if(ivalue) {
        off_air[label] = ivalue;
      }
      break;

    case NONE:
      break;
    }
  }

  // Figure the start and stop dates from the worksheet name
  string name = worksheet.GetTitle();
  re::sregex rex = re::sregex::compile("(.+) +(.+)");
  re::smatch matches;
  if(!re::regex_match(name, matches, rex)) {
    cerr << format("Worksheet name [%1%] does not look like a month and year") %
         name << endl;
    return 1;
  }

  string mon, yr;
  int month, year;
  mon = matches[1];
  yr  = matches[2];
  year = lexical_cast<int>(yr.c_str());
  if(year < 2000) {
    year += 2000;
  }
  month = 0;
  string months[] = {
    "jan", "feb", "mar", "apr", "may", "jun",
    "jul", "aug", "sep", "oct", "nov", "dec"
  };
  for (int i=0; i<12; ++i) {
    if (iequals(mon, months[i])) {
      month=i+1;
      break;
    }
  }
  if(month < 1) {
    cerr << format("Worksheet name [%1%] does not contain a valid month") %
         name << endl;
    return 1;
  }
  date start_date(year, month, 1);
  date stop_date = start_date.end_of_month();

  stringstream start, stop;
  date_facet *facet = new date_facet("%d %b");
  start.imbue(locale(cout.getloc(), facet));
  start << start_date;
  opt.start_date = to_upper_copy(start.str());

  facet = new date_facet("%d %b %Y");
  stop.imbue(locale(cout.getloc(), facet));
  stop << stop_date;
  opt.stop_date = to_upper_copy(stop.str());

  // Print the report
  PrintReport(cout, opt, on_air, off_air);
  return 0;
}
Example #15
0
/*!
  switches on/off  the comment header in the views of the selected spreadsheets.
*/
void SpreadsheetDock::commentsShownChanged(int state){
	Spreadsheet* spreadsheet;
	foreach(spreadsheet, m_spreadsheetList)
		qobject_cast<SpreadsheetView*>(spreadsheet->view())->showComments(state);
}
Example #16
0
/*!
    reads the content of the file \c fileName to the data source \c dataSource.
    Uses the settings defined in the data source.
*/
void ImageFilterPrivate::read(const QString & fileName, AbstractDataSource* dataSource, AbstractFileFilter::ImportMode mode) {
	QImage image = QImage(fileName);
	if (image.isNull() || image.format() == QImage::Format_Invalid) {
		qDebug()<<"failed to read image"<<fileName<<"or invalid image format";
		return;
	}

	int cols = image.width();
	int rows = image.height();

	// set range of rows
	if (endColumn == -1)
		endColumn = cols;
	if (endRow == -1)
		endRow = rows;
	int actualCols=0, actualRows=0;

	switch (importFormat) {
	case ImageFilter::MATRIX: {
		actualCols = endColumn-startColumn+1;
		actualRows = endRow-startRow+1;
		break;
	}
	case ImageFilter::XYZ: {
		actualCols = 3;
		actualRows = (endColumn-startColumn+1)*(endRow-startRow+1);
		break;
	}
	case ImageFilter::XYRGB: {
		actualCols = 5;
		actualRows = (endColumn-startColumn+1)*(endRow-startRow+1);
		break;
	}
	}

#ifdef QT_DEBUG
	qDebug()<<"image format ="<<image.format();
	qDebug()<<"image w/h ="<<cols<<rows;
	qDebug()<<"actual rows/cols ="<<actualRows<<actualCols;
#endif

	//make sure we have enough columns in the data source.
	int columnOffset = 0;
	QVector<QVector<double>*> dataPointers;
	if (dataSource != 0)
		columnOffset = dataSource->create(dataPointers, mode, actualRows, actualCols);
	else {
		qDebug()<<"data source in image import not defined! Giving up.";
		return;
	}

	// read data
	switch (importFormat) {
	case ImageFilter::MATRIX: {
		for (int i=0; i<actualRows; i++) {
			for ( int j=0; j<actualCols; j++ ) {
				double value=qGray(image.pixel(j+startColumn-1,i+startRow-1));
				dataPointers[j]->operator[](i) = value;
			}
			emit q->completed(100*i/actualRows);
		}
		break;
	}
	case ImageFilter::XYZ: {
		int currentRow=0;
		for (int i=startRow-1; i<endRow; i++) {
			for ( int j=startColumn-1; j<endColumn; j++ ) {
				QRgb color=image.pixel(j, i);
				dataPointers[0]->operator[](currentRow) = i+1;
				dataPointers[1]->operator[](currentRow) = j+1;
				dataPointers[2]->operator[](currentRow) = qGray(color);
				currentRow++;
			}
			emit q->completed(100*i/actualRows);
		}
		break;
	}
	case ImageFilter::XYRGB: {
		int currentRow=0;
		for (int i=startRow-1; i<endRow; i++) {
			for ( int j=startColumn-1; j<endColumn; j++ ) {
				QRgb color=image.pixel(j, i);
				dataPointers[0]->operator[](currentRow) = i+1;
				dataPointers[1]->operator[](currentRow) = j+1;
				dataPointers[2]->operator[](currentRow) = qRed(color);
				dataPointers[3]->operator[](currentRow) = qGreen(color);
				dataPointers[4]->operator[](currentRow) = qBlue(color);
				currentRow++;
			}
			emit q->completed(100*i/actualRows);
		}
		break;
	}
	}

	Spreadsheet* spreadsheet = dynamic_cast<Spreadsheet*>(dataSource);
	if (spreadsheet) {
		QString comment = i18np("numerical data, %1 element", "numerical data, %1 elements", rows);
		for ( int n=0; n<actualCols; n++ ) {
			Column* column = spreadsheet->column(columnOffset+n);
			column->setComment(comment);
			column->setUndoAware(true);
			if (mode==AbstractFileFilter::Replace) {
				column->setSuppressDataChangedSignal(false);
				column->setChanged();
			}
		}
		spreadsheet->setUndoAware(true);
		return;
	}

	Matrix* matrix = dynamic_cast<Matrix*>(dataSource);
	if (matrix) {
		matrix->setSuppressDataChangedSignal(false);
		matrix->setChanged();
		matrix->setUndoAware(true);
	}
}
Example #17
0
/*!
    reads the content of the file \c fileName to the data source \c dataSource or return as string for preview.
    Uses the settings defined in the data source.
*/
QString BinaryFilterPrivate::readData(const QString & fileName, AbstractDataSource* dataSource, AbstractFileFilter::ImportMode mode, int lines){
	QStringList dataString;

	QIODevice *device = KFilterDev::deviceForFile(fileName);
	if (! device->open(QIODevice::ReadOnly))
		return QString();

	QDataStream in(device);

	if (byteOrder == BinaryFilter::BigEndian)
		in.setByteOrder(QDataStream::BigEndian);
	else if (byteOrder == BinaryFilter::LittleEndian)
		in.setByteOrder(QDataStream::LittleEndian);

	int numRows=BinaryFilter::rowNumber(fileName,vectors,dataType);

	// catch case that skipStartBytes or startRow is bigger than file
	if(skipStartBytes >= BinaryFilter::dataSize(dataType)*vectors*numRows || startRow > numRows) {
		if(dataSource != NULL)
			dataSource->clear();
		return QString();
	}

	// skip bytes at start
	for (int i=0; i<skipStartBytes; i++){
		qint8 tmp;
		in >> tmp;
	}

	// skip until start row
	for (int i=0; i<(startRow-1)*vectors; ++i){
		for(int j=0;j<BinaryFilter::dataSize(dataType);++j) {
			qint8 tmp;
			in >> tmp;
		}
	}

	// set range of rows
	int actualRows;
	if (endRow == -1)
		actualRows = numRows-startRow+1;
	else if (endRow > numRows-startRow+1)
		actualRows = numRows;
	else
		actualRows = endRow-startRow+1;
	int actualCols=vectors;
	if (lines == -1)
		lines=actualRows;
#ifdef QT_DEBUG
	qDebug()<<"	numRows ="<<numRows;
	qDebug()<<"	startRow ="<<startRow;
	qDebug()<<"	endRow ="<<endRow;
	qDebug()<<"	actualRows ="<<actualRows;
	qDebug()<<"	actualCols ="<<actualCols;
	qDebug()<<"	lines ="<<lines;
#endif

	QVector<QVector<double>*> dataPointers;
	int columnOffset = 0;
	if(dataSource != NULL)
		columnOffset = dataSource->create(dataPointers, mode, actualRows, actualCols);

	// read data
	for (int i=0; i<qMin(actualRows,lines); i++){
		for ( int n=0; n<actualCols; n++ ){
			switch(dataType) {
			case BinaryFilter::INT8: {
				qint8 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::INT16: {
				qint16 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::INT32: {
				qint32 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::INT64: {
				qint64 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::UINT8: {
				quint8 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::UINT16: {
				quint16 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::UINT32: {
				quint32 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::UINT64: {
				quint64 value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::REAL32: {
				float value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			case BinaryFilter::REAL64: {
				double value;
				in >> value;
				if (dataSource != NULL)
					dataPointers[n]->operator[](i) = value;
				else
					dataString<<QString::number(value)<<" ";
				break;
			}
			}
		}
		dataString<<"\n";
		emit q->completed(100*i/actualRows);
	}

	if (!dataSource)
		return dataString.join("");

	//make everything undo/redo-able again
	//set the comments for each of the columns
	Spreadsheet* spreadsheet = dynamic_cast<Spreadsheet*>(dataSource);
	if (spreadsheet) {
		Spreadsheet* spreadsheet = dynamic_cast<Spreadsheet*>(dataSource);
		QString comment = i18np("numerical data, %1 element", "numerical data, %1 elements", actualRows);
		for ( int n=0; n<actualCols; n++ ){
			Column* column = spreadsheet->column(columnOffset+n);
			column->setComment(comment);
			column->setUndoAware(true);
			if (mode==AbstractFileFilter::Replace) {
				column->setSuppressDataChangedSignal(false);
				column->setChanged();
			}
		}
		spreadsheet->setUndoAware(true);
		return dataString.join("");
	}

	Matrix* matrix = dynamic_cast<Matrix*>(dataSource);
	if (matrix) {
		matrix->setSuppressDataChangedSignal(false);
		matrix->setChanged();
		matrix->setUndoAware(true);
	}

	return dataString.join("");
}