Sheet: Apply clang format

This commit is contained in:
wmayer
2023-09-10 14:24:00 +02:00
committed by wwmayer
parent 50bb81e6fc
commit b5d363baf1
30 changed files with 1947 additions and 1403 deletions

View File

@@ -30,18 +30,18 @@
#include <Base/FileInfo.h>
#include <Base/Interpreter.h>
#include <Gui/Application.h>
#include <Gui/Language/Translator.h>
#include <Gui/MainWindow.h>
#include <Gui/WidgetFactory.h>
#include <Gui/Language/Translator.h>
#include <Mod/Spreadsheet/App/Sheet.h>
#include "DlgSettingsImp.h"
#include "SpreadsheetView.h"
#include "SheetTableViewAccessibleInterface.h"
#include "SpreadsheetView.h"
#include "ViewProviderSpreadsheet.h"
#include "Workbench.h"
// use a different name to CreateCommand()
// use a different name to CreateCommand()
void CreateSpreadsheetCommands();
void loadSpreadsheetResource()
@@ -52,49 +52,53 @@ void loadSpreadsheetResource()
Gui::Translator::instance()->refresh();
}
namespace SpreadsheetGui {
class Module : public Py::ExtensionModule<Module>
namespace SpreadsheetGui
{
class Module: public Py::ExtensionModule<Module>
{
public:
Module()
: Py::ExtensionModule<Module>("SpreadsheetGui")
{
public:
Module() : Py::ExtensionModule<Module>("SpreadsheetGui")
{
add_varargs_method("open",&Module::open
);
initialize("This module is the SpreadsheetGui module."); // register with Python
}
private:
Py::Object open(const Py::Tuple& args)
{
char* Name;
const char* DocName=nullptr;
if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName))
throw Py::Exception();
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
try {
Base::FileInfo file(EncodedName);
App::Document *pcDoc = App::GetApplication().newDocument(DocName ? DocName : QT_TR_NOOP("Unnamed"));
Spreadsheet::Sheet *pcSheet = static_cast<Spreadsheet::Sheet *>(pcDoc->addObject("Spreadsheet::Sheet", file.fileNamePure().c_str()));
pcSheet->importFromFile(EncodedName, '\t', '"', '\\');
pcSheet->execute();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
return Py::None();
}
};
PyObject* initModule()
{
return Base::Interpreter().addModule(new Module);
add_varargs_method("open", &Module::open);
initialize("This module is the SpreadsheetGui module.");// register with Python
}
} // namespace SpreadsheetGui
private:
Py::Object open(const Py::Tuple& args)
{
char* Name;
const char* DocName = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &DocName)) {
throw Py::Exception();
}
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
try {
Base::FileInfo file(EncodedName);
App::Document* pcDoc =
App::GetApplication().newDocument(DocName ? DocName : QT_TR_NOOP("Unnamed"));
Spreadsheet::Sheet* pcSheet = static_cast<Spreadsheet::Sheet*>(
pcDoc->addObject("Spreadsheet::Sheet", file.fileNamePure().c_str()));
pcSheet->importFromFile(EncodedName, '\t', '"', '\\');
pcSheet->execute();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
return Py::None();
}
};
PyObject* initModule()
{
return Base::Interpreter().addModule(new Module);
}
}// namespace SpreadsheetGui
/* Python entry */
PyMOD_INIT_FUNC(SpreadsheetGui)
@@ -116,7 +120,8 @@ PyMOD_INIT_FUNC(SpreadsheetGui)
SpreadsheetGui::SheetViewPy::init_type();
// register preference page
new Gui::PrefPageProducer<SpreadsheetGui::DlgSettingsImp> (QT_TRANSLATE_NOOP("QObject","Spreadsheet"));
new Gui::PrefPageProducer<SpreadsheetGui::DlgSettingsImp>(
QT_TRANSLATE_NOOP("QObject", "Spreadsheet"));
// add resources and reloads the translators
loadSpreadsheetResource();

View File

@@ -22,11 +22,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
#include <sstream>
#endif
#if defined(FC_OS_WIN32)
# include <sys/timeb.h>
#include <sys/timeb.h>
#endif
#include <App/Document.h>
@@ -53,15 +53,15 @@ using namespace App;
DEF_STD_CMD_A(CmdSpreadsheetMergeCells)
CmdSpreadsheetMergeCells::CmdSpreadsheetMergeCells()
: Command("Spreadsheet_MergeCells")
: Command("Spreadsheet_MergeCells")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Merge cells");
sToolTipText = QT_TR_NOOP("Merge selected cells");
sWhatsThis = "Spreadsheet_MergeCells";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetMergeCells";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Merge cells");
sToolTipText = QT_TR_NOOP("Merge selected cells");
sWhatsThis = "Spreadsheet_MergeCells";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetMergeCells";
}
void CmdSpreadsheetMergeCells::activated(int iMsg)
@@ -69,20 +69,25 @@ 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);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
// Execute mergeCells commands
if (!ranges.empty()) {
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "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(),
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()");
}
@@ -94,7 +99,8 @@ bool CmdSpreadsheetMergeCells::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
return (sheetView->selectedIndexesRaw().size() > 1);
@@ -108,15 +114,15 @@ bool CmdSpreadsheetMergeCells::isActive()
DEF_STD_CMD_A(CmdSpreadsheetSplitCell)
CmdSpreadsheetSplitCell::CmdSpreadsheetSplitCell()
: Command("Spreadsheet_SplitCell")
: Command("Spreadsheet_SplitCell")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Split cell");
sToolTipText = QT_TR_NOOP("Split previously merged cells");
sWhatsThis = "Spreadsheet_SplitCell";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetSplitCell";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Split cell");
sToolTipText = QT_TR_NOOP("Split previously merged cells");
sWhatsThis = "Spreadsheet_SplitCell";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetSplitCell";
}
void CmdSpreadsheetSplitCell::activated(int iMsg)
@@ -124,16 +130,19 @@ void CmdSpreadsheetSplitCell::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
QModelIndex current = sheetView->currentIndex();
if (current.isValid()) {
std::string address = CellAddress(current.row(), current.column()).toString();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Split cell"));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.splitCell('%s')", sheet->getNameInDocument(),
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()");
@@ -146,16 +155,16 @@ bool CmdSpreadsheetSplitCell::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
QModelIndex current = sheetView->currentIndex();
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
if (current.isValid())
{
return (sheetView->selectedIndexesRaw().size() == 1 &&
sheet->isMergedCell(CellAddress(current.row(), current.column())));
if (current.isValid()) {
return (sheetView->selectedIndexesRaw().size() == 1
&& sheet->isMergedCell(CellAddress(current.row(), current.column())));
}
}
}
@@ -167,15 +176,15 @@ bool CmdSpreadsheetSplitCell::isActive()
DEF_STD_CMD_A(CmdSpreadsheetImport)
CmdSpreadsheetImport::CmdSpreadsheetImport()
: Command("Spreadsheet_Import")
: Command("Spreadsheet_Import")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Import spreadsheet");
sToolTipText = QT_TR_NOOP("Import CSV file into spreadsheet");
sWhatsThis = "Spreadsheet_Import";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetImport";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Import spreadsheet");
sToolTipText = QT_TR_NOOP("Import CSV file into spreadsheet");
sWhatsThis = "Spreadsheet_Import";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetImport";
}
void CmdSpreadsheetImport::activated(int iMsg)
@@ -190,16 +199,19 @@ void CmdSpreadsheetImport::activated(int iMsg)
&selectedFilter);
if (!fileName.isEmpty()) {
std::string FeatName = getUniqueObjectName("Spreadsheet");
Sheet * sheet = freecad_dynamic_cast<Sheet>(App::GetApplication().getActiveDocument()->addObject("Spreadsheet::Sheet", FeatName.c_str()));
if (sheet){
Sheet* sheet = freecad_dynamic_cast<Sheet>(
App::GetApplication().getActiveDocument()->addObject("Spreadsheet::Sheet",
FeatName.c_str()));
if (sheet) {
char delim, quote, escape;
std::string errMsg = "Import";
bool isValid = sheet->getCharsFromPrefs(delim, quote, escape, errMsg);
if (isValid){
if (isValid) {
sheet->importFromFile(fileName.toStdString(), delim, quote, escape);
sheet->execute();
} else {
}
else {
Base::Console().Error(errMsg.c_str());
return;
}
@@ -217,15 +229,15 @@ bool CmdSpreadsheetImport::isActive()
DEF_STD_CMD_A(CmdSpreadsheetExport)
CmdSpreadsheetExport::CmdSpreadsheetExport()
: Command("Spreadsheet_Export")
: Command("Spreadsheet_Export")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Export spreadsheet");
sToolTipText = QT_TR_NOOP("Export spreadsheet to CSV file");
sWhatsThis = "Spreadsheet_Export";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetExport";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Export spreadsheet");
sToolTipText = QT_TR_NOOP("Export spreadsheet to CSV file");
sWhatsThis = "Spreadsheet_Export";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetExport";
}
void CmdSpreadsheetExport::activated(int iMsg)
@@ -233,10 +245,11 @@ void CmdSpreadsheetExport::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
QString selectedFilter;
QString formatList = QObject::tr("All (*)");
QString fileName = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(),
@@ -244,15 +257,16 @@ void CmdSpreadsheetExport::activated(int iMsg)
QString(),
formatList,
&selectedFilter);
if (!fileName.isEmpty()){
if (sheet){
if (!fileName.isEmpty()) {
if (sheet) {
char delim, quote, escape;
std::string errMsg = "Export";
bool isValid = sheet->getCharsFromPrefs(delim, quote, escape, errMsg);
if (isValid){
if (isValid) {
sheet->exportToFile(fileName.toStdString(), delim, quote, escape);
} else {
}
else {
Base::Console().Error(errMsg.c_str());
return;
}
@@ -266,9 +280,9 @@ bool CmdSpreadsheetExport::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -278,15 +292,15 @@ bool CmdSpreadsheetExport::isActive()
DEF_STD_CMD_A(CmdSpreadsheetAlignLeft)
CmdSpreadsheetAlignLeft::CmdSpreadsheetAlignLeft()
: Command("Spreadsheet_AlignLeft")
: Command("Spreadsheet_AlignLeft")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align left");
sToolTipText = QT_TR_NOOP("Left-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignLeft";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignLeft";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align left");
sToolTipText = QT_TR_NOOP("Left-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignLeft";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignLeft";
}
void CmdSpreadsheetAlignLeft::activated(int iMsg)
@@ -294,19 +308,24 @@ void CmdSpreadsheetAlignLeft::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Left-align cell"));
for (; i != ranges.end(); ++i)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setAlignment('%s', 'left', 'keep')", sheet->getNameInDocument(),
i->rangeString().c_str());
for (; i != ranges.end(); ++i) {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setAlignment('%s', 'left', 'keep')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
@@ -318,9 +337,9 @@ bool CmdSpreadsheetAlignLeft::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -330,15 +349,15 @@ bool CmdSpreadsheetAlignLeft::isActive()
DEF_STD_CMD_A(CmdSpreadsheetAlignCenter)
CmdSpreadsheetAlignCenter::CmdSpreadsheetAlignCenter()
: Command("Spreadsheet_AlignCenter")
: Command("Spreadsheet_AlignCenter")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align center");
sToolTipText = QT_TR_NOOP("Center-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignCenter";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignCenter";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align center");
sToolTipText = QT_TR_NOOP("Center-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignCenter";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignCenter";
}
void CmdSpreadsheetAlignCenter::activated(int iMsg)
@@ -346,19 +365,24 @@ void CmdSpreadsheetAlignCenter::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Center cell"));
for (; i != ranges.end(); ++i)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setAlignment('%s', 'center', 'keep')", sheet->getNameInDocument(),
i->rangeString().c_str());
for (; i != ranges.end(); ++i) {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setAlignment('%s', 'center', 'keep')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
@@ -370,9 +394,9 @@ bool CmdSpreadsheetAlignCenter::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -382,15 +406,15 @@ bool CmdSpreadsheetAlignCenter::isActive()
DEF_STD_CMD_A(CmdSpreadsheetAlignRight)
CmdSpreadsheetAlignRight::CmdSpreadsheetAlignRight()
: Command("Spreadsheet_AlignRight")
: Command("Spreadsheet_AlignRight")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align right");
sToolTipText = QT_TR_NOOP("Right-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignRight";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignRight";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align right");
sToolTipText = QT_TR_NOOP("Right-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignRight";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignRight";
}
void CmdSpreadsheetAlignRight::activated(int iMsg)
@@ -398,19 +422,24 @@ void CmdSpreadsheetAlignRight::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Right-align cell"));
for (; i != ranges.end(); ++i)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setAlignment('%s', 'right', 'keep')", sheet->getNameInDocument(),
i->rangeString().c_str());
for (; i != ranges.end(); ++i) {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setAlignment('%s', 'right', 'keep')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
@@ -422,9 +451,9 @@ bool CmdSpreadsheetAlignRight::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -434,15 +463,15 @@ bool CmdSpreadsheetAlignRight::isActive()
DEF_STD_CMD_A(CmdSpreadsheetAlignTop)
CmdSpreadsheetAlignTop::CmdSpreadsheetAlignTop()
: Command("Spreadsheet_AlignTop")
: Command("Spreadsheet_AlignTop")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align top");
sToolTipText = QT_TR_NOOP("Top-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignTop";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignTop";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align top");
sToolTipText = QT_TR_NOOP("Top-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignTop";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignTop";
}
void CmdSpreadsheetAlignTop::activated(int iMsg)
@@ -450,19 +479,24 @@ void CmdSpreadsheetAlignTop::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Top-align cell"));
for (; i != ranges.end(); ++i)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setAlignment('%s', 'top', 'keep')", sheet->getNameInDocument(),
i->rangeString().c_str());
for (; i != ranges.end(); ++i) {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setAlignment('%s', 'top', 'keep')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
@@ -474,9 +508,9 @@ bool CmdSpreadsheetAlignTop::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -486,15 +520,15 @@ bool CmdSpreadsheetAlignTop::isActive()
DEF_STD_CMD_A(CmdSpreadsheetAlignBottom)
CmdSpreadsheetAlignBottom::CmdSpreadsheetAlignBottom()
: Command("Spreadsheet_AlignBottom")
: Command("Spreadsheet_AlignBottom")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align bottom");
sToolTipText = QT_TR_NOOP("Bottom-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignBottom";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignBottom";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Align bottom");
sToolTipText = QT_TR_NOOP("Bottom-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignBottom";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignBottom";
}
void CmdSpreadsheetAlignBottom::activated(int iMsg)
@@ -502,19 +536,24 @@ void CmdSpreadsheetAlignBottom::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Bottom-align cell"));
for (; i != ranges.end(); ++i)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setAlignment('%s', 'bottom', 'keep')", sheet->getNameInDocument(),
i->rangeString().c_str());
for (; i != ranges.end(); ++i) {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setAlignment('%s', 'bottom', 'keep')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
@@ -526,9 +565,9 @@ bool CmdSpreadsheetAlignBottom::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -538,15 +577,15 @@ bool CmdSpreadsheetAlignBottom::isActive()
DEF_STD_CMD_A(CmdSpreadsheetAlignVCenter)
CmdSpreadsheetAlignVCenter::CmdSpreadsheetAlignVCenter()
: Command("Spreadsheet_AlignVCenter")
: Command("Spreadsheet_AlignVCenter")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Vertically center-align");
sToolTipText = QT_TR_NOOP("Vertically center-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignVCenter";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignVCenter";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Vertically center-align");
sToolTipText = QT_TR_NOOP("Vertically center-align contents of selected cells");
sWhatsThis = "Spreadsheet_AlignVCenter";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetAlignVCenter";
}
void CmdSpreadsheetAlignVCenter::activated(int iMsg)
@@ -554,19 +593,24 @@ void CmdSpreadsheetAlignVCenter::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "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());
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()");
}
@@ -578,9 +622,9 @@ bool CmdSpreadsheetAlignVCenter::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -590,15 +634,15 @@ bool CmdSpreadsheetAlignVCenter::isActive()
DEF_STD_CMD_A(CmdSpreadsheetStyleBold)
CmdSpreadsheetStyleBold::CmdSpreadsheetStyleBold()
: Command("Spreadsheet_StyleBold")
: Command("Spreadsheet_StyleBold")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Bold text");
sToolTipText = QT_TR_NOOP("Set text in selected cells bold");
sWhatsThis = "Spreadsheet_StyleBold";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetStyleBold";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Bold text");
sToolTipText = QT_TR_NOOP("Set text in selected cells bold");
sWhatsThis = "Spreadsheet_StyleBold";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetStyleBold";
}
void CmdSpreadsheetStyleBold::activated(int iMsg)
@@ -606,17 +650,18 @@ void CmdSpreadsheetStyleBold::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
QModelIndexList selection = sheetView->selectedIndexes();
if (!selection.empty()) {
bool allBold = true;
for (const auto& it : selection) {
const Cell * cell = sheet->getCell(CellAddress(it.row(), it.column()));
const Cell* cell = sheet->getCell(CellAddress(it.row(), it.column()));
if (cell) {
std::set<std::string> style;
@@ -634,12 +679,20 @@ void CmdSpreadsheetStyleBold::activated(int iMsg)
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Set bold text"));
for (; i != ranges.end(); ++i) {
if (!allBold)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setStyle('%s', 'bold', 'add')", sheet->getNameInDocument(),
i->rangeString().c_str());
else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setStyle('%s', 'bold', 'remove')", sheet->getNameInDocument(),
i->rangeString().c_str());
if (!allBold) {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setStyle('%s', 'bold', 'add')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
else {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setStyle('%s', 'bold', 'remove')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
@@ -652,9 +705,9 @@ bool CmdSpreadsheetStyleBold::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -664,15 +717,15 @@ bool CmdSpreadsheetStyleBold::isActive()
DEF_STD_CMD_A(CmdSpreadsheetStyleItalic)
CmdSpreadsheetStyleItalic::CmdSpreadsheetStyleItalic()
: Command("Spreadsheet_StyleItalic")
: Command("Spreadsheet_StyleItalic")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Italic text");
sToolTipText = QT_TR_NOOP("Set text in selected cells italic");
sWhatsThis = "Spreadsheet_StyleItalic";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetStyleItalic";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Italic text");
sToolTipText = QT_TR_NOOP("Set text in selected cells italic");
sWhatsThis = "Spreadsheet_StyleItalic";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetStyleItalic";
}
void CmdSpreadsheetStyleItalic::activated(int iMsg)
@@ -680,17 +733,18 @@ void CmdSpreadsheetStyleItalic::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
QModelIndexList selection = sheetView->selectedIndexes();
if (!selection.empty()) {
bool allItalic = true;
for (const auto& it : selection) {
const Cell * cell = sheet->getCell(CellAddress(it.row(), it.column()));
const Cell* cell = sheet->getCell(CellAddress(it.row(), it.column()));
if (cell) {
std::set<std::string> style;
@@ -708,12 +762,20 @@ void CmdSpreadsheetStyleItalic::activated(int iMsg)
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Set italic text"));
for (; i != ranges.end(); ++i) {
if (!allItalic)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setStyle('%s', 'italic', 'add')", sheet->getNameInDocument(),
i->rangeString().c_str());
else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setStyle('%s', 'italic', 'remove')", sheet->getNameInDocument(),
i->rangeString().c_str());
if (!allItalic) {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setStyle('%s', 'italic', 'add')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
else {
Gui::Command::doCommand(
Gui::Command::Doc,
"App.ActiveDocument.%s.setStyle('%s', 'italic', 'remove')",
sheet->getNameInDocument(),
i->rangeString().c_str());
}
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
@@ -726,9 +788,9 @@ bool CmdSpreadsheetStyleItalic::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -738,15 +800,15 @@ bool CmdSpreadsheetStyleItalic::isActive()
DEF_STD_CMD_A(CmdSpreadsheetStyleUnderline)
CmdSpreadsheetStyleUnderline::CmdSpreadsheetStyleUnderline()
: Command("Spreadsheet_StyleUnderline")
: Command("Spreadsheet_StyleUnderline")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Underline text");
sToolTipText = QT_TR_NOOP("Underline text in selected cells");
sWhatsThis = "Spreadsheet_StyleUnderline";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetStyleUnderline";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Underline text");
sToolTipText = QT_TR_NOOP("Underline text in selected cells");
sWhatsThis = "Spreadsheet_StyleUnderline";
sStatusTip = sToolTipText;
sPixmap = "SpreadsheetStyleUnderline";
}
void CmdSpreadsheetStyleUnderline::activated(int iMsg)
@@ -754,17 +816,18 @@ 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);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
QModelIndexList selection = sheetView->selectedIndexes();
if (!selection.empty()) {
bool allUnderline = true;
for (const auto& it : selection) {
const Cell * cell = sheet->getCell(CellAddress(it.row(), it.column()));
const Cell* cell = sheet->getCell(CellAddress(it.row(), it.column()));
if (cell) {
std::set<std::string> style;
@@ -782,12 +845,20 @@ void CmdSpreadsheetStyleUnderline::activated(int iMsg)
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "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());
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()");
@@ -800,8 +871,9 @@ bool CmdSpreadsheetStyleUnderline::isActive()
{
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow))
if (activeWindow && freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow)) {
return true;
}
}
return false;
}
@@ -811,16 +883,16 @@ bool CmdSpreadsheetStyleUnderline::isActive()
DEF_STD_CMD_A(CmdSpreadsheetSetAlias)
CmdSpreadsheetSetAlias::CmdSpreadsheetSetAlias()
: Command("Spreadsheet_SetAlias")
: Command("Spreadsheet_SetAlias")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Set alias");
sToolTipText = QT_TR_NOOP("Set alias for selected cell");
sWhatsThis = "Spreadsheet_SetAlias";
sStatusTip = sToolTipText;
sAccel = "Ctrl+Shift+A";
sPixmap = "SpreadsheetAlias";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Set alias");
sToolTipText = QT_TR_NOOP("Set alias for selected cell");
sWhatsThis = "Spreadsheet_SetAlias";
sStatusTip = sToolTipText;
sAccel = "Ctrl+Shift+A";
sPixmap = "SpreadsheetAlias";
}
void CmdSpreadsheetSetAlias::activated(int iMsg)
@@ -828,24 +900,29 @@ void CmdSpreadsheetSetAlias::activated(int iMsg)
Q_UNUSED(iMsg);
if (getActiveGuiDocument()) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
QModelIndexList selection = sheetView->selectedIndexes();
if (selection.size() == 1) {
std::vector<Range> range;
range.emplace_back(selection[0].row(), selection[0].column(),
selection[0].row(), selection[0].column());
range.emplace_back(selection[0].row(),
selection[0].column(),
selection[0].row(),
selection[0].column());
std::unique_ptr<PropertiesDialog> dialog(new PropertiesDialog(sheet, range, sheetView));
std::unique_ptr<PropertiesDialog> dialog(
new PropertiesDialog(sheet, range, sheetView));
dialog->selectAlias();
if (dialog->exec() == QDialog::Accepted)
if (dialog->exec() == QDialog::Accepted) {
dialog->apply();
}
}
}
}
@@ -857,13 +934,15 @@ bool CmdSpreadsheetSetAlias::isActive()
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
if (activeWindow) {
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
QModelIndexList selection = sheetView->selectedIndexes();
if (selection.size() == 1)
if (selection.size() == 1) {
return true;
}
}
}
}
@@ -875,15 +954,15 @@ bool CmdSpreadsheetSetAlias::isActive()
DEF_STD_CMD_A(CmdCreateSpreadsheet)
CmdCreateSpreadsheet::CmdCreateSpreadsheet()
:Command("Spreadsheet_CreateSheet")
: Command("Spreadsheet_CreateSheet")
{
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Create spreadsheet");
sToolTipText = QT_TR_NOOP("Create a new spreadsheet");
sWhatsThis = "Spreadsheet_CreateSheet";
sStatusTip = sToolTipText;
sPixmap = "Spreadsheet";
sAppModule = "Spreadsheet";
sGroup = QT_TR_NOOP("Spreadsheet");
sMenuText = QT_TR_NOOP("Create spreadsheet");
sToolTipText = QT_TR_NOOP("Create a new spreadsheet");
sWhatsThis = "Spreadsheet_CreateSheet";
sStatusTip = sToolTipText;
sPixmap = "Spreadsheet";
}
void CmdCreateSpreadsheet::activated(int iMsg)
@@ -892,9 +971,9 @@ void CmdCreateSpreadsheet::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Spreadsheet");
openCommand(QT_TRANSLATE_NOOP("Command", "Create Spreadsheet"));
doCommand(Doc,"App.activeDocument().addObject('Spreadsheet::Sheet','%s\')",FeatName.c_str());
doCommand(Gui,"Gui.Selection.clearSelection()\n");
doCommand(Gui,"Gui.Selection.addSelection(App.activeDocument().Name,'%s\')",FeatName.c_str());
doCommand(Doc, "App.activeDocument().addObject('Spreadsheet::Sheet','%s\')", FeatName.c_str());
doCommand(Gui, "Gui.Selection.clearSelection()\n");
doCommand(Gui, "Gui.Selection.addSelection(App.activeDocument().Name,'%s\')", FeatName.c_str());
commitCommand();
}
@@ -907,7 +986,7 @@ bool CmdCreateSpreadsheet::isActive()
void CreateSpreadsheetCommands()
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
rcCmdMgr.addCommand(new CmdCreateSpreadsheet());

