void BindingManager::regionChanged(const Region& region)
{
    Sheet* sheet;
    QList< QPair<QRectF, Binding> > bindings;
    Region::ConstIterator end(region.constEnd());
    for (Region::ConstIterator it = region.constBegin(); it != end; ++it) {
        sheet = (*it)->sheet();
        const Region changedRegion((*it)->rect(), sheet);
        bindings = sheet->cellStorage()->bindingStorage()->intersectingPairs(changedRegion);
        for (int j = 0; j < bindings.count(); ++j)
            bindings[j].second.update(changedRegion);
    }
}
示例#2
0
void TestInformationFunctions::initTestCase()
{
    FunctionModuleRegistry::instance()->loadFunctionModules();
    m_map = new Map(0 /* no Doc */);
    m_map->addNewSheet();
    Sheet* sheet = m_map->sheet(0);
    sheet->setSheetName("Sheet1");
    CellStorage* storage = sheet->cellStorage();

    //
    // Test case data set
    //


     // A19:A31
     storage->setValue(1,19, Value(    1 ) );
     storage->setValue(1,20, Value(    2 ) );
     storage->setValue(1,21, Value(    4 ) );
     storage->setValue(1,22, Value(    8 ) );
     storage->setValue(1,23, Value(   16 ) );
     storage->setValue(1,24, Value(   32 ) );
     storage->setValue(1,25, Value(   64 ) );
     storage->setValue(1,26, Value(  128 ) );
     storage->setValue(1,27, Value(  256 ) );
     storage->setValue(1,28, Value(  512 ) );
     storage->setValue(1,29, Value( 1024 ) );
     storage->setValue(1,30, Value( 2048 ) );
     storage->setValue(1,31, Value( 4096 ) );

     // B1:B2
     Formula formula(sheet);
     formula.setExpression("=SUM(A19:A31)");
     storage->setFormula(2,1, formula);
     storage->setFormula(2,2, Formula::empty());

     // B3:B17
    storage->setValue(2, 3, Value("7"));
    storage->setValue(2, 4, Value(2));
    storage->setValue(2, 5, Value(3));
    storage->setValue(2, 6, Value(true));
    storage->setValue(2, 7, Value("Hello"));
     // B8 leave empty
    storage->setValue(2, 9, Value::errorDIV0());
    storage->setValue(2, 10, Value(0));
//     storage->setValue(2,11, Value(      3    ) );
//     storage->setValue(2,12, Value(      4    ) );
//     storage->setValue(2,13, Value( "2005-0131T01:00:00" ));
//     storage->setValue(2,14, Value(      1    ) );
//     storage->setValue(2,15, Value(      2    ) );
//     storage->setValue(2,16, Value(      3    ) );
//     storage->setValue(2,17, Value(      4    ) );
//
//
//     // C4:C7
    storage->setValue(3, 4, Value(4));
    storage->setValue(3, 5, Value(5));
//     storage->setValue(3, 6, Value( 7 ) );
    storage->setValue(3, 7, Value("2005-01-31"));

     // C11:C17
     storage->setValue(3,11, Value( 5 ) );
     storage->setValue(3,12, Value( 6 ) );
     storage->setValue(3,13, Value( 8 ) );
     storage->setValue(3,14, Value( 4 ) );
     storage->setValue(3,15, Value( 3 ) );
     storage->setValue(3,16, Value( 2 ) );
     storage->setValue(3,17, Value( 1 ) );

//     // C19:C31
//     storage->setValue(3,19, Value( 0 ) );
//     storage->setValue(3,20, Value( 5 ) );
//     storage->setValue(3,21, Value( 2 ) );
//     storage->setValue(3,22, Value( 5 ) );
//     storage->setValue(3,23, Value( 3 ) );
//     storage->setValue(3,24, Value( 4 ) );
//     storage->setValue(3,25, Value( 4 ) );
//     storage->setValue(3,26, Value( 0 ) );
//     storage->setValue(3,27, Value( 8 ) );
//     storage->setValue(3,28, Value( 1 ) );
//     storage->setValue(3,29, Value( 9 ) );
//     storage->setValue(3,30, Value( 6 ) );
//     storage->setValue(3,31, Value( 2 ) );
//     // C51:C57
//     storage->setValue(3,51, Value(  7 ) );
//     storage->setValue(3,52, Value(  9 ) );
//     storage->setValue(3,53, Value( 11 ) );
//     storage->setValue(3,54, Value( 12 ) );
//     storage->setValue(3,55, Value( 15 ) );
//     storage->setValue(3,56, Value( 17 ) );
//     storage->setValue(3,57, Value( 19 ) );
//
//     // D51:D57
//     storage->setValue(4,51, Value( 100 ) );
//     storage->setValue(4,52, Value( 105 ) );
//     storage->setValue(4,53, Value( 104 ) );
//     storage->setValue(4,54, Value( 108 ) );
//     storage->setValue(4,55, Value( 111 ) );
//     storage->setValue(4,56, Value( 120 ) );
//     storage->setValue(4,57, Value( 133 ) );
//
//
//     // F51:F60
//     storage->setValue(6,51, Value( 3 ) );
//     storage->setValue(6,52, Value( 4 ) );
//     storage->setValue(6,53, Value( 5 ) );
//     storage->setValue(6,54, Value( 2 ) );
//     storage->setValue(6,55, Value( 3 ) );
//     storage->setValue(6,56, Value( 4 ) );
//     storage->setValue(6,57, Value( 5 ) );
//     storage->setValue(6,58, Value( 6 ) );
//     storage->setValue(6,59, Value( 4 ) );
//     storage->setValue(6,60, Value( 7 ) );
//
//
//     // G51:G60
//     storage->setValue(7,51, Value( 23 ) );
//     storage->setValue(7,52, Value( 24 ) );
//     storage->setValue(7,53, Value( 25 ) );
//     storage->setValue(7,54, Value( 22 ) );
//     storage->setValue(7,55, Value( 23 ) );
//     storage->setValue(7,56, Value( 24 ) );
//     storage->setValue(7,57, Value( 25 ) );
//     storage->setValue(7,58, Value( 26 ) );
//     storage->setValue(7,59, Value( 24 ) );
//     storage->setValue(7,60, Value( 27 ) );

    // A1000:G1000
    storage->setValue(1, 1000, Value("abc"));
    storage->setValue(2, 1000, Value("def"));
    storage->setValue(3, 1000, Value("efoob"));
    storage->setValue(4, 1000, Value("flka"));
    storage->setValue(5, 1000, Value("kde"));
    storage->setValue(6, 1000, Value("kde"));
    storage->setValue(7, 1000, Value("xxx"));

     // Z19:Z23
     storage->setValue(26,19, Value(   16 ) );
     storage->setValue(26,20, Value(    8 ) );
     storage->setValue(26,21, Value(    4 ) );
     storage->setValue(26,22, Value(    2 ) );
     storage->setValue(26,23, Value(    1 ) );

    // Add the second sheet
    m_map->addNewSheet();
    sheet = m_map->sheet(1);
    sheet->setSheetName("Sheet2");
    storage = sheet->cellStorage();

    // B1:B2
     Formula formula2(sheet);
     formula2.setExpression("=SUM(Sheet1!A19:Sheet1!A31)");
     storage->setFormula(2,1, formula2);
     storage->setFormula(2,2, Formula::empty());

    // Add the third sheet
    m_map->addNewSheet();
    sheet = m_map->sheet(2);
    sheet->setSheetName("Sheet3");
    storage = sheet->cellStorage();

    // A1:A2
     storage->setValue(1,1, Value( 1.1 ) );
     storage->setValue(1,2, Value( 2.2 ) );
}
示例#3
0
void CellTest::testRichText()
{
    KoOdfStylesReader stylesReader;

    QBuffer buffer;
    buffer.open(QIODevice::ReadOnly);
    KoStore *store = KoStore::createStore(&buffer, KoStore::Read);

    KoOdfLoadingContext odfContext(stylesReader, store);
    OdfLoadingContext context(odfContext);

    KoDocumentResourceManager documentResources;
    KoShapeLoadingContext shapeContext(odfContext, &documentResources);
    context.shapeContext = &shapeContext;

    Styles autoStyles;
    QString cellStyleName;

    Map map;
    Sheet* sheet = map.addNewSheet();
    CellStorage* storage = sheet->cellStorage();
    storage->setValue(1, 1, Value(1));

    Cell cell = storage->firstInRow(1);
    QVERIFY(!cell.isNull());

    { // Test the simple case. Only one paragraph with some simple text.
        KoXmlDocument doc = xmlDocument("<text:p>Some text</text:p>");
        KoXmlElement e = doc.documentElement();
        QVERIFY(!e.isNull());
        cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
        QVERIFY(!cell.isNull());
        QVERIFY(!cell.richText());
        QVERIFY(cell.userInput().split('\n').count() == 1);
    }

    { // Text in the paragraph and in a child text:span means rich-text.
        KoXmlDocument doc = xmlDocument("<text:p>First<text:span>Second<text:span>Theird</text:span></text:span></text:p>");
        KoXmlElement e = doc.documentElement();
        QVERIFY(!e.isNull());
        cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
        QVERIFY(!cell.isNull());
        QVERIFY(cell.richText());
        QVERIFY(cell.userInput().split('\n').count() == 1);
    }

    { // The text:line-break should be translated into a \n newline and since there is no other rich-text it should not be detected as such.
        KoXmlDocument doc = xmlDocument("<text:p>First<text:line-break/>Second</text:p>");
        KoXmlElement e = doc.documentElement();
        QVERIFY(!e.isNull());
        cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
        QVERIFY(!cell.isNull());
        QVERIFY(!cell.richText());
        QVERIFY(cell.userInput().split('\n').count() == 2);
    }

    { // The text:s and text:tab should be translated into space and tabulator. No rich-text else.
        KoXmlDocument doc = xmlDocument("<text:p>First<text:s/>Second<text:tab/>Theird</text:p>");
        KoXmlElement e = doc.documentElement();
        QVERIFY(!e.isNull());
        cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
        QVERIFY(!cell.isNull());
        QVERIFY(!cell.richText());
        QVERIFY(cell.userInput().split('\n').count() == 1);
    }
}
bool AdjustColumnRowManipulator::process(Element* element)
{
    Sheet* sheet = m_sheet; // TODO Stefan: element->sheet();
    if (m_sheet && sheet != m_sheet) {
        return true;
    }

    QMap<int, double> heights;
    QMap<int, double> widths;
    if (m_reverse) {
        heights = m_oldHeights;
        widths = m_oldWidths;
    } else {
        heights = m_newHeights;
        widths = m_newWidths;
    }

    QRect range = element->rect();
    if (m_adjustColumn) {
        if (element->isRow()) {
            for (int row = range.top(); row <= range.bottom(); ++row) {
                Cell cell = sheet->cellStorage()->firstInRow(row);
                while (!cell.isNull()) {
                    int col = cell.column();
                    if (!cell.isEmpty() && !cell.isPartOfMerged()) {
                        if (widths.contains(col) && widths[col] != -1.0) {
                            ColumnFormat* format = sheet->nonDefaultColumnFormat(col);
                            if (qAbs(format->width() - widths[col]) > DBL_EPSILON) {
                                format->setWidth(qMax(2.0, widths[col]));
                            }
                        }
                    }
                    cell = sheet->cellStorage()->nextInRow(col, row);
                }
            }
        } else {
            for (int col = range.left(); col <= range.right(); ++col) {
                if (widths.contains(col) && widths[col] != -1.0) {
                    ColumnFormat* format = sheet->nonDefaultColumnFormat(col);
                    if (qAbs(format->width() - widths[col]) > DBL_EPSILON) {
                        format->setWidth(qMax(2.0, widths[col]));
                    }
                }
            }
        }
    }
    if (m_adjustRow) {
        if (element->isColumn()) {
            for (int col = range.left(); col <= range.right(); ++col) {
                Cell cell = sheet->cellStorage()->firstInColumn(col);
                while (!cell.isNull()) {
                    int row = cell.row();
                    if (!cell.isEmpty() && !cell.isPartOfMerged()) {
                        if (heights.contains(row) && heights[row] != -1.0) {
                            sheet->rowFormats()->setRowHeight(row, row, heights[row]);
                        }
                    }
                    cell = sheet->cellStorage()->nextInColumn(col, row);
                }
            }
        } else {
            for (int row = range.top(); row <= range.bottom(); ++row) {
                if (heights.contains(row) && heights[row] != -1.0) {
                    sheet->rowFormats()->setRowHeight(row, row, heights[row]);
                }
            }
        }
    }
    // The cell width(s) or height(s) changed, which are cached: rebuild them.
    const Region region(m_adjustRow ? 1 : range.left(),
                        m_adjustColumn ? 1 : range.top(),
                        m_adjustRow ? KS_colMax : range.width(),
                        m_adjustColumn ? KS_rowMax : range.height());
    m_sheet->map()->addDamage(new CellDamage(m_sheet, region, CellDamage::Appearance));
    return true;
}