Пример #1
0
void CmdSpreadsheetSetAlias::activated(int iMsg)
{
    if (getActiveGuiDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            QModelIndexList selection = sheetView->selectedIndexes();

            if (selection.size() == 1) {
                std::vector<Range> range;

                range.push_back(Range(selection[0].row(), selection[0].column(),
                                      selection[0].row(), selection[0].column()));

                std::auto_ptr<PropertiesDialog> dialog(new PropertiesDialog(sheet, range, sheetView));

                dialog->selectAlias();

                if (dialog->exec() == QDialog::Accepted)
                    dialog->apply();
            }
        }
    }
}
Пример #2
0
bool ViewProviderSheet::onDelete(const std::vector<std::string> &)
{
    // If view is closed, delete the object
    if (view.isNull())
        return true;

    // View is not closed, delete cell contents instead if it is active
    if (Gui::Application::Instance->activeDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            QModelIndexList selection = sheetView->selectedIndexes();

            if (selection.size() > 0) {
                Gui::Command::openCommand("Clear cell(s)");
                std::vector<Range> ranges = sheetView->selectedRanges();
                std::vector<Range>::const_iterator i = ranges.begin();

                for (; i != ranges.end(); ++i) {
                    Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.clear('%s')", sheet->getNameInDocument(),
                                            i->rangeString().c_str());
                }
                Gui::Command::commitCommand();
                Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
            }
        }
    }

    return false;
}
Пример #3
0
void WorkbenchHelper::setBackgroundColor(const QColor & color)
{
    Gui::Document * doc = Gui::Application::Instance->activeDocument();

    if (doc) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            std::vector<Range> ranges = sheetView->selectedRanges();

            // Execute mergeCells commands
            if (ranges.size() > 0) {
                std::vector<Range>::const_iterator i = ranges.begin();

                Gui::Command::openCommand("Set background color");
                for (; i != ranges.end(); ++i)
                        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setBackground('%s', (%f,%f,%f))", sheet->getNameInDocument(),
                                                i->rangeString().c_str(), color.redF(), color.greenF(), color.blueF());
                Gui::Command::commitCommand();
                Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
            }
        }
    }
}
Пример #4
0
void CmdSpreadsheetMergeCells::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    if (getActiveGuiDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            std::vector<Range> ranges = sheetView->selectedRanges();

            // Execute mergeCells commands
            if (ranges.size() > 0) {
                Gui::Command::openCommand("Merge cells");
                std::vector<Range>::const_iterator i = ranges.begin();
                for (; i != ranges.end(); ++i)
                    if (i->size() > 1)
                        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.mergeCells('%s')", sheet->getNameInDocument(),
                                                i->rangeString().c_str());
                Gui::Command::commitCommand();
                Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
            }
        }
    }
}
Пример #5
0
bool CmdSpreadsheetSplitCell::isActive()
{
    if (getActiveGuiDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            QModelIndex current = sheetView->currentIndex();
            Sheet * sheet = sheetView->getSheet();

            if (current.isValid())
                return sheet->isMergedCell(CellAddress(current.row(), current.column()));
        }
    }
    return false;
}
Пример #6
0
void CmdSpreadsheetStyleUnderline::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    if (getActiveGuiDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            QModelIndexList selection = sheetView->selectedIndexes();

            if (selection.size() > 0) {
                bool allUnderline = true;

                for (QModelIndexList::const_iterator it = selection.begin(); it != selection.end(); ++it) {
                    const Cell * cell = sheet->getCell(CellAddress((*it).row(), (*it).column()));

                    if (cell) {
                        std::set<std::string> style;

                        cell->getStyle(style);
                        if (style.find("underline") == style.end()) {
                            allUnderline = false;
                            break;
                        }
                    }
                }

                std::vector<Range> ranges = sheetView->selectedRanges();
                std::vector<Range>::const_iterator i = ranges.begin();

                Gui::Command::openCommand("Set underline text");
                for (; i != ranges.end(); ++i) {
                    if (!allUnderline)
                        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setStyle('%s', 'underline', 'add')", sheet->getNameInDocument(),
                                                i->rangeString().c_str());
                    else
                        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setStyle('%s', 'underline', 'remove')", sheet->getNameInDocument(),
                                                i->rangeString().c_str());
                }
                Gui::Command::commitCommand();
                Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
            }
        }
    }
}
Пример #7
0
void CmdSpreadsheetExport::activated(int iMsg)
{
    if (getActiveGuiDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            QString selectedFilter;
            QString formatList = QObject::tr("All (*)");
            QString fileName = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(),
                                                                QObject::tr("Export file"),
                                                                QString(),
                                                                formatList,
                                                                &selectedFilter);
            if (!fileName.isEmpty())
                sheet->exportToFile(Base::Tools::toStdString(fileName), '\t', '"', '\\');
        }
    }
}
Пример #8
0
void CmdSpreadsheetSplitCell::activated(int iMsg)
{
    if (getActiveGuiDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            QModelIndex current = sheetView->currentIndex();

            if (current.isValid()) {
                std::string address = CellAddress(current.row(), current.column()).toString();
                Gui::Command::openCommand("Split cell");
                Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.splitCell('%s')", sheet->getNameInDocument(),
                                        address.c_str());
                Gui::Command::commitCommand();
                Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
            }
        }
    }
}
Пример #9
0
void CmdSpreadsheetAlignVCenter::activated(int iMsg)
{
    if (getActiveGuiDocument()) {
        Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
        SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);

        if (sheetView) {
            Sheet * sheet = sheetView->getSheet();
            std::vector<Range> ranges = sheetView->selectedRanges();

            if (ranges.size() > 0) {
                std::vector<Range>::const_iterator i = ranges.begin();

                Gui::Command::openCommand("Vertically center cells");
                for (; i != ranges.end(); ++i)
                    Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setAlignment('%s', 'vcenter', 'keep')", sheet->getNameInDocument(),
                                            i->rangeString().c_str());
                Gui::Command::commitCommand();
                Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
            }
        }
    }
}