View File

@@ -22,8 +22,8 @@
#include "PreCompiled.h"
#include <boost/algorithm/string.hpp>
#include <QMessageBox>
#include <boost/algorithm/string.hpp>
#include <App/Application.h>
#include <App/Document.h>
@@ -39,42 +39,49 @@ using namespace App;
using namespace Spreadsheet;
using namespace SpreadsheetGui;
DlgBindSheet::DlgBindSheet(Sheet *sheet, const std::vector<Range> &ranges, QWidget *parent)
: QDialog(parent), sheet(sheet), range(ranges.front()), ui(new Ui::DlgBindSheet)
DlgBindSheet::DlgBindSheet(Sheet* sheet, const std::vector<Range>& ranges, QWidget* parent)
: QDialog(parent)
, sheet(sheet)
, range(ranges.front())
, ui(new Ui::DlgBindSheet)
{
ui->setupUi(this);
// remove the automatic help button in dialog title since we don't use it
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
std::string toStart,toEnd;
std::string toStart, toEnd;
ExpressionPtr pStart, pEnd;
App::ObjectIdentifier bindingTarget;
PropertySheet::BindingType type = sheet->getCellBinding(range,&pStart,&pEnd,&bindingTarget);
if(type == PropertySheet::BindingNone) {
if(ranges.size()>1) {
PropertySheet::BindingType type = sheet->getCellBinding(range, &pStart, &pEnd, &bindingTarget);
if (type == PropertySheet::BindingNone) {
if (ranges.size() > 1) {
toStart = ranges.back().from().toString();
toEnd = ranges.back().to().toString();
} else {
CellAddress target(range.to().row()?0:range.to().row()+1,range.from().col());
}
else {
CellAddress target(range.to().row() ? 0 : range.to().row() + 1, range.from().col());
toStart = target.toString();
target.setRow(target.row() + range.to().row() - range.from().row());
target.setCol(target.col() + range.to().col() - range.from().col());
toEnd = target.toString();
}
ui->btnDiscard->setDisabled(true);
} else {
}
else {
ui->lineEditFromStart->setReadOnly(true);
ui->lineEditFromEnd->setReadOnly(true);
ui->checkBoxHREF->setChecked(type==PropertySheet::BindingHiddenRef);
ui->checkBoxHREF->setChecked(type == PropertySheet::BindingHiddenRef);
assert(pStart && pEnd);
if(!pStart->hasComponent() && pStart->isDerivedFrom(StringExpression::getClassTypeId()))
if (!pStart->hasComponent() && pStart->isDerivedFrom(StringExpression::getClassTypeId())) {
toStart = static_cast<StringExpression*>(pStart.get())->getText();
}
else {
toStart = "=";
toStart += pStart->toString();
}
if(!pEnd->hasComponent() && pEnd->isDerivedFrom(StringExpression::getClassTypeId()))
if (!pEnd->hasComponent() && pEnd->isDerivedFrom(StringExpression::getClassTypeId())) {
toEnd = static_cast<StringExpression*>(pEnd.get())->getText();
}
else {
toEnd = "=";
toEnd += pEnd->toString();
@@ -84,49 +91,59 @@ DlgBindSheet::DlgBindSheet(Sheet *sheet, const std::vector<Range> &ranges, QWidg
ui->lineEditFromStart->setText(QString::fromLatin1(range.from().toString().c_str()));
ui->lineEditFromEnd->setText(QString::fromLatin1(range.to().toString().c_str()));
ui->lineEditToStart->setDocumentObject(sheet,false);
ui->lineEditToStart->setDocumentObject(sheet, false);
ui->lineEditToStart->setPrefix('=');
ui->lineEditToEnd->setDocumentObject(sheet,false);
ui->lineEditToEnd->setDocumentObject(sheet, false);
ui->lineEditToEnd->setPrefix('=');
ui->lineEditToStart->setText(QLatin1String(toStart.c_str()));
ui->lineEditToEnd->setText(QLatin1String(toEnd.c_str()));
ui->comboBox->addItem(QString::fromLatin1(". (%1)").arg(
QString::fromUtf8(sheet->Label.getValue())), QByteArray(""));
ui->comboBox->addItem(
QString::fromLatin1(". (%1)").arg(QString::fromUtf8(sheet->Label.getValue())),
QByteArray(""));
App::DocumentObject *target = bindingTarget.getDocumentObject();
for(auto obj : sheet->getDocument()->getObjectsOfType<Sheet>()) {
if(obj == sheet)
App::DocumentObject* target = bindingTarget.getDocumentObject();
for (auto obj : sheet->getDocument()->getObjectsOfType<Sheet>()) {
if (obj == sheet) {
continue;
}
QString label;
if(obj->Label.getStrValue() != obj->getNameInDocument())
label = QString::fromLatin1("%1 (%2)").arg(
QString::fromLatin1(obj->getNameInDocument()),
QString::fromUtf8(obj->Label.getValue()));
else
if (obj->Label.getStrValue() != obj->getNameInDocument()) {
label =
QString::fromLatin1("%1 (%2)").arg(QString::fromLatin1(obj->getNameInDocument()),
QString::fromUtf8(obj->Label.getValue()));
}
else {
label = QLatin1String(obj->getNameInDocument());
}
ui->comboBox->addItem(label, QByteArray(obj->getNameInDocument()));
if (obj == target)
ui->comboBox->setCurrentIndex(ui->comboBox->count()-1);
if (obj == target) {
ui->comboBox->setCurrentIndex(ui->comboBox->count() - 1);
}
}
for(auto doc : GetApplication().getDocuments()) {
if(doc == sheet->getDocument())
for (auto doc : GetApplication().getDocuments()) {
if (doc == sheet->getDocument()) {
continue;
for(auto obj : sheet->getDocument()->getObjectsOfType<Sheet>()) {
if(obj == sheet)
}
for (auto obj : sheet->getDocument()->getObjectsOfType<Sheet>()) {
if (obj == sheet) {
continue;
}
std::string fullname = obj->getFullName();
QString label;
if(obj->Label.getStrValue() != obj->getNameInDocument())
label = QString::fromLatin1("%1 (%2)").arg(
QString::fromLatin1(fullname.c_str()),
QString::fromUtf8(obj->Label.getValue()));
else
if (obj->Label.getStrValue() != obj->getNameInDocument()) {
label =
QString::fromLatin1("%1 (%2)").arg(QString::fromLatin1(fullname.c_str()),
QString::fromUtf8(obj->Label.getValue()));
}
else {
label = QLatin1String(fullname.c_str());
}
ui->comboBox->addItem(label, QByteArray(fullname.c_str()));
if (obj == target)
ui->comboBox->setCurrentIndex(ui->comboBox->count()-1);
if (obj == target) {
ui->comboBox->setCurrentIndex(ui->comboBox->count() - 1);
}
}
}
@@ -142,23 +159,29 @@ void DlgBindSheet::accept()
{
bool commandActive = false;
try {
const char *ref = ui->comboBox->itemData(ui->comboBox->currentIndex()).toByteArray().constData(); // clazy:exclude=returning-data-from-temporary
const char* ref = ui->comboBox->itemData(ui->comboBox->currentIndex())
.toByteArray()
.constData();// clazy:exclude=returning-data-from-temporary
auto obj = sheet;
if(ref[0]) {
const char *sep = strchr(ref,'#');
if(sep) {
std::string docname(ref,sep);
if (ref[0]) {
const char* sep = strchr(ref, '#');
if (sep) {
std::string docname(ref, sep);
auto doc = GetApplication().getDocument(docname.c_str());
if(!doc)
if (!doc) {
FC_THROWM(Base::RuntimeError, "Cannot find document " << docname);
obj = Base::freecad_dynamic_cast<Sheet>(doc->getObject(sep+1));
} else
}
obj = Base::freecad_dynamic_cast<Sheet>(doc->getObject(sep + 1));
}
else {
obj = Base::freecad_dynamic_cast<Sheet>(sheet->getDocument()->getObject(ref));
if(!obj)
}
if (!obj) {
FC_THROWM(Base::RuntimeError, "Cannot find Spreadsheet '" << ref << "'");
}
}
auto checkAddress = [](std::string &addr, CellAddress &cell, bool quote) {
auto checkAddress = [](std::string& addr, CellAddress& cell, bool quote) {
std::string copy(addr);
boost::to_upper(copy);
cell = App::stringToAddress(copy.c_str(), true);
@@ -167,10 +190,12 @@ void DlgBindSheet::accept()
msg += addr;
throw Base::ValueError(msg.c_str());
}
if (quote)
if (quote) {
addr = std::string("<<") + copy + ">>";
else
}
else {
addr = copy;
}
};
CellAddress fromCellStart, fromCellEnd, toCellStart, toCellEnd;
@@ -180,25 +205,32 @@ void DlgBindSheet::accept()
checkAddress(fromEnd, fromCellEnd, false);
std::string toStart(ui->lineEditToStart->text().trimmed().toLatin1().constData());
if(boost::starts_with(toStart,"="))
if (boost::starts_with(toStart, "=")) {
toStart.erase(toStart.begin());
else
}
else {
checkAddress(toStart, toCellStart, true);
}
std::string toEnd(ui->lineEditToEnd->text().trimmed().toLatin1().constData());
if(boost::starts_with(toEnd,"="))
if (boost::starts_with(toEnd, "=")) {
toEnd.erase(toEnd.begin());
}
else {
checkAddress(toEnd, toCellEnd, true);
if (toCellStart.isValid()) {
App::Range fromRange(fromCellStart, fromCellEnd, true);
App::Range toRange(toCellStart, toCellEnd, true);
if (fromRange.size() != toRange.size()) {
auto res = QMessageBox::warning(this, tr("Bind cells"),
tr("Source and target cell count mismatch. Partial binding may still work.\n\n"
"Do you want to continue?"), QMessageBox::Yes|QMessageBox::No);
if (res == QMessageBox::No)
auto res = QMessageBox::warning(this,
tr("Bind cells"),
tr("Source and target cell count mismatch. "
"Partial binding may still work.\n\n"
"Do you want to continue?"),
QMessageBox::Yes | QMessageBox::No);
if (res == QMessageBox::No) {
return;
}
}
}
}
@@ -206,39 +238,67 @@ void DlgBindSheet::accept()
Gui::Command::openCommand("Bind cells");
commandActive = true;
if(ui->checkBoxHREF->isChecked()) {
Gui::cmdAppObjectArgs(sheet, "setExpression('.cells.Bind.%s.%s', None)", fromStart, fromEnd);
if (ui->checkBoxHREF->isChecked()) {
Gui::cmdAppObjectArgs(sheet,
"setExpression('.cells.BindHiddenRef.%s.%s', 'hiddenref(tuple(%s.cells, %s, %s))')",
fromStart, fromEnd, ref, toStart, toEnd);
} else {
Gui::cmdAppObjectArgs(sheet, "setExpression('.cells.BindHiddenRef.%s.%s', None)", fromStart, fromEnd);
"setExpression('.cells.Bind.%s.%s', None)",
fromStart,
fromEnd);
Gui::cmdAppObjectArgs(
sheet,
"setExpression('.cells.BindHiddenRef.%s.%s', 'hiddenref(tuple(%s.cells, %s, %s))')",
fromStart,
fromEnd,
ref,
toStart,
toEnd);
}
else {
Gui::cmdAppObjectArgs(sheet,
"setExpression('.cells.Bind.%s.%s', 'tuple(%s.cells, %s, %s)')",
fromStart, fromEnd, ref, toStart, toEnd);
"setExpression('.cells.BindHiddenRef.%s.%s', None)",
fromStart,
fromEnd);
Gui::cmdAppObjectArgs(sheet,
"setExpression('.cells.Bind.%s.%s', 'tuple(%s.cells, %s, %s)')",
fromStart,
fromEnd,
ref,
toStart,
toEnd);
}
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::commitCommand();
QDialog::accept();
} catch(Base::Exception &e) {
}
catch (Base::Exception& e) {
e.ReportException();
QMessageBox::critical(this, tr("Bind Spreadsheet Cells"), tr("Error: \n") + QString::fromUtf8(e.what()));
if(commandActive)
QMessageBox::critical(this,
tr("Bind Spreadsheet Cells"),
tr("Error: \n") + QString::fromUtf8(e.what()));
if (commandActive) {
Gui::Command::abortCommand();
}
}
}
void DlgBindSheet::onDiscard() {
void DlgBindSheet::onDiscard()
{
try {
std::string fromStart(ui->lineEditFromStart->text().trimmed().toLatin1().constData());
std::string fromEnd(ui->lineEditFromEnd->text().trimmed().toLatin1().constData());
Gui::Command::openCommand("Unbind cells");
Gui::cmdAppObjectArgs(sheet, "setExpression('.cells.Bind.%s.%s', None)", fromStart, fromEnd);
Gui::cmdAppObjectArgs(sheet, "setExpression('.cells.BindHiddenRef.%s.%s', None)", fromStart, fromEnd);
Gui::cmdAppObjectArgs(sheet,
"setExpression('.cells.Bind.%s.%s', None)",
fromStart,
fromEnd);
Gui::cmdAppObjectArgs(sheet,
"setExpression('.cells.BindHiddenRef.%s.%s', None)",
fromStart,
fromEnd);
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::commitCommand();
reject();
} catch(Base::Exception &e) {
}
catch (Base::Exception& e) {
e.ReportException();
QMessageBox::critical(this, tr("Unbind cells"), QString::fromUtf8(e.what()));
Gui::Command::abortCommand();

View File

@@ -23,21 +23,25 @@
#ifndef DLG_BINDSHEET_H
#define DLG_BINDSHEET_H
#include <QDialog>
#include <Mod/Spreadsheet/App/Sheet.h>
#include <QDialog>
namespace Ui {
namespace Ui
{
class DlgBindSheet;
}
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class DlgBindSheet : public QDialog
class DlgBindSheet: public QDialog
{
Q_OBJECT
public:
explicit DlgBindSheet(Spreadsheet::Sheet *sheet, const std::vector<App::Range> &range, QWidget *parent = nullptr);
explicit DlgBindSheet(Spreadsheet::Sheet* sheet,
const std::vector<App::Range>& range,
QWidget* parent = nullptr);
~DlgBindSheet() override;
void accept() override;
@@ -46,11 +50,11 @@ public Q_SLOTS:
void onDiscard();
private:
Spreadsheet::Sheet * sheet;
Spreadsheet::Sheet* sheet;
App::Range range;
Ui::DlgBindSheet *ui;
Ui::DlgBindSheet* ui;
};
}
}// namespace SpreadsheetGui
#endif // DLG_BINDSHEET_H
#endif// DLG_BINDSHEET_H

View File

@@ -32,15 +32,14 @@ using namespace SpreadsheetGui;
/* TRANSLATOR SpreadsheetGui::DlgSettingsImp */
DlgSettingsImp::DlgSettingsImp( QWidget* parent )
: PreferencePage( parent )
, ui(new Ui_DlgSettings)
DlgSettingsImp::DlgSettingsImp(QWidget* parent)
: PreferencePage(parent)
, ui(new Ui_DlgSettings)
{
ui->setupUi(this);
}
/**
/**
* Destroys the object and frees any allocated resources
*/
DlgSettingsImp::~DlgSettingsImp() = default;
@@ -51,7 +50,8 @@ void DlgSettingsImp::saveSettings()
/** use whatever the user has entered here
* we'll check for validity during import/export
*/
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Spreadsheet");
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Spreadsheet");
QString delimiter = ui->delimiterComboBox->currentText();
hGrp->SetASCII("ImportExportDelimiter", delimiter.toStdString().c_str());
ui->quoteCharLineEdit->onSave();
@@ -66,21 +66,26 @@ void DlgSettingsImp::loadSettings()
* we'll recognize a few tokens: comma, semicolon, tab, and \t
*/
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Spreadsheet");
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Spreadsheet");
QString delimiter = QString::fromStdString(hGrp->GetASCII("ImportExportDelimiter", "tab"));
int idx = ui->delimiterComboBox->findText(delimiter, Qt::MatchFixedString);
if(idx != -1){
if (idx != -1) {
ui->delimiterComboBox->setCurrentIndex(idx);
} else if(delimiter.compare(QLatin1String("\\t"), Qt::CaseInsensitive) == 0){
}
else if (delimiter.compare(QLatin1String("\\t"), Qt::CaseInsensitive) == 0) {
idx = ui->delimiterComboBox->findText(QLatin1String("tab"), Qt::MatchFixedString);
ui->delimiterComboBox->setCurrentIndex(idx);
} else if(delimiter.compare(QLatin1String("semicolon"), Qt::CaseInsensitive) == 0){
}
else if (delimiter.compare(QLatin1String("semicolon"), Qt::CaseInsensitive) == 0) {
idx = ui->delimiterComboBox->findText(QLatin1String(";"), Qt::MatchFixedString);
ui->delimiterComboBox->setCurrentIndex(idx);
} else if(delimiter.compare(QLatin1String("comma"), Qt::CaseInsensitive) == 0){
}
else if (delimiter.compare(QLatin1String("comma"), Qt::CaseInsensitive) == 0) {
idx = ui->delimiterComboBox->findText(QLatin1String(","), Qt::MatchFixedString);
ui->delimiterComboBox->setCurrentIndex(idx);
} else {
}
else {
ui->delimiterComboBox->addItem(delimiter);
idx = ui->delimiterComboBox->findText(delimiter, Qt::MatchFixedString);
ui->delimiterComboBox->setCurrentIndex(idx);
@@ -95,7 +100,7 @@ void DlgSettingsImp::loadSettings()
/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgSettingsImp::changeEvent(QEvent *e)
void DlgSettingsImp::changeEvent(QEvent* e)
{
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);

View File

@@ -27,7 +27,8 @@
#include <Gui/PropertyPage.h>
#include <memory>
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class Ui_DlgSettings;
/**
@@ -35,23 +36,23 @@ class Ui_DlgSettings;
* for the Spreadsheet workbench.
* /author TheMarkster, based on work by Jürgen Riegel
*/
class DlgSettingsImp : public Gui::Dialog::PreferencePage
class DlgSettingsImp: public Gui::Dialog::PreferencePage
{
Q_OBJECT
public:
explicit DlgSettingsImp( QWidget* parent = nullptr );
explicit DlgSettingsImp(QWidget* parent = nullptr);
~DlgSettingsImp() override;
protected:
void saveSettings() override;
void loadSettings() override;
void changeEvent(QEvent *e) override;
void changeEvent(QEvent* e) override;
private:
std::unique_ptr<Ui_DlgSettings> ui;
};
} // namespace SpreadsheetGui
}// namespace SpreadsheetGui
#endif // SPREADSHEETGUI_DLGSETTINGSIMP_H
#endif// SPREADSHEETGUI_DLGSETTINGSIMP_H

View File

@@ -39,32 +39,35 @@ using namespace App;
using namespace Spreadsheet;
using namespace SpreadsheetGui;
DlgSheetConf::DlgSheetConf(Sheet *sheet, Range range, QWidget *parent)
: QDialog(parent), sheet(sheet), ui(new Ui::DlgSheetConf)
DlgSheetConf::DlgSheetConf(Sheet* sheet, Range range, QWidget* parent)
: QDialog(parent)
, sheet(sheet)
, ui(new Ui::DlgSheetConf)
{
ui->setupUi(this);
if(range.colCount()==1) {
if (range.colCount() == 1) {
auto to = range.to();
to.setCol(CellAddress::MAX_COLUMNS-1);
range = Range(range.from(),to);
to.setCol(CellAddress::MAX_COLUMNS - 1);
range = Range(range.from(), to);
}
ui->lineEditStart->setText(QString::fromLatin1(range.from().toString().c_str()));
ui->lineEditEnd->setText(QString::fromLatin1(range.to().toString().c_str()));
ui->lineEditProp->setDocumentObject(sheet,false);
ui->lineEditProp->setDocumentObject(sheet, false);
connect(ui->btnDiscard, &QPushButton::clicked, this, &DlgSheetConf::onDiscard);
CellAddress from,to;
CellAddress from, to;
std::string rangeConf;
ObjectIdentifier path;
auto prop = prepare(from,to,rangeConf,path,true);
if(prop) {
auto prop = prepare(from, to, rangeConf, path, true);
if (prop) {
ui->lineEditProp->setText(QString::fromUtf8(path.toString().c_str()));
if (auto group = prop->getGroup())
if (auto group = prop->getGroup()) {
ui->lineEditGroup->setText(QString::fromUtf8(group));
}
}
ui->lineEditStart->setText(QString::fromLatin1(from.toString().c_str()));
@@ -76,21 +79,23 @@ DlgSheetConf::~DlgSheetConf()
delete ui;
}
App::Property *DlgSheetConf::prepare(CellAddress &from, CellAddress &to,
std::string &rangeConf, ObjectIdentifier &path, bool init)
App::Property* DlgSheetConf::prepare(CellAddress& from,
CellAddress& to,
std::string& rangeConf,
ObjectIdentifier& path,
bool init)
{
from = sheet->getCellAddress(
ui->lineEditStart->text().trimmed().toLatin1().constData());
to = sheet->getCellAddress(
ui->lineEditEnd->text().trimmed().toLatin1().constData());
from = sheet->getCellAddress(ui->lineEditStart->text().trimmed().toLatin1().constData());
to = sheet->getCellAddress(ui->lineEditEnd->text().trimmed().toLatin1().constData());
if(from.col()>=to.col())
if (from.col() >= to.col()) {
FC_THROWM(Base::RuntimeError, "Invalid cell range");
}
// Setup row as parameters, and column as configurations
to.setRow(from.row());
CellAddress confFrom(from.row()+1,from.col());
CellAddress confFrom(from.row() + 1, from.col());
rangeConf = confFrom.toString();
// rangeConf is supposed to hold the range of string cells, each
// holding the name of a configuration. The '|' below indicates a
@@ -100,52 +105,59 @@ App::Property *DlgSheetConf::prepare(CellAddress &from, CellAddress &to,
// configuration.
rangeConf += ":|";
if(!init) {
if (!init) {
std::string exprTxt(ui->lineEditProp->text().trimmed().toUtf8().constData());
ExpressionPtr expr;
try {
expr.reset(App::Expression::parse(sheet,exprTxt));
} catch (Base::Exception &e) {
expr.reset(App::Expression::parse(sheet, exprTxt));
}
catch (Base::Exception& e) {
e.ReportException();
FC_THROWM(Base::RuntimeError, "Failed to parse expression for property");
}
if(expr->hasComponent() || !expr->isDerivedFrom(App::VariableExpression::getClassTypeId()))
if (expr->hasComponent()
|| !expr->isDerivedFrom(App::VariableExpression::getClassTypeId())) {
FC_THROWM(Base::RuntimeError, "Invalid property expression: " << expr->toString());
}
path = static_cast<App::VariableExpression*>(expr.get())->getPath();
auto obj = path.getDocumentObject();
if(!obj)
if (!obj) {
FC_THROWM(Base::RuntimeError, "Invalid object referenced in: " << expr->toString());
}
int pseudoType;
auto prop = path.getProperty(&pseudoType);
if(pseudoType || (prop && (!prop->isDerivedFrom(App::PropertyEnumeration::getClassTypeId())
|| !prop->testStatus(App::Property::PropDynamic))))
{
if (pseudoType
|| (prop
&& (!prop->isDerivedFrom(App::PropertyEnumeration::getClassTypeId())
|| !prop->testStatus(App::Property::PropDynamic)))) {
FC_THROWM(Base::RuntimeError, "Invalid property referenced in: " << expr->toString());
}
return prop;
}
Cell *cell = sheet->getCell(from);
if(cell && cell->getExpression()) {
Cell* cell = sheet->getCell(from);
if (cell && cell->getExpression()) {
auto expr = cell->getExpression();
if(expr->isDerivedFrom(FunctionExpression::getClassTypeId())) {
if (expr->isDerivedFrom(FunctionExpression::getClassTypeId())) {
auto fexpr = Base::freecad_dynamic_cast<FunctionExpression>(cell->getExpression());
if(fexpr && (fexpr->getFunction()==FunctionExpression::HREF
|| fexpr->getFunction()==FunctionExpression::HIDDENREF)
&& fexpr->getArgs().size()==1)
if (fexpr
&& (fexpr->getFunction() == FunctionExpression::HREF
|| fexpr->getFunction() == FunctionExpression::HIDDENREF)
&& fexpr->getArgs().size() == 1) {
expr = fexpr->getArgs().front();
}
}
auto vexpr = Base::freecad_dynamic_cast<VariableExpression>(expr);
if(vexpr) {
auto prop = Base::freecad_dynamic_cast<PropertyEnumeration>(
vexpr->getPath().getProperty());
if(prop) {
if (vexpr) {
auto prop =
Base::freecad_dynamic_cast<PropertyEnumeration>(vexpr->getPath().getProperty());
if (prop) {
auto obj = Base::freecad_dynamic_cast<DocumentObject>(prop->getContainer());
if (obj && prop->hasName()) {
path = ObjectIdentifier(sheet);
path.setDocumentObjectName(obj,true);
path.setDocumentObjectName(obj, true);
path << ObjectIdentifier::SimpleComponent(prop->getName());
return prop;
}
@@ -160,63 +172,78 @@ void DlgSheetConf::accept()
bool commandActive = false;
try {
std::string rangeConf;
CellAddress from,to;
CellAddress from, to;
ObjectIdentifier path;
App::Property *prop = prepare(from,to,rangeConf,path,false);
App::Property* prop = prepare(from, to, rangeConf, path, false);
Range range(from,to);
Range range(from, to);
// check rangeConf, make sure it is a sequence of string only
Range r(sheet->getRange(rangeConf.c_str()));
do {
auto cell = sheet->getCell(*r);
if(cell && cell->getExpression()) {
if (cell && cell->getExpression()) {
ExpressionPtr expr(cell->getExpression()->eval());
if(expr->isDerivedFrom(StringExpression::getClassTypeId()))
if (expr->isDerivedFrom(StringExpression::getClassTypeId())) {
continue;
}
}
FC_THROWM(Base::RuntimeError, "Expects cell "
<< r.address() << " evaluates to string.\n"
<< rangeConf << " is supposed to contain a list of configuration names");
} while(r.next());
FC_THROWM(Base::RuntimeError,
"Expects cell " << r.address() << " evaluates to string.\n"
<< rangeConf
<< " is supposed to contain a list of configuration names");
} while (r.next());
std::string exprTxt(ui->lineEditProp->text().trimmed().toUtf8().constData());
App::ExpressionPtr expr(App::Expression::parse(sheet,exprTxt));
if(expr->hasComponent() || !expr->isDerivedFrom(App::VariableExpression::getClassTypeId()))
App::ExpressionPtr expr(App::Expression::parse(sheet, exprTxt));
if (expr->hasComponent()
|| !expr->isDerivedFrom(App::VariableExpression::getClassTypeId())) {
FC_THROWM(Base::RuntimeError, "Invalid property expression: " << expr->toString());
}
AutoTransaction guard("Setup conf table");
commandActive = true;
// unbind any previous binding
int count = range.rowCount() * range.colCount();
for (int i=0; i<count; ++i) {
for (int i = 0; i < count; ++i) {
auto r = range;
auto binding = sheet->getCellBinding(r);
if(!binding)
if (!binding) {
break;
Gui::cmdAppObjectArgs(sheet, "setExpression('.cells.%s.%s.%s', None)",
binding==PropertySheet::BindingNormal?"Bind":"BindHiddenRef",
r.from().toString(), r.to().toString());
}
Gui::cmdAppObjectArgs(sheet,
"setExpression('.cells.%s.%s.%s', None)",
binding == PropertySheet::BindingNormal ? "Bind"
: "BindHiddenRef",
r.from().toString(),
r.to().toString());
}
auto obj = path.getDocumentObject();
if(!obj)
if (!obj) {
FC_THROWM(Base::RuntimeError, "Object not found");
}
// Add a dynamic PropertyEnumeration for user to switch the configuration
std::string propName = path.getPropertyName();
QString groupName = ui->lineEditGroup->text().trimmed();
if(!prop) {
prop = obj->addDynamicProperty("App::PropertyEnumeration", propName.c_str(),
groupName.toUtf8().constData());
} else if (groupName.size())
if (!prop) {
prop = obj->addDynamicProperty("App::PropertyEnumeration",
propName.c_str(),
groupName.toUtf8().constData());
}
else if (groupName.size()) {
obj->changeDynamicProperty(prop, groupName.toUtf8().constData(), nullptr);
prop->setStatus(App::Property::CopyOnChange,true);
}
prop->setStatus(App::Property::CopyOnChange, true);
// Bind the enumeration items to the column of configuration names
Gui::cmdAppObjectArgs(obj, "setExpression('%s.Enum', '%s.cells[<<%s>>]')",
propName, sheet->getFullName(), rangeConf);
Gui::cmdAppObjectArgs(obj,
"setExpression('%s.Enum', '%s.cells[<<%s>>]')",
propName,
sheet->getFullName(),
rangeConf);
Gui::cmdAppObjectArgs(obj, "recompute()");
@@ -224,76 +251,97 @@ void DlgSheetConf::accept()
// could have just bind the entire row as below, but binding the first
// cell separately using a simpler expression can make it easy for us
// to extract the name of the PropertyEnumeration for editing or unsetup.
Gui::cmdAppObjectArgs(sheet, "set('%s', '=hiddenref(%s.String)')",
from.toString(CellAddress::Cell::ShowRowColumn), prop->getFullName());
Gui::cmdAppObjectArgs(sheet,
"set('%s', '=hiddenref(%s.String)')",
from.toString(CellAddress::Cell::ShowRowColumn),
prop->getFullName());
// Adjust the range to skip the first cell
range = Range(from.row(),from.col()+1,to.row(),to.col());
range = Range(from.row(), from.col() + 1, to.row(), to.col());
// Formulate expression to calculate the row binding using
// PropertyEnumeration
Gui::cmdAppObjectArgs(sheet, "setExpression('.cells.Bind.%s.%s', "
Gui::cmdAppObjectArgs(
sheet,
"setExpression('.cells.Bind.%s.%s', "
"'tuple(.cells, <<%s>> + str(hiddenref(%s)+%d), <<%s>> + str(hiddenref(%s)+%d))')",
range.from().toString(CellAddress::Cell::ShowRowColumn),
range.to().toString(CellAddress::Cell::ShowRowColumn),
range.from().toString(CellAddress::Cell::ShowColumn), prop->getFullName(), from.row()+2,
range.to().toString(CellAddress::Cell::ShowColumn), prop->getFullName(), from.row()+2);
range.from().toString(CellAddress::Cell::ShowColumn),
prop->getFullName(),
from.row() + 2,
range.to().toString(CellAddress::Cell::ShowColumn),
prop->getFullName(),
from.row() + 2);
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::commitCommand();
QDialog::accept();
} catch(Base::Exception &e) {
}
catch (Base::Exception& e) {
e.ReportException();
QMessageBox::critical(this, tr("Setup configuration table"), QString::fromUtf8(e.what()));
if(commandActive)
if (commandActive) {
Gui::Command::abortCommand();
}
}
}
void DlgSheetConf::onDiscard() {
void DlgSheetConf::onDiscard()
{
bool commandActive = false;
try {
std::string rangeConf;
CellAddress from,to;
CellAddress from, to;
ObjectIdentifier path;
auto prop = prepare(from,to,rangeConf,path,true);
auto prop = prepare(from, to, rangeConf, path, true);
Range range(from,to);
Range range(from, to);
AutoTransaction guard("Unsetup conf table");
commandActive = true;
// unbind any previous binding
int count = range.rowCount() * range.colCount();
for (int i=0; i<count; ++i) {
for (int i = 0; i < count; ++i) {
auto r = range;
auto binding = sheet->getCellBinding(r);
if(!binding)
if (!binding) {
break;
Gui::cmdAppObjectArgs(sheet, "setExpression('.cells.%s.%s.%s', None)",
binding==PropertySheet::BindingNormal?"Bind":"BindHiddenRef",
r.from().toString(), r.to().toString());
}
Gui::cmdAppObjectArgs(sheet,
"setExpression('.cells.%s.%s.%s', None)",
binding == PropertySheet::BindingNormal ? "Bind"
: "BindHiddenRef",
r.from().toString(),
r.to().toString());
}
Gui::cmdAppObjectArgs(sheet, "clear('%s')", from.toString(CellAddress::Cell::ShowRowColumn));
Gui::cmdAppObjectArgs(sheet,
"clear('%s')",
from.toString(CellAddress::Cell::ShowRowColumn));
if(prop && prop->getName()) {
if (prop && prop->getName()) {
auto obj = path.getDocumentObject();
if(!obj)
if (!obj) {
FC_THROWM(Base::RuntimeError, "Object not found");
}
Gui::cmdAppObjectArgs(obj, "setExpression('%s.Enum', None)", prop->getName());
if(prop->testStatus(Property::PropDynamic))
if (prop->testStatus(Property::PropDynamic)) {
Gui::cmdAppObjectArgs(obj, "removeProperty('%s')", prop->getName());
}
}
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::commitCommand();
QDialog::accept();
} catch(Base::Exception &e) {
}
catch (Base::Exception& e) {
e.ReportException();
QMessageBox::critical(this, tr("Unsetup configuration table"), QString::fromUtf8(e.what()));
if(commandActive)
if (commandActive) {
Gui::Command::abortCommand();
}
}
}

View File

@@ -23,36 +23,41 @@
#ifndef DLG_SHEETCONF_H
#define DLG_SHEETCONF_H
#include <QDialog>
#include <Mod/Spreadsheet/App/Sheet.h>
#include <QDialog>
namespace Ui {
namespace Ui
{
class DlgSheetConf;
}
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class DlgSheetConf : public QDialog
class DlgSheetConf: public QDialog
{
Q_OBJECT
public:
explicit DlgSheetConf(Spreadsheet::Sheet *sheet, App::Range range, QWidget *parent = nullptr);
explicit DlgSheetConf(Spreadsheet::Sheet* sheet, App::Range range, QWidget* parent = nullptr);
~DlgSheetConf() override;
void accept() override;
App::Property *prepare(App::CellAddress &from, App::CellAddress &to,
std::string &rangeConf, App::ObjectIdentifier &path, bool init);
App::Property* prepare(App::CellAddress& from,
App::CellAddress& to,
std::string& rangeConf,
App::ObjectIdentifier& path,
bool init);
public Q_SLOTS:
void onDiscard();
private:
Spreadsheet::Sheet * sheet;
Ui::DlgSheetConf *ui;
Spreadsheet::Sheet* sheet;
Ui::DlgSheetConf* ui;
};
}
}// namespace SpreadsheetGui
#endif // DLG_SHEETCONF_H
#endif// DLG_SHEETCONF_H

View File

@@ -23,9 +23,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QApplication>
# include <QEvent>
# include <QKeyEvent>
#include <QApplication>
#include <QEvent>
#include <QKeyEvent>
#endif
#include "LineEdit.h"
@@ -33,7 +33,7 @@
using namespace SpreadsheetGui;
LineEdit::LineEdit(QWidget *parent)
LineEdit::LineEdit(QWidget* parent)
: Gui::ExpressionLineEdit(parent, false, '=', true)
, lastKeyPressed(0)
{
@@ -46,12 +46,12 @@ bool LineEdit::eventFilter(QObject* object, QEvent* event)
if (event && event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Tab) {
// Special tab handling -- must be done via a QApplication event filter, otherwise the widget
// system will always grab the tab events
// Special tab handling -- must be done via a QApplication event filter, otherwise the
// widget system will always grab the tab events
if (completerActive()) {
hideCompleter();
event->accept();
return true; // To make sure this tab press doesn't do anything else
return true;// To make sure this tab press doesn't do anything else
}
else {
lastKeyPressed = keyEvent->key();
@@ -59,22 +59,23 @@ bool LineEdit::eventFilter(QObject* object, QEvent* event)
}
}
}
return false; // We don't usually actually "handle" the tab event, we just keep track of it
return false;// We don't usually actually "handle" the tab event, we just keep track of it
}
bool LineEdit::event(QEvent *event)
bool LineEdit::event(QEvent* event)
{
if (event && event->type() == QEvent::FocusIn) {
qApp->installEventFilter(this);
}
else if (event && event->type() == QEvent::FocusOut) {
qApp->removeEventFilter(this);
if (lastKeyPressed)
if (lastKeyPressed) {
Q_EMIT finishedWithKey(lastKeyPressed, lastModifiers);
}
lastKeyPressed = 0;
}
else if (event && event->type() == QEvent::KeyPress && !completerActive()) {
QKeyEvent * kevent = static_cast<QKeyEvent*>(event);
QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
lastKeyPressed = kevent->key();
lastModifiers = kevent->modifiers();
}

View File

@@ -23,19 +23,20 @@
#ifndef LINEEDIT_H
#define LINEEDIT_H
#include <QWidget>
#include <Gui/ExpressionCompleter.h>
#include <QWidget>
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class LineEdit : public Gui::ExpressionLineEdit
class LineEdit: public Gui::ExpressionLineEdit
{
Q_OBJECT
public:
explicit LineEdit(QWidget *parent = nullptr);
explicit LineEdit(QWidget* parent = nullptr);
bool event(QEvent *event) override;
bool event(QEvent* event) override;
Q_SIGNALS:
void finishedWithKey(int key, Qt::KeyboardModifiers modifiers);
@@ -49,6 +50,6 @@ private:
Qt::KeyboardModifiers lastModifiers;
};
}
}// namespace SpreadsheetGui
#endif // LINEEDIT_H
#endif// LINEEDIT_H

View File

@@ -28,10 +28,10 @@
// point at which warnings of overly long specifiers disabled (needed for VC6)
#ifdef _MSC_VER
# pragma warning(disable : 4005)
# pragma warning(disable : 4251)
# pragma warning(disable : 4503)
# pragma warning(disable : 4786) // specifier longer then 255 chars
#pragma warning(disable : 4005)
#pragma warning(disable : 4251)
#pragma warning(disable : 4503)
#pragma warning(disable : 4786)// specifier longer then 255 chars
#endif
#ifdef _PreComp_
@@ -43,14 +43,14 @@
#include <sstream>
#ifdef FC_OS_WIN32
# include <windows.h>
#include <windows.h>
#endif
// Qt Toolkit
#ifndef __QtAll__
# include <Gui/QtAll.h>
#include <Gui/QtAll.h>
#endif
#endif //_PreComp_
#endif//_PreComp_
#endif // SPREADSHEET_PRECOMPILED_H
#endif// SPREADSHEET_PRECOMPILED_H

View File

@@ -22,9 +22,9 @@
#include "PreCompiled.h"
#include <App/Range.h>
#include <App/Document.h>
#include <App/ExpressionParser.h>
#include <App/Range.h>
#include <Base/Tools.h>
#include <Gui/CommandT.h>
@@ -36,14 +36,16 @@ using namespace App;
using namespace Spreadsheet;
using namespace SpreadsheetGui;
PropertiesDialog::PropertiesDialog(Sheet *_sheet, const std::vector<Range> &_ranges, QWidget *parent) :
QDialog(parent),
sheet(_sheet),
ranges(_ranges),
ui(new Ui::PropertiesDialog),
alignment(0),
displayUnitOk(true),
aliasOk(true)
PropertiesDialog::PropertiesDialog(Sheet* _sheet,
const std::vector<Range>& _ranges,
QWidget* parent)
: QDialog(parent)
, sheet(_sheet)
, ranges(_ranges)
, ui(new Ui::PropertiesDialog)
, alignment(0)
, displayUnitOk(true)
, aliasOk(true)
{
ui->setupUi(this);
ui->foregroundColor->setStandardColors();
@@ -52,7 +54,7 @@ PropertiesDialog::PropertiesDialog(Sheet *_sheet, const std::vector<Range> &_ran
assert(ranges.size() > 0);
Range range = ranges[0];
Cell * cell = sheet->getNewCell(*range);
Cell* cell = sheet->getNewCell(*range);
assert(cell);
@@ -79,34 +81,49 @@ PropertiesDialog::PropertiesDialog(Sheet *_sheet, const std::vector<Range> &_ran
backgroundColor.b,
backgroundColor.a));
if (alignment & Cell::ALIGNMENT_LEFT)
if (alignment & Cell::ALIGNMENT_LEFT) {
ui->alignLeft->setChecked(true);
else if (alignment & Cell::ALIGNMENT_HCENTER)
}
else if (alignment & Cell::ALIGNMENT_HCENTER) {
ui->alignHCenter->setChecked(true);
else if (alignment & Cell::ALIGNMENT_RIGHT)
}
else if (alignment & Cell::ALIGNMENT_RIGHT) {
ui->alignRight->setChecked(true);
}
if (alignment & Cell::ALIGNMENT_TOP)
if (alignment & Cell::ALIGNMENT_TOP) {
ui->alignTop->setChecked(true);
else if (alignment & Cell::ALIGNMENT_VCENTER)
}
else if (alignment & Cell::ALIGNMENT_VCENTER) {
ui->alignVCenter->setChecked(true);
else if (alignment & Cell::ALIGNMENT_BOTTOM)
}
else if (alignment & Cell::ALIGNMENT_BOTTOM) {
ui->alignBottom->setChecked(true);
}
if (style.find("bold") != style.end())
if (style.find("bold") != style.end()) {
ui->styleBold->setChecked(true);
if (style.find("italic") != style.end())
}
if (style.find("italic") != style.end()) {
ui->styleItalic->setChecked(true);
if (style.find("underline") != style.end())
}
if (style.find("underline") != style.end()) {
ui->styleUnderline->setChecked(true);
}
ui->displayUnit->setText(Base::Tools::fromStdString(displayUnit.stringRep));
ui->alias->setText(Base::Tools::fromStdString(alias));
// Colors
connect(ui->foregroundColor, &QtColorPicker::colorChanged, this, &PropertiesDialog::foregroundColorChanged);
connect(ui->backgroundColor, &QtColorPicker::colorChanged, this, &PropertiesDialog::backgroundColorChanged);
connect(ui->foregroundColor,
&QtColorPicker::colorChanged,
this,
&PropertiesDialog::foregroundColorChanged);
connect(ui->backgroundColor,
&QtColorPicker::colorChanged,
this,
&PropertiesDialog::backgroundColorChanged);
// Alignment
connect(ui->alignLeft, &QRadioButton::clicked, this, &PropertiesDialog::alignmentChanged);
@@ -134,55 +151,67 @@ PropertiesDialog::PropertiesDialog(Sheet *_sheet, const std::vector<Range> &_ran
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(displayUnitOk && aliasOk);
}
void PropertiesDialog::foregroundColorChanged(const QColor & color)
void PropertiesDialog::foregroundColorChanged(const QColor& color)
{
foregroundColor = App::Color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}
void PropertiesDialog::backgroundColorChanged(const QColor & color)
void PropertiesDialog::backgroundColorChanged(const QColor& color)
{
backgroundColor = App::Color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}
void PropertiesDialog::alignmentChanged()
{
if (sender() == ui->alignLeft)
if (sender() == ui->alignLeft) {
alignment = (alignment & ~Cell::ALIGNMENT_HORIZONTAL) | Cell::ALIGNMENT_LEFT;
else if (sender() == ui->alignHCenter)
}
else if (sender() == ui->alignHCenter) {
alignment = (alignment & ~Cell::ALIGNMENT_HORIZONTAL) | Cell::ALIGNMENT_HCENTER;
else if (sender() == ui->alignRight)
}
else if (sender() == ui->alignRight) {
alignment = (alignment & ~Cell::ALIGNMENT_HORIZONTAL) | Cell::ALIGNMENT_RIGHT;
else if (sender() == ui->alignTop)
}
else if (sender() == ui->alignTop) {
alignment = (alignment & ~Cell::ALIGNMENT_VERTICAL) | Cell::ALIGNMENT_TOP;
else if (sender() == ui->alignVCenter)
}
else if (sender() == ui->alignVCenter) {
alignment = (alignment & ~Cell::ALIGNMENT_VERTICAL) | Cell::ALIGNMENT_VCENTER;
else if (sender() == ui->alignBottom)
}
else if (sender() == ui->alignBottom) {
alignment = (alignment & ~Cell::ALIGNMENT_VERTICAL) | Cell::ALIGNMENT_BOTTOM;
}
}
void PropertiesDialog::styleChanged()
{
if (sender() == ui->styleBold) {
if (ui->styleBold->isChecked())
if (ui->styleBold->isChecked()) {
style.insert("bold");
else
}
else {
style.erase("bold");
}
}
else if (sender() == ui->styleItalic) {
if (ui->styleItalic->isChecked())
if (ui->styleItalic->isChecked()) {
style.insert("italic");
else
}
else {
style.erase("italic");
}
}
else if (sender() == ui->styleUnderline) {
if (ui->styleUnderline->isChecked())
if (ui->styleUnderline->isChecked()) {
style.insert("underline");
else
}
else {
style.erase("underline");
}
}
}
void PropertiesDialog::displayUnitChanged(const QString & text)
void PropertiesDialog::displayUnitChanged(const QString& text)
{
if (text.isEmpty()) {
displayUnit = DisplayUnit();
@@ -192,7 +221,8 @@ void PropertiesDialog::displayUnitChanged(const QString & text)
QPalette palette = ui->displayUnit->palette();
try {
std::unique_ptr<UnitExpression> e(App::ExpressionParser::parseUnit(sheet, text.toUtf8().constData()));
std::unique_ptr<UnitExpression> e(
App::ExpressionParser::parseUnit(sheet, text.toUtf8().constData()));
displayUnit = DisplayUnit(text.toUtf8().constData(), e->getUnit(), e->getScaler());
palette.setColor(QPalette::Text, Qt::black);
@@ -207,7 +237,7 @@ void PropertiesDialog::displayUnitChanged(const QString & text)
ui->displayUnit->setPalette(palette);
}
void PropertiesDialog::aliasChanged(const QString & text)
void PropertiesDialog::aliasChanged(const QString& text)
{
QPalette palette = ui->alias->palette();
@@ -233,42 +263,53 @@ void PropertiesDialog::apply()
for (; i != ranges.end(); ++i) {
if (orgAlignment != alignment) {
Gui::cmdAppObjectArgs(sheet, "setAlignment('%s', '%s')",
i->rangeString().c_str(), Cell::encodeAlignment(alignment).c_str());
Gui::cmdAppObjectArgs(sheet,
"setAlignment('%s', '%s')",
i->rangeString().c_str(),
Cell::encodeAlignment(alignment).c_str());
changes = true;
}
if (orgStyle != style) {
Gui::cmdAppObjectArgs(sheet, "setStyle('%s', '%s')",
i->rangeString().c_str(), Cell::encodeStyle(style).c_str());
Gui::cmdAppObjectArgs(sheet,
"setStyle('%s', '%s')",
i->rangeString().c_str(),
Cell::encodeStyle(style).c_str());
changes = true;
}
if (orgForegroundColor != foregroundColor) {
Gui::cmdAppObjectArgs(sheet, "setForeground('%s', (%f,%f,%f,%f))",
i->rangeString().c_str(),
foregroundColor.r,
foregroundColor.g,
foregroundColor.b,
foregroundColor.a);
Gui::cmdAppObjectArgs(sheet,
"setForeground('%s', (%f,%f,%f,%f))",
i->rangeString().c_str(),
foregroundColor.r,
foregroundColor.g,
foregroundColor.b,
foregroundColor.a);
changes = true;
}
if (orgBackgroundColor != backgroundColor) {
Gui::cmdAppObjectArgs(sheet, "setBackground('%s', (%f,%f,%f,%f))",
i->rangeString().c_str(),
backgroundColor.r,
backgroundColor.g,
backgroundColor.b,
backgroundColor.a);
Gui::cmdAppObjectArgs(sheet,
"setBackground('%s', (%f,%f,%f,%f))",
i->rangeString().c_str(),
backgroundColor.r,
backgroundColor.g,
backgroundColor.b,
backgroundColor.a);
changes = true;
}
if (orgDisplayUnit != displayUnit) {
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(displayUnit.stringRep.c_str());
Gui::cmdAppObjectArgs(sheet, "setDisplayUnit('%s', '%s')",
i->rangeString().c_str(), escapedstr.c_str());
std::string escapedstr =
Base::Tools::escapedUnicodeFromUtf8(displayUnit.stringRep.c_str());
Gui::cmdAppObjectArgs(sheet,
"setDisplayUnit('%s', '%s')",
i->rangeString().c_str(),
escapedstr.c_str());
changes = true;
}
if (ranges.size() == 1 && ranges[0].size() == 1 && orgAlias != alias) {
Gui::cmdAppObjectArgs(sheet, "setAlias('%s', '%s')",
i->address().c_str(), alias.c_str());
Gui::cmdAppObjectArgs(sheet,
"setAlias('%s', '%s')",
i->address().c_str(),
alias.c_str());
changes = true;
}
}
@@ -276,8 +317,9 @@ void PropertiesDialog::apply()
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
else
else {
Gui::Command::abortCommand();
}
}
}

View File

@@ -23,37 +23,42 @@
#ifndef PROPERTIESDIALOG_H
#define PROPERTIESDIALOG_H
#include <QDialog>
#include <Mod/Spreadsheet/App/Sheet.h>
#include <QDialog>
namespace Ui {
namespace Ui
{
class PropertiesDialog;
}
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class PropertiesDialog : public QDialog
class PropertiesDialog: public QDialog
{
Q_OBJECT
public:
explicit PropertiesDialog(Spreadsheet::Sheet *_sheet, const std::vector<App::Range> & _ranges, QWidget *parent = nullptr);
explicit PropertiesDialog(Spreadsheet::Sheet* _sheet,
const std::vector<App::Range>& _ranges,
QWidget* parent = nullptr);
~PropertiesDialog() override;
void apply();
void selectAlias();
private Q_SLOTS:
void foregroundColorChanged(const QColor &color);
void backgroundColorChanged(const QColor &color);
void foregroundColorChanged(const QColor& color);
void backgroundColorChanged(const QColor& color);
void alignmentChanged();
void styleChanged();
void displayUnitChanged(const QString &text);
void aliasChanged(const QString &text);
void displayUnitChanged(const QString& text);
void aliasChanged(const QString& text);
private:
Spreadsheet::Sheet * sheet;
Spreadsheet::Sheet* sheet;
std::vector<App::Range> ranges;
Ui::PropertiesDialog *ui;
Ui::PropertiesDialog* ui;
App::Color foregroundColor;
App::Color backgroundColor;
int alignment;
@@ -72,6 +77,6 @@ private:
bool aliasOk;
};
}
}// namespace SpreadsheetGui
#endif // PROPERTIESDIALOG_H
#endif// PROPERTIESDIALOG_H

View File

@@ -43,14 +43,16 @@ using namespace Spreadsheet;
using namespace App;
namespace sp = std::placeholders;
SheetModel::SheetModel(Sheet* _sheet, QObject* parent) : QAbstractTableModel(parent), sheet(_sheet)
SheetModel::SheetModel(Sheet* _sheet, QObject* parent)
: QAbstractTableModel(parent)
, sheet(_sheet)
{
//NOLINTBEGIN
// NOLINTBEGIN
cellUpdatedConnection =
sheet->cellUpdated.connect(std::bind(&SheetModel::cellUpdated, this, sp::_1));
rangeUpdatedConnection =
sheet->rangeUpdated.connect(std::bind(&SheetModel::rangeUpdated, this, sp::_1));
//NOLINTEND
// NOLINTEND
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Spreadsheet");
@@ -108,10 +110,11 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
int col = index.column();
const Cell* cell = sheet->getCell(CellAddress(row, col));
if (!cell)
if (!cell) {
cell = emptyCell;
}
//#define DEBUG_DEPS
// #define DEBUG_DEPS
#ifdef DEBUG_DEPS
if (role == Qt::ToolTipRole) {
QString v;
@@ -123,15 +126,17 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (deps.size() > 0) {
v += QString::fromUtf8("Depends on:");
for (std::set<std::string>::const_iterator i = deps.begin(); i != deps.end(); ++i)
for (std::set<std::string>::const_iterator i = deps.begin(); i != deps.end(); ++i) {
v += QString::fromUtf8("\n\t") + Tools::fromStdString(*i);
}
v += QString::fromUtf8("\n");
}
if (provides.size() > 0) {
v += QString::fromUtf8("Used by:");
for (std::set<std::string>::const_iterator i = provides.begin(); i != provides.end();
++i)
++i) {
v += QString::fromUtf8("\n\t") + Tools::fromStdString(*i);
}
v += QString::fromUtf8("\n");
}
return QVariant(v);
@@ -139,8 +144,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
#else
if (!cell->hasException() && role == Qt::ToolTipRole) {
std::string alias;
if (cell->getAlias(alias))
if (cell->getAlias(alias)) {
return QVariant(Base::Tools::fromStdString(alias));
}
}
#endif
@@ -156,8 +162,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
QString::fromUtf8("#ERR: %1").arg(Tools::fromStdString(cell->getException())));
#else
std::string str;
if (cell->getStringContent(str))
if (cell->getStringContent(str)) {
return QVariant::fromValue(QString::fromUtf8(str.c_str()));
}
return QVariant::fromValue(QString::fromUtf8("#ERR"));
#endif
}
@@ -174,8 +181,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (role == Qt::EditRole || role == Qt::StatusTipRole) {
std::string str;
if (cell->getStringContent(str))
if (cell->getStringContent(str)) {
return QVariant(QString::fromUtf8(str.c_str()));
}
return {};
}
@@ -186,9 +194,10 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (role == Qt::BackgroundRole) {
Color color;
if (cell->getBackground(color))
if (cell->getBackground(color)) {
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
}
else {
std::string alias;
if (cell->getAlias(alias)) {
@@ -203,30 +212,39 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
int alignment;
cell->getAlignment(alignment);
if (alignment & Cell::ALIGNMENT_LEFT)
if (alignment & Cell::ALIGNMENT_LEFT) {
qtAlignment |= Qt::AlignLeft;
if (alignment & Cell::ALIGNMENT_HCENTER)
}
if (alignment & Cell::ALIGNMENT_HCENTER) {
qtAlignment |= Qt::AlignHCenter;
if (alignment & Cell::ALIGNMENT_RIGHT)
}
if (alignment & Cell::ALIGNMENT_RIGHT) {
qtAlignment |= Qt::AlignRight;
if (alignment & Cell::ALIGNMENT_TOP)
}
if (alignment & Cell::ALIGNMENT_TOP) {
qtAlignment |= Qt::AlignTop;
if (alignment & Cell::ALIGNMENT_VCENTER)
}
if (alignment & Cell::ALIGNMENT_VCENTER) {
qtAlignment |= Qt::AlignVCenter;
if (alignment & Cell::ALIGNMENT_BOTTOM)
}
if (alignment & Cell::ALIGNMENT_BOTTOM) {
qtAlignment |= Qt::AlignBottom;
}
std::set<std::string> style;
if (role == Qt::FontRole && cell->getStyle(style)) {
QFont f;
for (const auto& i : style) {
if (i == "bold")
if (i == "bold") {
f.setBold(true);
else if (i == "italic")
}
else if (i == "italic") {
f.setItalic(true);
else if (i == "underline")
}
else if (i == "underline") {
f.setUnderline(true);
}
}
return QVariant::fromValue(f);
@@ -238,7 +256,8 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (!prop || dirty) {
switch (role) {
case Qt::ForegroundRole: {
return QColor(0, 0,
return QColor(0,
0,
255.0);// TODO: Remove this hardcoded color, replace with preference
}
case Qt::TextAlignmentRole: {
@@ -275,11 +294,13 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
if (cell->getForeground(color)) {
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else
}
else {
return QVariant(QColor(textFgColor));
}
}
case Qt::DisplayRole: {
QString v = QString::fromUtf8(stringProp->getValue());
@@ -308,14 +329,17 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
if (cell->getForeground(color)) {
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
}
else {
if (floatProp->getValue() < 0)
if (floatProp->getValue() < 0) {
return QVariant::fromValue(QColor(negativeFgColor));
else
}
else {
return QVariant::fromValue(QColor(positiveFgColor));
}
}
}
case Qt::TextAlignmentRole: {
@@ -338,9 +362,11 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
if (cell->getDisplayUnit(displayUnit)) {
if (computedUnit.isEmpty() || computedUnit == displayUnit.unit) {
QString number =
QLocale().toString(floatProp->getValue() / displayUnit.scaler, 'f',
QLocale().toString(floatProp->getValue() / displayUnit.scaler,
'f',
Base::UnitsApi::getDecimals());
//QString number = QString::number(floatProp->getValue() / displayUnit.scaler);
// QString number = QString::number(floatProp->getValue() /
// displayUnit.scaler);
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
else {
@@ -366,8 +392,9 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
double d;
long l;
bool isInteger = false;
if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId()))
if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId())) {
d = static_cast<const App::PropertyFloat*>(prop)->getValue();
}
else {
isInteger = true;
l = static_cast<const App::PropertyInteger*>(prop)->getValue();
@@ -378,14 +405,17 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
if (cell->getForeground(color)) {
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
}
else {
if (d < 0)
if (d < 0) {
return QVariant::fromValue(QColor(negativeFgColor));
else
}
else {
return QVariant::fromValue(QColor(positiveFgColor));
}
}
}
case Qt::TextAlignmentRole: {
@@ -405,17 +435,19 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
// Display locale specific decimal separator (#0003875,#0003876)
if (cell->getDisplayUnit(displayUnit)) {
QString number = QLocale().toString(d / displayUnit.scaler, 'f',
QString number = QLocale().toString(d / displayUnit.scaler,
'f',
Base::UnitsApi::getDecimals());
//QString number = QString::number(d / displayUnit.scaler);
// QString number = QString::number(d / displayUnit.scaler);
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
else if (!isInteger) {
v = QLocale::system().toString(d, 'f', Base::UnitsApi::getDecimals());
//v = QString::number(d);
// v = QString::number(d);
}
else
else {
v = QString::number(l);
}
return formatCellDisplay(v, cell);
}
default:
@@ -429,11 +461,13 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
case Qt::ForegroundRole: {
Color color;
if (cell->getForeground(color))
if (cell->getForeground(color)) {
return QVariant::fromValue(
QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a));
else
}
else {
return QVariant(QColor(textFgColor));
}
}
case Qt::TextAlignmentRole: {
if (alignment & Cell::ALIGNMENT_HIMPLIED) {
@@ -478,12 +512,14 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
QVariant SheetModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::SizeHintRole) {
if (orientation == Qt::Horizontal)
if (orientation == Qt::Horizontal) {
return QVariant(
QSize(sheet->getColumnWidth(section), PropertyRowHeights::defaultHeight));
else
}
else {
return QVariant(
QSize(PropertyColumnWidths::defaultHeaderWidth, sheet->getRowHeight(section)));
}
}
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
@@ -537,12 +573,16 @@ bool SheetModel::setData(const QModelIndex& index, const QVariant& value, int ro
if (cell) {
std::string oldContent;
cell->getStringContent(oldContent);
if (str == QString::fromStdString(oldContent))
if (str == QString::fromStdString(oldContent)) {
return true;
}
}
QMetaObject::invokeMethod(this, "setCellData", Qt::QueuedConnection,
Q_ARG(QModelIndex, index), Q_ARG(QString, str));
QMetaObject::invokeMethod(this,
"setCellData",
Qt::QueuedConnection,
Q_ARG(QModelIndex, index),
Q_ARG(QString, str));
}
return true;
}

View File

@@ -28,43 +28,45 @@
#include <App/Range.h>
namespace Spreadsheet {
namespace Spreadsheet
{
class Sheet;
}
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class SheetModel : public QAbstractTableModel
class SheetModel: public QAbstractTableModel
{
Q_OBJECT
public:
explicit SheetModel(Spreadsheet::Sheet * _sheet, QObject *parent = nullptr);
explicit SheetModel(Spreadsheet::Sheet* _sheet, QObject* parent = nullptr);
~SheetModel() override;
explicit SheetModel(QObject *parent);
int rowCount(const QModelIndex &parent = QModelIndex()) const override ;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
explicit SheetModel(QObject* parent);
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role) override;
Qt::ItemFlags flags(const QModelIndex&) const override;
private Q_SLOTS:
void setCellData(QModelIndex index, QString str);
private:
void cellUpdated(App::CellAddress address);
void rangeUpdated(const App::Range &range);
void rangeUpdated(const App::Range& range);
boost::signals2::scoped_connection cellUpdatedConnection;
boost::signals2::scoped_connection rangeUpdatedConnection;
Spreadsheet::Sheet * sheet;
Spreadsheet::Sheet* sheet;
QColor aliasBgColor;
QColor textFgColor;
QColor positiveFgColor;
QColor negativeFgColor;
};
}
}// namespace SpreadsheetGui
#endif // SHEETMODEL_H
#endif// SHEETMODEL_H

File diff suppressed because it is too large Load Diff

View File

@@ -30,34 +30,39 @@
#include <Mod/Spreadsheet/App/Sheet.h>
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class SheetViewHeader : public QHeaderView {
class SheetViewHeader: public QHeaderView
{
Q_OBJECT
public:
SheetViewHeader(QTableView *owner, Qt::Orientation o)
: QHeaderView(o),owner(owner)
SheetViewHeader(QTableView* owner, Qt::Orientation o)
: QHeaderView(o)
, owner(owner)
{
setSectionsClickable(true);
}
Q_SIGNALS:
void resizeFinished();
protected:
void mouseReleaseEvent(QMouseEvent * event) override;
bool viewportEvent(QEvent *e) override;
void mouseReleaseEvent(QMouseEvent* event) override;
bool viewportEvent(QEvent* e) override;
private:
QTableView *owner;
QTableView* owner;
};
class SheetTableView : public QTableView
class SheetTableView: public QTableView
{
Q_OBJECT
public:
explicit SheetTableView(QWidget *parent = nullptr);
explicit SheetTableView(QWidget* parent = nullptr);
~SheetTableView() override;
void edit(const QModelIndex &index);
void setSheet(Spreadsheet::Sheet *_sheet);
void edit(const QModelIndex& index);
void setSheet(Spreadsheet::Sheet* _sheet);
std::vector<App::Range> selectedRanges() const;
QModelIndexList selectedIndexesRaw() const;
QString toHtml() const;
@@ -69,11 +74,13 @@ public Q_SLOTS:
void copySelection();
void cutSelection();
void pasteClipboard();
void finishEditWithMove(int keyPressed, Qt::KeyboardModifiers modifiers, bool handleTabMotion = false);
void finishEditWithMove(int keyPressed,
Qt::KeyboardModifiers modifiers,
bool handleTabMotion = false);
void ModifyBlockSelection(int targetRow, int targetColumn);
protected Q_SLOTS:
void commitData(QWidget *editor) override;
void commitData(QWidget* editor) override;
void updateCellSpan();
void insertRows();
void insertRowsAfter();
@@ -87,32 +94,33 @@ protected Q_SLOTS:
void onConfSetup();
protected:
bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) override;
bool event(QEvent *event) override;
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint) override;
bool edit(const QModelIndex& index, EditTrigger trigger, QEvent* event) override;
bool event(QEvent* event) override;
void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint) override;
void mousePressEvent(QMouseEvent* event) override;
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
void selectionChanged(const QItemSelection& selected,
const QItemSelection& deselected) override;
void contextMenuEvent (QContextMenuEvent * e) override;
void contextMenuEvent(QContextMenuEvent* e) override;
void _copySelection(const std::vector<App::Range> &ranges, bool copy);
void _copySelection(const std::vector<App::Range>& ranges, bool copy);
QModelIndex currentEditIndex;
Spreadsheet::Sheet * sheet;
Spreadsheet::Sheet* sheet;
int tabCounter;
QMenu *contextMenu;
QMenu* contextMenu;
QAction *actionProperties;
QAction *actionRecompute;
QAction *actionConf;
QAction *actionMerge;
QAction *actionSplit;
QAction *actionCopy;
QAction *actionPaste;
QAction *actionCut;
QAction *actionDel;
QAction *actionBind;
QAction* actionProperties;
QAction* actionRecompute;
QAction* actionConf;
QAction* actionMerge;
QAction* actionSplit;
QAction* actionCopy;
QAction* actionPaste;
QAction* actionCut;
QAction* actionDel;
QAction* actionBind;
QTimer timer;
@@ -120,6 +128,6 @@ protected:
std::set<App::CellAddress> spanChanges;
};
}
}// namespace SpreadsheetGui
#endif // SHEETTABLEVIEW_H
#endif// SHEETTABLEVIEW_H

View File

@@ -24,65 +24,67 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QAction>
# include <QApplication>
# include <QClipboard>
# include <QKeyEvent>
# include <QMessageBox>
# include <QMenu>
# include <QMimeData>
#include <QAction>
#include <QApplication>
#include <QClipboard>
#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
#include <QMimeData>
#endif
#include "SheetTableViewAccessibleInterface.h"
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
SheetTableViewAccessibleInterface::SheetTableViewAccessibleInterface(
SheetTableViewAccessibleInterface::SheetTableViewAccessibleInterface(
SpreadsheetGui::SheetTableView* view)
: QAccessibleWidget(view)
{
}
{}
QString SheetTableViewAccessibleInterface::text(QAccessible::Text txt) const
{
if (txt == QAccessible::Help)
return QString::fromLatin1("Implement me");
return QAccessibleWidget::text(txt);
}
QAccessibleInterface* SheetTableViewAccessibleInterface::childAt(int x, int y) const
{
Q_UNUSED(x)
Q_UNUSED(y)
return (QAccessibleInterface*)this;
}
int SheetTableViewAccessibleInterface::indexOfChild(const QAccessibleInterface*) const
{
return 0;
}
int SheetTableViewAccessibleInterface::childCount() const
{
return 0;
}
QAccessibleInterface* SheetTableViewAccessibleInterface::focusChild() const
{
return (QAccessibleInterface*)this;
}
QAccessibleInterface* SheetTableViewAccessibleInterface::child(int index) const
{
Q_UNUSED(index)
return (QAccessibleInterface*)this;
}
QAccessibleInterface* SheetTableViewAccessibleInterface::ifactory(const QString& key, QObject* obj)
{
if (key == QString::fromUtf8("SpreadsheetGui::SheetTableView"))
return new SheetTableViewAccessibleInterface(
static_cast<SpreadsheetGui::SheetTableView*>(obj));
return nullptr;
QString SheetTableViewAccessibleInterface::text(QAccessible::Text txt) const
{
if (txt == QAccessible::Help) {
return QString::fromLatin1("Implement me");
}
return QAccessibleWidget::text(txt);
}
QAccessibleInterface* SheetTableViewAccessibleInterface::childAt(int x, int y) const
{
Q_UNUSED(x)
Q_UNUSED(y)
return (QAccessibleInterface*)this;
}
int SheetTableViewAccessibleInterface::indexOfChild(const QAccessibleInterface*) const
{
return 0;
}
int SheetTableViewAccessibleInterface::childCount() const
{
return 0;
}
QAccessibleInterface* SheetTableViewAccessibleInterface::focusChild() const
{
return (QAccessibleInterface*)this;
}
QAccessibleInterface* SheetTableViewAccessibleInterface::child(int index) const
{
Q_UNUSED(index)
return (QAccessibleInterface*)this;
}
QAccessibleInterface* SheetTableViewAccessibleInterface::ifactory(const QString& key, QObject* obj)
{
if (key == QString::fromUtf8("SpreadsheetGui::SheetTableView")) {
return new SheetTableViewAccessibleInterface(
static_cast<SpreadsheetGui::SheetTableView*>(obj));
}
return nullptr;
}
}// namespace SpreadsheetGui

View File

@@ -27,32 +27,33 @@
#include <Mod/Spreadsheet/Gui/SheetTableView.h>
#include <QtWidgets/qaccessiblewidget.h>
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
// Currently SheetTableViewAccessibleInterface below deactivates the
// built-in QAccessibleTable interface, and all the accessibility
// features.
//
// For a proper implementation, start by extending that
// and ensure you're not queue-ing empty cells, or counting empty cells
//
// Otherwise it will hang - https://github.com/FreeCAD/FreeCAD/issues/8265
// Currently SheetTableViewAccessibleInterface below deactivates the
// built-in QAccessibleTable interface, and all the accessibility
// features.
//
// For a proper implementation, start by extending that
// and ensure you're not queue-ing empty cells, or counting empty cells
//
// Otherwise it will hang - https://github.com/FreeCAD/FreeCAD/issues/8265
class SheetTableViewAccessibleInterface : public QAccessibleWidget
{
public:
explicit SheetTableViewAccessibleInterface(SpreadsheetGui::SheetTableView* view);
class SheetTableViewAccessibleInterface: public QAccessibleWidget
{
public:
explicit SheetTableViewAccessibleInterface(SpreadsheetGui::SheetTableView* view);
QString text(QAccessible::Text txt) const override;
QString text(QAccessible::Text txt) const override;
QAccessibleInterface* childAt(int x, int y) const override;
int indexOfChild(const QAccessibleInterface*) const override;
int childCount() const override;
QAccessibleInterface* focusChild() const override;
QAccessibleInterface* child(int index) const override;
QAccessibleInterface* childAt(int x, int y) const override;
int indexOfChild(const QAccessibleInterface*) const override;
int childCount() const override;
QAccessibleInterface* focusChild() const override;
QAccessibleInterface* child(int index) const override;
static QAccessibleInterface* ifactory(const QString& key, QObject* obj);
};
}
static QAccessibleInterface* ifactory(const QString& key, QObject* obj);
};
}// namespace SpreadsheetGui
#endif // SHEETTABLEVIEW_INTERFACE_H
#endif// SHEETTABLEVIEW_INTERFACE_H

View File

@@ -25,16 +25,16 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QLineEdit>
# include <QPainter>
#include <QLineEdit>
#include <QPainter>
#endif
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Mod/Spreadsheet/App/Sheet.h>
#include "SpreadsheetDelegate.h"
#include "LineEdit.h"
#include "SpreadsheetDelegate.h"
FC_LOG_LEVEL_INIT("Spreadsheet", true, true)
@@ -42,43 +42,45 @@ FC_LOG_LEVEL_INIT("Spreadsheet", true, true)
using namespace Spreadsheet;
using namespace SpreadsheetGui;
SpreadsheetDelegate::SpreadsheetDelegate(Spreadsheet::Sheet * _sheet, QWidget *parent)
SpreadsheetDelegate::SpreadsheetDelegate(Spreadsheet::Sheet* _sheet, QWidget* parent)
: QStyledItemDelegate(parent)
, sheet(_sheet)
{
}
{}
QWidget *SpreadsheetDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex &index) const
QWidget* SpreadsheetDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem&,
const QModelIndex& index) const
{
App::CellAddress addr(index.row(),index.column());
App::Range range(addr,addr);
if(sheet && sheet->getCellBinding(range)) {
App::CellAddress addr(index.row(), index.column());
App::Range range(addr, addr);
if (sheet && sheet->getCellBinding(range)) {
FC_ERR("Bound cell " << addr.toString() << " cannot be edited");
return nullptr;
}
SpreadsheetGui::LineEdit *editor = new SpreadsheetGui::LineEdit(parent);
SpreadsheetGui::LineEdit* editor = new SpreadsheetGui::LineEdit(parent);
editor->setDocumentObject(sheet);
connect(editor, &SpreadsheetGui::LineEdit::finishedWithKey, this, &SpreadsheetDelegate::onEditorFinishedWithKey);
connect(editor,
&SpreadsheetGui::LineEdit::finishedWithKey,
this,
&SpreadsheetDelegate::onEditorFinishedWithKey);
return editor;
}
void SpreadsheetDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
void SpreadsheetDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
QLineEdit* edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
edit->setText(index.model()->data(index, Qt::EditRole).toString());
return;
}
}
void SpreadsheetDelegate::setModelData(QWidget *editor,
QAbstractItemModel *model, const QModelIndex &index) const
void SpreadsheetDelegate::setModelData(QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index) const
{
QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
QLineEdit* edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
model->setData(index, edit->text());
return;
@@ -90,49 +92,59 @@ void SpreadsheetDelegate::onEditorFinishedWithKey(int key, Qt::KeyboardModifiers
Q_EMIT finishedWithKey(key, modifiers);
}
QSize SpreadsheetDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
QSize SpreadsheetDelegate::sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
return {};
}
static inline void drawBorder(QPainter *painter, const QStyleOptionViewItem &option,
unsigned flags, QColor color, Qt::PenStyle style)
static inline void drawBorder(QPainter* painter,
const QStyleOptionViewItem& option,
unsigned flags,
QColor color,
Qt::PenStyle style)
{
if(!flags)
if (!flags) {
return;
}
QPen pen(color);
pen.setWidth(2);
pen.setStyle(style);
painter->setPen(pen);
QRect rect = option.rect.adjusted(1,1,0,0);
if(flags == Sheet::BorderAll) {
painter->drawRect(rect.adjusted(0,0,-1,-1));
QRect rect = option.rect.adjusted(1, 1, 0, 0);
if (flags == Sheet::BorderAll) {
painter->drawRect(rect.adjusted(0, 0, -1, -1));
return;
}
if(flags & Sheet::BorderLeft)
if (flags & Sheet::BorderLeft) {
painter->drawLine(rect.topLeft(), rect.bottomLeft());
if(flags & Sheet::BorderTop)
}
if (flags & Sheet::BorderTop) {
painter->drawLine(rect.topLeft(), rect.topRight());
if(flags & Sheet::BorderRight)
}
if (flags & Sheet::BorderRight) {
painter->drawLine(rect.topRight(), rect.bottomRight());
if(flags & Sheet::BorderBottom)
}
if (flags & Sheet::BorderBottom) {
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
}
}
void SpreadsheetDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index ) const
void SpreadsheetDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QStyledItemDelegate::paint(painter, option, index);
if(!sheet)
if (!sheet) {
return;
}
App::CellAddress addr(index.row(), index.column());
drawBorder(painter, option, sheet->getCellBindingBorder(addr), Qt::blue, Qt::SolidLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr,true), Qt::green, Qt::DashLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr,false), Qt::red, Qt::DashLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr, true), Qt::green, Qt::DashLine);
drawBorder(painter, option, sheet->getCopyOrCutBorder(addr, false), Qt::red, Qt::DashLine);
}
#include "moc_SpreadsheetDelegate.cpp"

View File

@@ -27,35 +27,42 @@
#include <QStyledItemDelegate>
namespace Spreadsheet {
namespace Spreadsheet
{
class Sheet;
}
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
class SpreadsheetDelegate : public QStyledItemDelegate
class SpreadsheetDelegate: public QStyledItemDelegate
{
Q_OBJECT
public:
explicit SpreadsheetDelegate(Spreadsheet::Sheet * sheet, QWidget *parent = nullptr);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const override;
explicit SpreadsheetDelegate(Spreadsheet::Sheet* sheet, QWidget* parent = nullptr);
QWidget* createEditor(QWidget* parent,
const QStyleOptionViewItem&,
const QModelIndex& index) const override;
void setEditorData(QWidget* editor, const QModelIndex& index) const override;
void setModelData(QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const override;
Q_SIGNALS:
void finishedWithKey(int key, Qt::KeyboardModifiers modifiers);
private:
void onEditorFinishedWithKey(int key, Qt::KeyboardModifiers modifiers);
private:
Spreadsheet::Sheet * sheet;
Spreadsheet::Sheet* sheet;
};
}
}// namespace SpreadsheetGui
#endif // SPREADSHEETDELEGATE_H
#endif// SPREADSHEETDELEGATE_H

View File

@@ -23,12 +23,12 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cmath>
# include <QPalette>
# include <QPrinter>
# include <QPrintDialog>
# include <QPrintPreviewDialog>
# include <QTextDocument>
#include <QPalette>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include <QPrinter>
#include <QTextDocument>
#include <cmath>
#endif
#include <App/DocumentObject.h>
@@ -44,11 +44,11 @@
#include <Mod/Spreadsheet/App/Sheet.h>
#include <Mod/Spreadsheet/App/SheetPy.h>
#include "SpreadsheetView.h"
#include "ui_Sheet.h"
#include "LineEdit.h"
#include "qtcolorpicker.h"
#include "SpreadsheetDelegate.h"
#include "SpreadsheetView.h"
#include "qtcolorpicker.h"
#include "ui_Sheet.h"
using namespace SpreadsheetGui;
@@ -61,7 +61,7 @@ namespace sp = std::placeholders;
TYPESYSTEM_SOURCE_ABSTRACT(SpreadsheetGui::SheetView, Gui::MDIView)
SheetView::SheetView(Gui::Document *pcDocument, App::DocumentObject *docObj, QWidget *parent)
SheetView::SheetView(Gui::Document* pcDocument, App::DocumentObject* docObj, QWidget* parent)
: MDIView(pcDocument, parent)
, sheet(static_cast<Sheet*>(docObj))
{
@@ -70,7 +70,7 @@ SheetView::SheetView(Gui::Document *pcDocument, App::DocumentObject *docObj, QWi
model = new SheetModel(static_cast<Sheet*>(docObj));
ui = new Ui::Sheet();
QWidget * w = new QWidget(this);
QWidget* w = new QWidget(this);
ui->setupUi(w);
setCentralWidget(w);
@@ -80,43 +80,66 @@ SheetView::SheetView(Gui::Document *pcDocument, App::DocumentObject *docObj, QWi
ui->cells->setSheet(sheet);
// Connect signals
connect(ui->cells->selectionModel(), &QItemSelectionModel::currentChanged,
this, &SheetView::currentChanged);
connect(ui->cells->selectionModel(),
&QItemSelectionModel::currentChanged,
this,
&SheetView::currentChanged);
connect(dynamic_cast<SheetViewHeader*>(ui->cells->horizontalHeader()), &SheetViewHeader::resizeFinished,
this, &SheetView::columnResizeFinished);
connect(ui->cells->horizontalHeader(), &QHeaderView::sectionResized,
this, &SheetView::columnResized);
connect(dynamic_cast<SheetViewHeader*>(ui->cells->horizontalHeader()),
&SheetViewHeader::resizeFinished,
this,
&SheetView::columnResizeFinished);
connect(ui->cells->horizontalHeader(),
&QHeaderView::sectionResized,
this,
&SheetView::columnResized);
connect(dynamic_cast<SheetViewHeader*>(ui->cells->verticalHeader()), &SheetViewHeader::resizeFinished,
this, &SheetView::rowResizeFinished);
connect(ui->cells->verticalHeader(), &QHeaderView::sectionResized,
this, &SheetView::rowResized);
connect(dynamic_cast<SheetViewHeader*>(ui->cells->verticalHeader()),
&SheetViewHeader::resizeFinished,
this,
&SheetView::rowResizeFinished);
connect(ui->cells->verticalHeader(),
&QHeaderView::sectionResized,
this,
&SheetView::rowResized);
connect(delegate, &SpreadsheetDelegate::finishedWithKey, this, &SheetView::editingFinishedWithKey);
connect(ui->cellContent, &ExpressionLineEdit::returnPressed, this, [this]() {confirmContentChanged(ui->cellContent->text()); });
connect(ui->cellAlias, &ExpressionLineEdit::editingFinished, this, [this]() {confirmAliasChanged(ui->cellAlias->text()); });
connect(delegate,
&SpreadsheetDelegate::finishedWithKey,
this,
&SheetView::editingFinishedWithKey);
connect(ui->cellContent, &ExpressionLineEdit::returnPressed, this, [this]() {
confirmContentChanged(ui->cellContent->text());
});
connect(ui->cellAlias, &ExpressionLineEdit::editingFinished, this, [this]() {
confirmAliasChanged(ui->cellAlias->text());
});
connect(ui->cellAlias, &LineEdit::textEdited, this, &SheetView::aliasChanged);
//NOLINTBEGIN
columnWidthChangedConnection = sheet->columnWidthChanged.connect(std::bind(&SheetView::resizeColumn, this, sp::_1, sp::_2));
rowHeightChangedConnection = sheet->rowHeightChanged.connect(std::bind(&SheetView::resizeRow, this, sp::_1, sp::_2));
//NOLINTEND
// NOLINTBEGIN
columnWidthChangedConnection = sheet->columnWidthChanged.connect(
std::bind(&SheetView::resizeColumn, this, sp::_1, sp::_2));
rowHeightChangedConnection =
sheet->rowHeightChanged.connect(std::bind(&SheetView::resizeRow, this, sp::_1, sp::_2));
// NOLINTEND
connect( model, &QAbstractItemModel::dataChanged, this, &SheetView::modelUpdated);
connect(model, &QAbstractItemModel::dataChanged, this, &SheetView::modelUpdated);
QPalette palette = ui->cells->palette();
palette.setColor(QPalette::Base, QColor(255, 255, 255));
palette.setColor(QPalette::Text, QColor(0, 0, 0));
ui->cells->setPalette(palette);
QList<QtColorPicker*> bgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(QString::fromLatin1("Spreadsheet_BackgroundColor"));
if (!bgList.empty())
QList<QtColorPicker*> bgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(
QString::fromLatin1("Spreadsheet_BackgroundColor"));
if (!bgList.empty()) {
bgList[0]->setCurrentColor(palette.color(QPalette::Base));
}
QList<QtColorPicker*> fgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(QString::fromLatin1("Spreadsheet_ForegroundColor"));
if (!fgList.empty())
QList<QtColorPicker*> fgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(
QString::fromLatin1("Spreadsheet_ForegroundColor"));
if (!fgList.empty()) {
fgList[0]->setCurrentColor(palette.color(QPalette::Text));
}
// Set document object to create auto completer
ui->cellContent->setDocumentObject(sheet);
@@ -131,31 +154,33 @@ SheetView::~SheetView()
delete delegate;
}
bool SheetView::onMsg(const char *pMsg, const char **)
bool SheetView::onMsg(const char* pMsg, const char**)
{
if(strcmp("Undo",pMsg) == 0 ) {
if (strcmp("Undo", pMsg) == 0) {
getGuiDocument()->undo(1);
App::Document* doc = getAppDocument();
if (doc)
if (doc) {
doc->recompute();
}
return true;
}
else if(strcmp("Redo",pMsg) == 0 ) {
else if (strcmp("Redo", pMsg) == 0) {
getGuiDocument()->redo(1);
App::Document* doc = getAppDocument();
if (doc)
if (doc) {
doc->recompute();
}
return true;
}
else if (strcmp("Save",pMsg) == 0) {
else if (strcmp("Save", pMsg) == 0) {
getGuiDocument()->save();
return true;
}
else if (strcmp("SaveAs",pMsg) == 0) {
else if (strcmp("SaveAs", pMsg) == 0) {
getGuiDocument()->saveAs();
return true;
}
else if(strcmp("Std_Delete",pMsg) == 0) {
else if (strcmp("Std_Delete", pMsg) == 0) {
std::vector<Range> ranges = selectedRanges();
if (sheet->hasCell(ranges)) {
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Clear cell(s)"));
@@ -168,48 +193,57 @@ bool SheetView::onMsg(const char *pMsg, const char **)
}
return true;
}
else if (strcmp("Cut",pMsg) == 0) {
else if (strcmp("Cut", pMsg) == 0) {
ui->cells->cutSelection();
return true;
}
else if (strcmp("Copy",pMsg) == 0) {
else if (strcmp("Copy", pMsg) == 0) {
ui->cells->copySelection();
return true;
}
else if (strcmp("Paste",pMsg) == 0) {
else if (strcmp("Paste", pMsg) == 0) {
ui->cells->pasteClipboard();
return true;
}
else
else {
return false;
}
}
bool SheetView::onHasMsg(const char *pMsg) const
bool SheetView::onHasMsg(const char* pMsg) const
{
if (strcmp("Undo",pMsg) == 0) {
if (strcmp("Undo", pMsg) == 0) {
App::Document* doc = getAppDocument();
return doc && doc->getAvailableUndos() > 0;
}
if (strcmp("Redo",pMsg) == 0) {
if (strcmp("Redo", pMsg) == 0) {
App::Document* doc = getAppDocument();
return doc && doc->getAvailableRedos() > 0;
}
if (strcmp("Save",pMsg) == 0)
if (strcmp("Save", pMsg) == 0) {
return true;
if (strcmp("SaveAs",pMsg) == 0)
}
if (strcmp("SaveAs", pMsg) == 0) {
return true;
if (strcmp("Cut",pMsg) == 0)
}
if (strcmp("Cut", pMsg) == 0) {
return true;
if (strcmp("Copy",pMsg) == 0)
}
if (strcmp("Copy", pMsg) == 0) {
return true;
if (strcmp("Paste",pMsg) == 0)
}
if (strcmp("Paste", pMsg) == 0) {
return true;
if (strcmp(pMsg, "Print") == 0)
}
if (strcmp(pMsg, "Print") == 0) {
return true;
if (strcmp(pMsg, "PrintPreview") == 0)
}
if (strcmp(pMsg, "PrintPreview") == 0) {
return true;
if (strcmp(pMsg, "PrintPdf") == 0)
}
if (strcmp(pMsg, "PrintPdf") == 0) {
return true;
}
return false;
}
@@ -233,8 +267,10 @@ void SheetView::printPreview()
QPrinter printer(QPrinter::ScreenResolution);
printer.setPageOrientation(QPageLayout::Landscape);
QPrintPreviewDialog dlg(&printer, this);
connect(&dlg, &QPrintPreviewDialog::paintRequested,
this, qOverload<QPrinter*>(&SheetView::print));
connect(&dlg,
&QPrintPreviewDialog::paintRequested,
this,
qOverload<QPrinter*>(&SheetView::print));
dlg.exec();
}
@@ -253,11 +289,15 @@ void SheetView::print(QPrinter* printer)
*/
void SheetView::printPdf()
{
QString filename = FileDialog::getSaveFileName(this, tr("Export PDF"), QString(),
QString::fromLatin1("%1 (*.pdf)").arg(tr("PDF file")));
QString filename =
FileDialog::getSaveFileName(this,
tr("Export PDF"),
QString(),
QString::fromLatin1("%1 (*.pdf)").arg(tr("PDF file")));
if (!filename.isEmpty()) {
QPrinter printer(QPrinter::ScreenResolution);
// setPdfVersion sets the printied PDF Version to comply with PDF/A-1b, more details under: https://www.kdab.com/creating-pdfa-documents-qt/
// setPdfVersion sets the printied PDF Version to comply with PDF/A-1b, more details under:
// https://www.kdab.com/creating-pdfa-documents-qt/
printer.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b);
printer.setPageOrientation(QPageLayout::Landscape);
printer.setOutputFormat(QPrinter::PdfFormat);
@@ -279,12 +319,14 @@ void SheetView::updateContentLine()
if (i.isValid()) {
std::string str;
if (const auto * cell = sheet->getCell(CellAddress(i.row(), i.column())))
if (const auto* cell = sheet->getCell(CellAddress(i.row(), i.column()))) {
(void)cell->getStringContent(str);
}
ui->cellContent->setText(QString::fromUtf8(str.c_str()));
ui->cellContent->setEnabled(true);
// Update completer model; for the time being, we do this by setting the document object of the input line.
// Update completer model; for the time being, we do this by setting the document object of
// the input line.
ui->cellContent->setDocumentObject(sheet);
}
}
@@ -295,46 +337,53 @@ void SheetView::updateAliasLine()
if (i.isValid()) {
std::string str;
if (const auto * cell = sheet->getCell(CellAddress(i.row(), i.column())))
if (const auto* cell = sheet->getCell(CellAddress(i.row(), i.column()))) {
(void)cell->getAlias(str);
}
ui->cellAlias->setText(QString::fromUtf8(str.c_str()));
ui->cellAlias->setEnabled(true);
// Update completer model; for the time being, we do this by setting the document object of the input line.
// Update completer model; for the time being, we do this by setting the document object of
// the input line.
ui->cellAlias->setDocumentObject(sheet);
}
}
void SheetView::columnResizeFinished()
{
if (newColumnSizes.empty())
if (newColumnSizes.empty()) {
return;
}
blockSignals(true);
for(auto &v : newColumnSizes)
sheet->setColumnWidth(v.first,v.second);
for (auto& v : newColumnSizes) {
sheet->setColumnWidth(v.first, v.second);
}
blockSignals(false);
newColumnSizes.clear();
}
void SheetView::rowResizeFinished()
{
if (newRowSizes.empty())
if (newRowSizes.empty()) {
return;
}
blockSignals(true);
for(auto &v : newRowSizes)
sheet->setRowHeight(v.first,v.second);
for (auto& v : newRowSizes) {
sheet->setRowHeight(v.first, v.second);
}
blockSignals(false);
newRowSizes.clear();
}
void SheetView::modelUpdated(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void SheetView::modelUpdated(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
const QModelIndex & current = ui->cells->currentIndex();
const QModelIndex& current = ui->cells->currentIndex();
if (current < topLeft || bottomRight < current)
if (current < topLeft || bottomRight < current) {
return;
}
updateContentLine();
updateAliasLine();
@@ -354,14 +403,16 @@ void SheetView::rowResized(int row, int oldSize, int newSize)
void SheetView::resizeColumn(int col, int newSize)
{
if (ui->cells->horizontalHeader()->sectionSize(col) != newSize)
if (ui->cells->horizontalHeader()->sectionSize(col) != newSize) {
ui->cells->setColumnWidth(col, newSize);
}
}
void SheetView::resizeRow(int col, int newSize)
{
if (ui->cells->verticalHeader()->sectionSize(col) != newSize)
if (ui->cells->verticalHeader()->sectionSize(col) != newSize) {
ui->cells->setRowHeight(col, newSize);
}
}
void SheetView::editingFinishedWithKey(int key, Qt::KeyboardModifiers modifiers)
@@ -385,17 +436,18 @@ void SheetView::confirmAliasChanged(const QString& text)
QModelIndex i = ui->cells->currentIndex();
if (const auto* cell = sheet->getNewCell(CellAddress(i.row(), i.column()))) {
if (!aliasOkay) {
//do not show error message if failure to set new alias is because it is already the same string
// do not show error message if failure to set new alias is because it is already the
// same string
std::string current_alias;
(void)cell->getAlias(current_alias);
if (text != QString::fromUtf8(current_alias.c_str())) {
Base::Console().Error("Unable to set alias: %s\n", Base::Tools::toStdString(text).c_str());
Base::Console().Error("Unable to set alias: %s\n",
Base::Tools::toStdString(text).c_str());
}
}
else {
std::string address = CellAddress(i.row(), i.column()).toString();
Gui::cmdAppObjectArgs(sheet, "setAlias('%s', '%s')",
address, text.toStdString());
Gui::cmdAppObjectArgs(sheet, "setAlias('%s', '%s')", address, text.toStdString());
Gui::cmdAppDocument(sheet->getDocument(), "recompute()");
ui->cells->setFocus();
}
@@ -417,13 +469,16 @@ void SheetView::aliasChanged(const QString& text)
bool aliasOk = true;
static auto originalStylesheet = ui->cellAlias->styleSheet();
QString warningColor;
if (qApp->styleSheet().contains(QLatin1String("dark"), Qt::CaseInsensitive))
warningColor = QLatin1String("rgb(255,90,90)"); // Light red for dark mode
else
warningColor = QLatin1String("rgb(200,0,0)"); // Dark red for light mode
if (qApp->styleSheet().contains(QLatin1String("dark"), Qt::CaseInsensitive)) {
warningColor = QLatin1String("rgb(255,90,90)");// Light red for dark mode
}
else {
warningColor = QLatin1String("rgb(200,0,0)");// Dark red for light mode
}
if (!text.isEmpty() && !sheet->isValidAlias(Base::Tools::toStdString(text)))
if (!text.isEmpty() && !sheet->isValidAlias(Base::Tools::toStdString(text))) {
aliasOk = false;
}
if (!aliasOk) {
// change tooltip and make text color red
@@ -433,12 +488,13 @@ void SheetView::aliasChanged(const QString& text)
else {
// go back to normal
ui->cellAlias->setToolTip(
QObject::tr("Refer to cell by alias, for example\nSpreadsheet.my_alias_name instead of Spreadsheet.B1"));
QObject::tr("Refer to cell by alias, for example\nSpreadsheet.my_alias_name instead of "
"Spreadsheet.B1"));
ui->cellAlias->setStyleSheet(originalStylesheet);
}
}
void SheetView::currentChanged ( const QModelIndex & current, const QModelIndex & previous )
void SheetView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
Q_UNUSED(current);
Q_UNUSED(previous);
@@ -446,7 +502,7 @@ void SheetView::currentChanged ( const QModelIndex & current, const QModelIndex
updateAliasLine();
}
void SheetView::updateCell(const App::Property *prop)
void SheetView::updateCell(const App::Property* prop)
{
try {
if (prop == &sheet->Label) {
@@ -455,10 +511,11 @@ void SheetView::updateCell(const App::Property *prop)
}
CellAddress address;
if(!sheet->getCellAddress(prop, address))
if (!sheet->getCellAddress(prop, address)) {
return;
}
if (currentIndex().row() == address.row() && currentIndex().column() == address.col() ){
if (currentIndex().row() == address.row() && currentIndex().column() == address.col()) {
updateContentLine();
updateAliasLine();
}
@@ -484,14 +541,20 @@ QModelIndexList SheetView::selectedIndexesRaw() const
return ui->cells->selectedIndexesRaw();
}
void SpreadsheetGui::SheetView::select(App::CellAddress cell, QItemSelectionModel::SelectionFlags flags)
void SpreadsheetGui::SheetView::select(App::CellAddress cell,
QItemSelectionModel::SelectionFlags flags)
{
ui->cells->selectionModel()->select(model->index(cell.row(), cell.col()), flags);
}
void SpreadsheetGui::SheetView::select(App::CellAddress topLeft, App::CellAddress bottomRight, QItemSelectionModel::SelectionFlags flags)
void SpreadsheetGui::SheetView::select(App::CellAddress topLeft,
App::CellAddress bottomRight,
QItemSelectionModel::SelectionFlags flags)
{
ui->cells->selectionModel()->select(QItemSelection(model->index(topLeft.row(), topLeft.col()), model->index(bottomRight.row(), bottomRight.col())), flags);
ui->cells->selectionModel()->select(
QItemSelection(model->index(topLeft.row(), topLeft.col()),
model->index(bottomRight.row(), bottomRight.col())),
flags);
}
void SheetView::deleteSelection()
@@ -509,10 +572,11 @@ void SpreadsheetGui::SheetView::setCurrentIndex(App::CellAddress cell) const
ui->cells->setCurrentIndex(model->index(cell.row(), cell.col()));
}
PyObject *SheetView::getPyObject()
PyObject* SheetView::getPyObject()
{
if (!pythonObject)
if (!pythonObject) {
pythonObject = new SheetViewPy(this);
}
Py_INCREF(pythonObject);
return pythonObject;
@@ -534,29 +598,45 @@ void SheetViewPy::init_type()
behaviors().supportGetattr();
behaviors().supportSetattr();
add_varargs_method("selectedRanges", &SheetViewPy::selectedRanges, "selectedRanges(): Get a list of all selected ranges");
add_varargs_method("selectedCells", &SheetViewPy::selectedCells, "selectedCells(): Get a list of all selected cells");
add_varargs_method("select", &SheetViewPy::select, "select(cell,flags): Select (or deselect) the given cell, applying QItemSelectionModel.SelectionFlags\nselect(topLeft,bottomRight,flags): Select (or deselect) the given range, applying QItemSelectionModel.SelectionFlags");
add_varargs_method("currentIndex", &SheetViewPy::currentIndex, "currentIndex(): Get the current index");
add_varargs_method("setCurrentIndex", &SheetViewPy::setCurrentIndex, "setCurrentIndex(cell): Set the current index to the named cell (e.g. 'A1')");
add_varargs_method("selectedRanges",
&SheetViewPy::selectedRanges,
"selectedRanges(): Get a list of all selected ranges");
add_varargs_method("selectedCells",
&SheetViewPy::selectedCells,
"selectedCells(): Get a list of all selected cells");
add_varargs_method(
"select",
&SheetViewPy::select,
"select(cell,flags): Select (or deselect) the given cell, applying "
"QItemSelectionModel.SelectionFlags\nselect(topLeft,bottomRight,flags): Select (or "
"deselect) the given range, applying QItemSelectionModel.SelectionFlags");
add_varargs_method("currentIndex",
&SheetViewPy::currentIndex,
"currentIndex(): Get the current index");
add_varargs_method(
"setCurrentIndex",
&SheetViewPy::setCurrentIndex,
"setCurrentIndex(cell): Set the current index to the named cell (e.g. 'A1')");
add_varargs_method("getSheet", &SheetViewPy::getSheet, "getSheet()");
add_varargs_method("cast_to_base", &SheetViewPy::cast_to_base, "cast_to_base() cast to MDIView class");
add_varargs_method("cast_to_base",
&SheetViewPy::cast_to_base,
"cast_to_base() cast to MDIView class");
behaviors().readyType();
}
SheetViewPy::SheetViewPy(SheetView *mdi)
: base(mdi)
{
}
SheetViewPy::SheetViewPy(SheetView* mdi)
: base(mdi)
{}
SheetViewPy::~SheetViewPy() = default;
Py::Object SheetViewPy::repr()
{
std::ostringstream s_out;
if (!getSheetViewPtr())
if (!getSheetViewPtr()) {
throw Py::RuntimeError("Cannot print representation of deleted object");
}
s_out << "SheetView";
return Py::String(s_out.str());
}
@@ -565,14 +645,14 @@ Py::Object SheetViewPy::repr()
// a trick is to use MDIViewPy as class member and override getattr() to
// join the attributes of both classes. This way all methods of MDIViewPy
// appear for SheetViewPy, too.
Py::Object SheetViewPy::getattr(const char * attr)
Py::Object SheetViewPy::getattr(const char* attr)
{
if (!getSheetViewPtr()) {
std::ostringstream s_out;
s_out << "Cannot access attribute '" << attr << "' of deleted object";
throw Py::RuntimeError(s_out.str());
}
std::string name( attr );
std::string name(attr);
if (name == "__dict__" || name == "__class__") {
Py::Dict dict_self(BaseType::getattr("__dict__"));
Py::Dict dict_base(base.getattr("__dict__"));
@@ -598,8 +678,9 @@ SheetView* SheetViewPy::getSheetViewPtr()
Py::Object SheetViewPy::getSheet(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
return Py::asObject(new Spreadsheet::SheetPy(getSheetViewPtr()->getSheet()));
}
@@ -610,13 +691,13 @@ Py::Object SheetViewPy::cast_to_base(const Py::Tuple&)
Py::Object SheetViewPy::selectedRanges(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
SheetView* sheetView = getSheetViewPtr();
std::vector<App::Range> ranges = sheetView->selectedRanges();
Py::List list;
for (const auto& range : ranges)
{
for (const auto& range : ranges) {
list.append(Py::String(range.rangeString()));
}
@@ -625,8 +706,9 @@ Py::Object SheetViewPy::selectedRanges(const Py::Tuple& args)
Py::Object SheetViewPy::selectedCells(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
SheetView* sheetView = getSheetViewPtr();
QModelIndexList cells = sheetView->selectedIndexes();
Py::List list;
@@ -648,26 +730,37 @@ Py::Object SheetViewPy::select(const Py::Tuple& _args)
const char* bottomRight;
int flags = 0;
if (args.size() == 2 && PyArg_ParseTuple(_args.ptr(), "si", &cell, &flags)) {
sheetView->select(App::CellAddress(cell), static_cast<QItemSelectionModel::SelectionFlags>(flags));
sheetView->select(App::CellAddress(cell),
static_cast<QItemSelectionModel::SelectionFlags>(flags));
}
else if (args.size() == 3 && PyArg_ParseTuple(_args.ptr(), "ssi", &topLeft, &bottomRight, &flags)) {
sheetView->select(App::CellAddress(topLeft), App::CellAddress(bottomRight), static_cast<QItemSelectionModel::SelectionFlags>(flags));
else if (args.size() == 3
&& PyArg_ParseTuple(_args.ptr(), "ssi", &topLeft, &bottomRight, &flags)) {
sheetView->select(App::CellAddress(topLeft),
App::CellAddress(bottomRight),
static_cast<QItemSelectionModel::SelectionFlags>(flags));
}
else {
if (args.size() == 2)
throw Base::TypeError("Expects the arguments to be a cell name (e.g. 'A1') and QItemSelectionModel.SelectionFlags");
else if (args.size() == 3)
throw Base::TypeError("Expects the arguments to be a cell name (e.g. 'A1'), a second cell name (e.g. 'B5'), and QItemSelectionModel.SelectionFlags");
else
throw Base::TypeError("Wrong arguments to select: specify either a cell, or two cells (for a range), and QItemSelectionModel.SelectionFlags");
if (args.size() == 2) {
throw Base::TypeError("Expects the arguments to be a cell name (e.g. 'A1') and "
"QItemSelectionModel.SelectionFlags");
}
else if (args.size() == 3) {
throw Base::TypeError("Expects the arguments to be a cell name (e.g. 'A1'), a second "
"cell name (e.g. 'B5'), and QItemSelectionModel.SelectionFlags");
}
else {
throw Base::TypeError("Wrong arguments to select: specify either a cell, or two cells "
"(for a range), and QItemSelectionModel.SelectionFlags");
}
}
return Py::None();
}
Py::Object SheetViewPy::currentIndex(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
SheetView* sheetView = getSheetViewPtr();
auto index = sheetView->currentIndex();
Py::String str(App::CellAddress(index.row(), index.column()).toString());

View File

@@ -38,12 +38,14 @@ class QActionGroup;
class QPopupMenu;
class QToolBar;
namespace App {
namespace App
{
class DocumentObject;
class Property;
}
}// namespace App
namespace Ui {
namespace Ui
{
class Sheet;
}
@@ -54,7 +56,7 @@ namespace SpreadsheetGui
class SpreadsheetDelegate;
class SpreadsheetGuiExport SheetView : public Gui::MDIView
class SpreadsheetGuiExport SheetView: public Gui::MDIView
{
Q_OBJECT
@@ -64,9 +66,12 @@ public:
SheetView(Gui::Document* pcDocument, App::DocumentObject* docObj, QWidget* parent);
~SheetView() override;
const char *getName() const override {return "SheetView";}
const char* getName() const override
{
return "SheetView";
}
bool onMsg(const char* pMsg,const char** ppReturn) override;
bool onMsg(const char* pMsg, const char** ppReturn) override;
bool onHasMsg(const char* pMsg) const override;
/** @name Printing */
@@ -77,9 +82,12 @@ public:
void print(QPrinter*) override;
//@}
void updateCell(const App::Property * prop);
void updateCell(const App::Property* prop);
Spreadsheet::Sheet * getSheet() { return sheet; }
Spreadsheet::Sheet* getSheet()
{
return sheet;
}
std::vector<App::Range> selectedRanges() const;
@@ -88,7 +96,9 @@ public:
void select(App::CellAddress cell, QItemSelectionModel::SelectionFlags flags);
void select(App::CellAddress topLeft, App::CellAddress bottomRight, QItemSelectionModel::SelectionFlags flags);
void select(App::CellAddress topLeft,
App::CellAddress bottomRight,
QItemSelectionModel::SelectionFlags flags);
QModelIndex currentIndex() const;
@@ -96,7 +106,7 @@ public:
void deleteSelection();
PyObject *getPyObject() override;
PyObject* getPyObject() override;
void deleteSelf() override;
@@ -105,12 +115,13 @@ protected Q_SLOTS:
void confirmAliasChanged(const QString& text);
void aliasChanged(const QString& text);
void confirmContentChanged(const QString& text);
void currentChanged( const QModelIndex & current, const QModelIndex & previous );
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
void columnResized(int col, int oldSize, int newSize);
void rowResized(int row, int oldSize, int newSize);
void columnResizeFinished();
void rowResizeFinished();
void modelUpdated(const QModelIndex & topLeft, const QModelIndex & bottomRight);
void modelUpdated(const QModelIndex& topLeft, const QModelIndex& bottomRight);
protected:
void updateContentLine();
void updateAliasLine();
@@ -118,10 +129,10 @@ protected:
void resizeColumn(int col, int newSize);
void resizeRow(int col, int newSize);
Ui::Sheet * ui;
Spreadsheet::Sheet * sheet;
SpreadsheetDelegate * delegate;
SheetModel * model;
Ui::Sheet* ui;
Spreadsheet::Sheet* sheet;
SpreadsheetDelegate* delegate;
SheetModel* model;
boost::signals2::scoped_connection columnWidthChangedConnection;
boost::signals2::scoped_connection rowHeightChangedConnection;
boost::signals2::scoped_connection positionChangedConnection;
@@ -130,20 +141,20 @@ protected:
std::map<int, int> newRowSizes;
};
class SheetViewPy : public Py::PythonExtension<SheetViewPy>
class SheetViewPy: public Py::PythonExtension<SheetViewPy>
{
public:
using BaseType = Py::PythonExtension<SheetViewPy>;
static void init_type();
explicit SheetViewPy(SheetView *mdi);
explicit SheetViewPy(SheetView* mdi);
~SheetViewPy() override;
Py::Object repr() override;
Py::Object getattr(const char *) override;
Py::Object getattr(const char*) override;
Py::Object getSheet(const Py::Tuple&);
Py::Object cast_to_base(const Py::Tuple&);
Py::Object selectedRanges(const Py::Tuple&);
Py::Object selectedCells(const Py::Tuple&);
Py::Object select(const Py::Tuple&);
@@ -156,6 +167,6 @@ protected:
Gui::MDIViewPy base;
};
} // namespace SpreadsheetModGui
}// namespace SpreadsheetGui
#endif // SpreadsheetView_H
#endif// SpreadsheetView_H

View File

@@ -24,9 +24,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
# include <QMenu>
# include <QString>
#include <QMenu>
#include <QString>
#include <sstream>
#endif
#include <Gui/Application.h>
@@ -36,9 +36,9 @@
#include <Gui/View3DInventor.h>
#include <Mod/Spreadsheet/App/Sheet.h>
#include "SpreadsheetView.h"
#include "ViewProviderSpreadsheet.h"
#include "ViewProviderSpreadsheetPy.h"
#include "SpreadsheetView.h"
using namespace Base;
@@ -51,14 +51,13 @@ PROPERTY_SOURCE(SpreadsheetGui::ViewProviderSheet, Gui::ViewProviderDocumentObje
ViewProviderSheet::ViewProviderSheet()
: Gui::ViewProviderDocumentObject()
{
}
{}
ViewProviderSheet::~ViewProviderSheet()
{
if (!view.isNull()) {
Gui::getMainWindow()->removeWindow(view);
// delete view;
// delete view;
}
}
@@ -76,27 +75,12 @@ std::vector<std::string> ViewProviderSheet::getDisplayModes() const
QIcon ViewProviderSheet::getIcon() const
{
static const char * const Points_Feature_xpm[] = {
"16 16 3 1",
" c None",
". c #000000",
"+ c #FFFFFF",
" ",
" ",
"................",
".++++.++++.++++.",
".++++.++++.++++.",
"................",
".++++.++++.++++.",
".++++.++++.++++.",
"................",
".++++.++++.++++.",
".++++.++++.++++.",
"................",
".++++.++++.++++.",
".++++.++++.++++.",
"................",
" "};
static const char* const Points_Feature_xpm[] = {
"16 16 3 1", " c None", ". c #000000", "+ c #FFFFFF",
" ", " ", "................", ".++++.++++.++++.",
".++++.++++.++++.", "................", ".++++.++++.++++.", ".++++.++++.++++.",
"................", ".++++.++++.++++.", ".++++.++++.++++.", "................",
".++++.++++.++++.", ".++++.++++.++++.", "................", " "};
QPixmap px(Points_Feature_xpm);
return px;
}
@@ -123,14 +107,14 @@ bool ViewProviderSheet::doubleClicked()
return true;
}
void ViewProviderSheet::setupContextMenu(QMenu * menu, QObject *receiver, const char *member)
void ViewProviderSheet::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
QAction* act;
act = menu->addAction(QObject::tr("Show spreadsheet"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
}
Sheet *ViewProviderSheet::getSpreadsheetObject() const
Sheet* ViewProviderSheet::getSpreadsheetObject() const
{
return freecad_dynamic_cast<Sheet>(pcObject);
}
@@ -138,21 +122,23 @@ Sheet *ViewProviderSheet::getSpreadsheetObject() const
void ViewProviderSheet::beforeDelete()
{
ViewProviderDocumentObject::beforeDelete();
if(!view)
if (!view) {
return;
if(view==Gui::getMainWindow()->activeWindow())
getDocument()->setActiveView(nullptr,Gui::View3DInventor::getClassTypeId());
}
if (view == Gui::getMainWindow()->activeWindow()) {
getDocument()->setActiveView(nullptr, Gui::View3DInventor::getClassTypeId());
}
Gui::getMainWindow()->removeWindow(view);
}
SheetView *ViewProviderSheet::showSpreadsheetView()
SheetView* ViewProviderSheet::showSpreadsheetView()
{
if (!view){
Gui::Document* doc = Gui::Application::Instance->getDocument
(this->pcObject->getDocument());
if (!view) {
Gui::Document* doc = Gui::Application::Instance->getDocument(this->pcObject->getDocument());
view = new SheetView(doc, this->pcObject, Gui::getMainWindow());
view->setWindowIcon(Gui::BitmapFactory().pixmap(":icons/Spreadsheet.svg"));
view->setWindowTitle(QString::fromUtf8(pcObject->Label.getValue()) + QString::fromLatin1("[*]"));
view->setWindowTitle(QString::fromUtf8(pcObject->Label.getValue())
+ QString::fromLatin1("[*]"));
Gui::getMainWindow()->addWindow(view);
startEditing();
}
@@ -160,32 +146,35 @@ SheetView *ViewProviderSheet::showSpreadsheetView()
return view;
}
Gui::MDIView *ViewProviderSheet::getMDIView() const
Gui::MDIView* ViewProviderSheet::getMDIView() const
{
return const_cast<ViewProviderSheet*>(this)->showSpreadsheetView();
}
void ViewProviderSheet::updateData(const App::Property* prop)
{
if (view)
if (view) {
view->updateCell(prop);
}
}
PyObject *ViewProviderSheet::getPyObject()
PyObject* ViewProviderSheet::getPyObject()
{
if (!pyViewObject)
if (!pyViewObject) {
pyViewObject = new ViewProviderSpreadsheetPy(this);
}
pyViewObject->IncRef();
return pyViewObject;
}
// Python feature -----------------------------------------------------------------------
namespace Gui {
namespace Gui
{
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(SpreadsheetGui::ViewProviderSheetPython, SpreadsheetGui::ViewProviderSheet)
/// @endcond
// explicit template instantiation
template class SpreadsheetGuiExport ViewProviderPythonFeatureT<ViewProviderSheet>;
}
}// namespace Gui

View File

@@ -31,7 +31,8 @@
#include <Mod/Spreadsheet/SpreadsheetGlobal.h>
namespace Spreadsheet {
namespace Spreadsheet
{
class Sheet;
}
@@ -40,7 +41,7 @@ namespace SpreadsheetGui
class SheetView;
class SpreadsheetGuiExport ViewProviderSheet : public Gui::ViewProviderDocumentObject
class SpreadsheetGuiExport ViewProviderSheet: public Gui::ViewProviderDocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(SpreadsheetGui::ViewProviderSheet);
@@ -52,7 +53,10 @@ public:
~ViewProviderSheet() override;
void setDisplayMode(const char* ModeName) override;
bool useNewSelectionModel() const override {return false;}
bool useNewSelectionModel() const override
{
return false;
}
std::vector<std::string> getDisplayModes() const override;
bool doubleClicked() override;
@@ -66,24 +70,31 @@ public:
bool setEdit(int ModNum) override;
bool isShow() const override { return true; }
bool isShow() const override
{
return true;
}
Gui::MDIView *getMDIView() const override;
Gui::MDIView* getMDIView() const override;
inline SheetView* getView() const { return view; }
inline SheetView* getView() const
{
return view;
}
PyObject *getPyObject() override;
PyObject* getPyObject() override;
protected:
SheetView* showSpreadsheetView();
void updateData(const App::Property *prop) override;
void updateData(const App::Property* prop) override;
private:
QPointer<SheetView> view;
};
using ViewProviderSheetPython = Gui::ViewProviderPythonFeatureT<ViewProviderSheet>;
} //namespace Spreadsheet
}// namespace SpreadsheetGui
#endif // SPREADSHEET_ViewProviderSpreadsheet_H
#endif// SPREADSHEET_ViewProviderSpreadsheet_H

View File

@@ -22,9 +22,11 @@
#include "PreCompiled.h"
// clang-format off
#include "SpreadsheetView.h"
#include "ViewProviderSpreadsheetPy.h"
#include "ViewProviderSpreadsheetPy.cpp"
// clang-format on
using namespace SpreadsheetGui;
@@ -37,17 +39,19 @@ std::string ViewProviderSpreadsheetPy::representation() const
PyObject* ViewProviderSpreadsheetPy::getView(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
if (sheetView)
if (sheetView) {
return sheetView->getPyObject();
}
Py_RETURN_NONE;
}
PyObject *ViewProviderSpreadsheetPy::getCustomAttributes(const char* /*attr*/) const
PyObject* ViewProviderSpreadsheetPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}

View File

@@ -24,18 +24,18 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <qobject.h>
# include <QToolBar>
#include <QToolBar>
#include <qobject.h>
#endif
#include "Mod/Spreadsheet/App/Sheet.h"
#include "Mod/Spreadsheet/Gui/SpreadsheetView.h"
#include <App/Range.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/MainWindow.h>
#include <Gui/MenuManager.h>
#include <Gui/ToolBarManager.h>
#include "Mod/Spreadsheet/App/Sheet.h"
#include "Mod/Spreadsheet/Gui/SpreadsheetView.h"
#include "Workbench.h"
#include "qtcolorpicker.h"
@@ -46,7 +46,7 @@ using namespace App;
using namespace SpreadsheetGui;
using namespace Spreadsheet;
#if 0 // needed for Qt's lupdate utility
#if 0// needed for Qt's lupdate utility
qApp->translate("Workbench", "Spreadsheet");
qApp->translate("Workbench", "&Spreadsheet");
qApp->translate("Workbench", "&Alignment");
@@ -60,49 +60,61 @@ Workbench::Workbench()
: Gui::StdWorkbench()
, initialized(false)
, workbenchHelper(new WorkbenchHelper)
{
}
{}
Workbench::~Workbench() = default;
void Workbench::activated()
{
if (!initialized) {
QList<QToolBar*> bars = Gui::getMainWindow()->findChildren<QToolBar*>(QString::fromLatin1("Spreadsheet"));
QList<QToolBar*> bars =
Gui::getMainWindow()->findChildren<QToolBar*>(QString::fromLatin1("Spreadsheet"));
if (bars.size() == 1) {
QToolBar * bar = bars[0];
QtColorPicker * foregroundColor;
QtColorPicker * backgroundColor;
QToolBar* bar = bars[0];
QtColorPicker* foregroundColor;
QtColorPicker* backgroundColor;
QPalette palette = Gui::getMainWindow()->palette();
QList<QtColorPicker*> fgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(QString::fromLatin1("Spreadsheet_ForegroundColor"));
if (!fgList.empty())
QList<QtColorPicker*> fgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(
QString::fromLatin1("Spreadsheet_ForegroundColor"));
if (!fgList.empty()) {
foregroundColor = fgList[0];
}
else {
foregroundColor = new QtColorPicker(bar);
foregroundColor->setObjectName(QString::fromLatin1("Spreadsheet_ForegroundColor"));
foregroundColor->setStandardColors();
foregroundColor->setCurrentColor(palette.color(QPalette::WindowText));
QObject::connect(foregroundColor, &QtColorPicker::colorSet, workbenchHelper.get(), &WorkbenchHelper::setForegroundColor);
QObject::connect(foregroundColor,
&QtColorPicker::colorSet,
workbenchHelper.get(),
&WorkbenchHelper::setForegroundColor);
}
foregroundColor->setToolTip(QObject::tr("Set cell(s) foreground color"));
foregroundColor->setWhatsThis(QObject::tr("Sets the Spreadsheet cell(s) foreground color"));
foregroundColor->setWhatsThis(
QObject::tr("Sets the Spreadsheet cell(s) foreground color"));
foregroundColor->setStatusTip(QObject::tr("Set cell(s) foreground color"));
bar->addWidget(foregroundColor);
QList<QtColorPicker*> bgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(QString::fromLatin1("Spreadsheet_BackgroundColor"));
if (!bgList.empty())
QList<QtColorPicker*> bgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(
QString::fromLatin1("Spreadsheet_BackgroundColor"));
if (!bgList.empty()) {
backgroundColor = bgList[0];
}
else {
backgroundColor = new QtColorPicker(bar);
backgroundColor->setObjectName(QString::fromLatin1("Spreadsheet_BackgroundColor"));
backgroundColor->setStandardColors();
backgroundColor->setCurrentColor(palette.color(QPalette::Base));
QObject::connect(backgroundColor, &QtColorPicker::colorSet, workbenchHelper.get(), &WorkbenchHelper::setBackgroundColor);
QObject::connect(backgroundColor,
&QtColorPicker::colorSet,
workbenchHelper.get(),
&WorkbenchHelper::setBackgroundColor);
}
backgroundColor->setToolTip(QObject::tr("Set cell(s) background color"));
backgroundColor->setWhatsThis(QObject::tr("Sets the Spreadsheet cell(s) background color"));
backgroundColor->setWhatsThis(
QObject::tr("Sets the Spreadsheet cell(s) background color"));
backgroundColor->setStatusTip(QObject::tr("Set cell(s) background color"));
bar->addWidget(backgroundColor);
@@ -111,16 +123,17 @@ void Workbench::activated()
}
}
void WorkbenchHelper::setForegroundColor(const QColor & color)
void WorkbenchHelper::setForegroundColor(const QColor& color)
{
Gui::Document * doc = Gui::Application::Instance->activeDocument();
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
// Execute mergeCells commands
@@ -128,9 +141,15 @@ void WorkbenchHelper::setForegroundColor(const QColor & color)
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Set foreground color"));
for (; i != ranges.end(); ++i)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setForeground('%s', (%f,%f,%f))", sheet->getNameInDocument(),
i->rangeString().c_str(), color.redF(), color.greenF(), color.blueF());
for (; i != ranges.end(); ++i) {
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.setForeground('%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()");
}
@@ -138,16 +157,17 @@ void WorkbenchHelper::setForegroundColor(const QColor & color)
}
}
void WorkbenchHelper::setBackgroundColor(const QColor & color)
void WorkbenchHelper::setBackgroundColor(const QColor& color)
{
Gui::Document * doc = Gui::Application::Instance->activeDocument();
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
Gui::MDIView* activeWindow = Gui::getMainWindow()->activeWindow();
SpreadsheetGui::SheetView * sheetView = freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
SpreadsheetGui::SheetView* sheetView =
freecad_dynamic_cast<SpreadsheetGui::SheetView>(activeWindow);
if (sheetView) {
Sheet * sheet = sheetView->getSheet();
Sheet* sheet = sheetView->getSheet();
std::vector<Range> ranges = sheetView->selectedRanges();
// Execute mergeCells commands
@@ -155,9 +175,15 @@ void WorkbenchHelper::setBackgroundColor(const QColor & color)
std::vector<Range>::const_iterator i = ranges.begin();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "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());
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()");
}
@@ -165,7 +191,7 @@ void WorkbenchHelper::setBackgroundColor(const QColor & color)
}
}
Gui::MenuItem *Workbench::setupMenuBar() const
Gui::MenuItem* Workbench::setupMenuBar() const
{
Gui::MenuItem* root = StdWorkbench::setupMenuBar();
Gui::MenuItem* item = root->findItem("&Windows");
@@ -176,35 +202,28 @@ Gui::MenuItem *Workbench::setupMenuBar() const
// utilities
Gui::MenuItem* alignments = new Gui::MenuItem;
alignments->setCommand("&Alignment");
*alignments
<< "Spreadsheet_AlignLeft"
<< "Spreadsheet_AlignCenter"
<< "Spreadsheet_AlignRight"
<< "Spreadsheet_AlignTop"
<< "Spreadsheet_AlignVCenter"
<< "Spreadsheet_AlignBottom"
;
*alignments << "Spreadsheet_AlignLeft"
<< "Spreadsheet_AlignCenter"
<< "Spreadsheet_AlignRight"
<< "Spreadsheet_AlignTop"
<< "Spreadsheet_AlignVCenter"
<< "Spreadsheet_AlignBottom";
Gui::MenuItem* styles = new Gui::MenuItem;
styles->setCommand("&Styles");
*styles
<< "Spreadsheet_StyleBold"
*styles << "Spreadsheet_StyleBold"
<< "Spreadsheet_StyleItalic"
<< "Spreadsheet_StyleUnderline"
;
<< "Spreadsheet_StyleUnderline";
spreadsheet->setCommand("&Spreadsheet");
*spreadsheet << "Spreadsheet_CreateSheet"
<< "Separator"
<< "Spreadsheet_Import"
<< "Spreadsheet_Export"
<< "Separator"
<< "Spreadsheet_MergeCells"
<< "Spreadsheet_SplitCell"
<< "Separator"
<< alignments
<< styles
;
<< "Separator"
<< "Spreadsheet_Import"
<< "Spreadsheet_Export"
<< "Separator"
<< "Spreadsheet_MergeCells"
<< "Spreadsheet_SplitCell"
<< "Separator" << alignments << styles;
return root;
}
@@ -234,8 +253,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "Spreadsheet_StyleUnderline"
<< "Separator"
<< "Spreadsheet_SetAlias"
<< "Separator"
;
<< "Separator";
return root;
}

View File

@@ -31,41 +31,42 @@
class QtColorPicker;
class QColor;
namespace SpreadsheetGui {
namespace SpreadsheetGui
{
/**
* @author Eivind Kvedalen
*/
class SpreadsheetGuiExport WorkbenchHelper : public QObject
class SpreadsheetGuiExport WorkbenchHelper: public QObject
{
Q_OBJECT
public Q_SLOTS:
void setForegroundColor(const QColor &color);
void setBackgroundColor(const QColor &color);
void setForegroundColor(const QColor& color);
void setBackgroundColor(const QColor& color);
};
class SpreadsheetGuiExport Workbench : public Gui::StdWorkbench
class SpreadsheetGuiExport Workbench: public Gui::StdWorkbench
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
Workbench();
~Workbench() override;
void activated() override;
Workbench();
~Workbench() override;
void activated() override;
private:
bool initialized;
std::unique_ptr<WorkbenchHelper> workbenchHelper;
bool initialized;
std::unique_ptr<WorkbenchHelper> workbenchHelper;
protected:
Gui::MenuItem *setupMenuBar() const override;
Gui::ToolBarItem* setupToolBars() const override;
Gui::ToolBarItem* setupCommandBars() const override;
Gui::MenuItem* setupMenuBar() const override;
Gui::ToolBarItem* setupToolBars() const override;
Gui::ToolBarItem* setupCommandBars() const override;
};
} // namespace SpreadsheetModGui
}// namespace SpreadsheetGui
#endif // SPREADSHEET_WORKBENCH_H
#endif// SPREADSHEET_WORKBENCH_H

View File

@@ -47,30 +47,30 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cmath>
#include <cmath>
# include <QApplication>
# include <QPainter>
# include <QPushButton>
# include <QColorDialog>
# include <QGridLayout>
# include <QtCore/QMap>
# include <QLayout>
# include <QStyle>
# include <QtGui/QFocusEvent>
# include <QtGui/QHideEvent>
# include <QtGui/QKeyEvent>
# include <QtGui/QMouseEvent>
# include <QtGui/QPaintEvent>
# include <QtGui/QPixmap>
# include <QtGui/QShowEvent>
#include <QApplication>
#include <QColorDialog>
#include <QGridLayout>
#include <QLayout>
#include <QPainter>
#include <QPushButton>
#include <QStyle>
#include <QtCore/QMap>
#include <QtGui/QFocusEvent>
#include <QtGui/QHideEvent>
#include <QtGui/QKeyEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QPaintEvent>
#include <QtGui/QPixmap>
#include <QtGui/QShowEvent>
#endif
#include <Gui/FileDialog.h>
#include "qtcolorpicker.h"
// clang-format off
/*! \class QtColorPicker
\brief The QtColorPicker class provides a widget for selecting
@@ -1164,6 +1164,6 @@ void ColorPickerButton::paintEvent(QPaintEvent *e)
p.end();
}
// clang-format on
#include "moc_qtcolorpicker.cpp"
#include <moc_qtcolorpicker-internal.cpp>

View File

@@ -1,17 +1,17 @@
/****************************************************************************
**
** This file is part of a Qt Solutions component.
**
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Solutions Commercial License Agreement provided
** with the Software or, alternatively, in accordance with the terms
** contained in a written agreement between you and Nokia.
**
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
@@ -19,31 +19,32 @@
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** Please note Third Party Software included with Qt Solutions may impose
** additional restrictions and it is the user's responsibility to ensure
** that they have met the licensing requirements of the GPL, LGPL, or Qt
** Solutions Commercial license and the relevant license of the Third
** Party Software they are using.
**
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**
****************************************************************************/
// clang-format off
#ifndef QTCOLORPICKER_H
#define QTCOLORPICKER_H
#include <QPushButton>
@@ -120,3 +121,4 @@ private:
};
#endif
// clang-format on