diff --git a/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp b/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp
index 2702032b9d..d9efec75ff 100644
--- a/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp
+++ b/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp
@@ -30,18 +30,18 @@
#include
#include
#include
+#include
#include
#include
-#include
#include
#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
+namespace SpreadsheetGui
+{
+class Module: public Py::ExtensionModule
+{
+public:
+ Module()
+ : Py::ExtensionModule("SpreadsheetGui")
{
- public:
- Module() : Py::ExtensionModule("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(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(
+ 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 (QT_TRANSLATE_NOOP("QObject","Spreadsheet"));
+ new Gui::PrefPageProducer(
+ QT_TRANSLATE_NOOP("QObject", "Spreadsheet"));
// add resources and reloads the translators
loadSpreadsheetResource();
diff --git a/src/Mod/Spreadsheet/Gui/Command.cpp b/src/Mod/Spreadsheet/Gui/Command.cpp
index f4719390c6..6bc7ab5adb 100644
--- a/src/Mod/Spreadsheet/Gui/Command.cpp
+++ b/src/Mod/Spreadsheet/Gui/Command.cpp
@@ -22,11 +22,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include
+#include
#endif
#if defined(FC_OS_WIN32)
-# include
+#include
#endif
#include
@@ -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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
std::vector ranges = sheetView->selectedRanges();
// Execute mergeCells commands
if (!ranges.empty()) {
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Merge cells"));
std::vector::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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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(App::GetApplication().getActiveDocument()->addObject("Spreadsheet::Sheet", FeatName.c_str()));
- if (sheet){
+ Sheet* sheet = freecad_dynamic_cast(
+ 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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
std::vector ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector::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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
std::vector ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector::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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
std::vector ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector::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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
std::vector ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector::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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
std::vector ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector::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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
std::vector ranges = sheetView->selectedRanges();
if (!ranges.empty()) {
std::vector::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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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 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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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 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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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 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(activeWindow))
+ if (activeWindow && freecad_dynamic_cast(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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(activeWindow);
if (sheetView) {
- Sheet * sheet = sheetView->getSheet();
+ Sheet* sheet = sheetView->getSheet();
QModelIndexList selection = sheetView->selectedIndexes();
if (selection.size() == 1) {
std::vector 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 dialog(new PropertiesDialog(sheet, range, sheetView));
+ std::unique_ptr 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(activeWindow);
+ SpreadsheetGui::SheetView* sheetView =
+ freecad_dynamic_cast(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());
diff --git a/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp b/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp
index d1a3cf9531..496230249e 100644
--- a/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp
+++ b/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp
@@ -22,8 +22,8 @@
#include "PreCompiled.h"
-#include
#include
+#include
#include
#include
@@ -39,42 +39,49 @@ using namespace App;
using namespace Spreadsheet;
using namespace SpreadsheetGui;
-DlgBindSheet::DlgBindSheet(Sheet *sheet, const std::vector &ranges, QWidget *parent)
- : QDialog(parent), sheet(sheet), range(ranges.front()), ui(new Ui::DlgBindSheet)
+DlgBindSheet::DlgBindSheet(Sheet* sheet, const std::vector& 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(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(pEnd.get())->getText();
+ }
else {
toEnd = "=";
toEnd += pEnd->toString();
@@ -84,49 +91,59 @@ DlgBindSheet::DlgBindSheet(Sheet *sheet, const std::vector &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()) {
- if(obj == sheet)
+ App::DocumentObject* target = bindingTarget.getDocumentObject();
+ for (auto obj : sheet->getDocument()->getObjectsOfType()) {
+ 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()) {
- if(obj == sheet)
+ }
+ for (auto obj : sheet->getDocument()->getObjectsOfType()) {
+ 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(doc->getObject(sep+1));
- } else
+ }
+ obj = Base::freecad_dynamic_cast(doc->getObject(sep + 1));
+ }
+ else {
obj = Base::freecad_dynamic_cast(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();
diff --git a/src/Mod/Spreadsheet/Gui/DlgBindSheet.h b/src/Mod/Spreadsheet/Gui/DlgBindSheet.h
index eab41e1509..1f8810ada0 100644
--- a/src/Mod/Spreadsheet/Gui/DlgBindSheet.h
+++ b/src/Mod/Spreadsheet/Gui/DlgBindSheet.h
@@ -23,21 +23,25 @@
#ifndef DLG_BINDSHEET_H
#define DLG_BINDSHEET_H
-#include
#include
+#include
-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 &range, QWidget *parent = nullptr);
+ explicit DlgBindSheet(Spreadsheet::Sheet* sheet,
+ const std::vector& 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
diff --git a/src/Mod/Spreadsheet/Gui/DlgSettingsImp.cpp b/src/Mod/Spreadsheet/Gui/DlgSettingsImp.cpp
index cc17195f63..d90e4fc54b 100644
--- a/src/Mod/Spreadsheet/Gui/DlgSettingsImp.cpp
+++ b/src/Mod/Spreadsheet/Gui/DlgSettingsImp.cpp
@@ -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);
diff --git a/src/Mod/Spreadsheet/Gui/DlgSettingsImp.h b/src/Mod/Spreadsheet/Gui/DlgSettingsImp.h
index 3aa365e81e..aa65403cee 100644
--- a/src/Mod/Spreadsheet/Gui/DlgSettingsImp.h
+++ b/src/Mod/Spreadsheet/Gui/DlgSettingsImp.h
@@ -27,7 +27,8 @@
#include
#include
-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;
};
-} // namespace SpreadsheetGui
+}// namespace SpreadsheetGui
-#endif // SPREADSHEETGUI_DLGSETTINGSIMP_H
+#endif// SPREADSHEETGUI_DLGSETTINGSIMP_H
diff --git a/src/Mod/Spreadsheet/Gui/DlgSheetConf.cpp b/src/Mod/Spreadsheet/Gui/DlgSheetConf.cpp
index 4781b70f55..3b18db875f 100644
--- a/src/Mod/Spreadsheet/Gui/DlgSheetConf.cpp
+++ b/src/Mod/Spreadsheet/Gui/DlgSheetConf.cpp
@@ -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(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(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(expr);
- if(vexpr) {
- auto prop = Base::freecad_dynamic_cast(
- vexpr->getPath().getProperty());
- if(prop) {
+ if (vexpr) {
+ auto prop =
+ Base::freecad_dynamic_cast(vexpr->getPath().getProperty());
+ if (prop) {
auto obj = Base::freecad_dynamic_cast(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; igetCellBinding(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; igetCellBinding(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();
+ }
}
}
diff --git a/src/Mod/Spreadsheet/Gui/DlgSheetConf.h b/src/Mod/Spreadsheet/Gui/DlgSheetConf.h
index 7555339f79..ac2fa4606e 100644
--- a/src/Mod/Spreadsheet/Gui/DlgSheetConf.h
+++ b/src/Mod/Spreadsheet/Gui/DlgSheetConf.h
@@ -23,36 +23,41 @@
#ifndef DLG_SHEETCONF_H
#define DLG_SHEETCONF_H
-#include
#include
+#include
-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
diff --git a/src/Mod/Spreadsheet/Gui/LineEdit.cpp b/src/Mod/Spreadsheet/Gui/LineEdit.cpp
index 3908f146c4..cf7d465842 100644
--- a/src/Mod/Spreadsheet/Gui/LineEdit.cpp
+++ b/src/Mod/Spreadsheet/Gui/LineEdit.cpp
@@ -23,9 +23,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include
-# include
-# include
+#include
+#include
+#include
#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(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(event);
+ QKeyEvent* kevent = static_cast(event);
lastKeyPressed = kevent->key();
lastModifiers = kevent->modifiers();
}
diff --git a/src/Mod/Spreadsheet/Gui/LineEdit.h b/src/Mod/Spreadsheet/Gui/LineEdit.h
index 3f508f8048..e6666fbd09 100644
--- a/src/Mod/Spreadsheet/Gui/LineEdit.h
+++ b/src/Mod/Spreadsheet/Gui/LineEdit.h
@@ -23,19 +23,20 @@
#ifndef LINEEDIT_H
#define LINEEDIT_H
-#include
#include
+#include
-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
diff --git a/src/Mod/Spreadsheet/Gui/PreCompiled.h b/src/Mod/Spreadsheet/Gui/PreCompiled.h
index 29cd0ed332..710286a3dd 100644
--- a/src/Mod/Spreadsheet/Gui/PreCompiled.h
+++ b/src/Mod/Spreadsheet/Gui/PreCompiled.h
@@ -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
#ifdef FC_OS_WIN32
-# include
+#include
#endif
// Qt Toolkit
#ifndef __QtAll__
-# include
+#include
#endif
-#endif //_PreComp_
+#endif//_PreComp_
-#endif // SPREADSHEET_PRECOMPILED_H
+#endif// SPREADSHEET_PRECOMPILED_H
diff --git a/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp b/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp
index 50bf6d124e..a2fb26d722 100644
--- a/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp
+++ b/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp
@@ -22,9 +22,9 @@
#include "PreCompiled.h"
-#include
#include
#include
+#include
#include
#include
@@ -36,14 +36,16 @@ using namespace App;
using namespace Spreadsheet;
using namespace SpreadsheetGui;
-PropertiesDialog::PropertiesDialog(Sheet *_sheet, const std::vector &_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& _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 &_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 &_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 &_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 e(App::ExpressionParser::parseUnit(sheet, text.toUtf8().constData()));
+ std::unique_ptr 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();
+ }
}
}
diff --git a/src/Mod/Spreadsheet/Gui/PropertiesDialog.h b/src/Mod/Spreadsheet/Gui/PropertiesDialog.h
index d688975ea0..5334ba7bb3 100644
--- a/src/Mod/Spreadsheet/Gui/PropertiesDialog.h
+++ b/src/Mod/Spreadsheet/Gui/PropertiesDialog.h
@@ -23,37 +23,42 @@
#ifndef PROPERTIESDIALOG_H
#define PROPERTIESDIALOG_H
-#include
#include
+#include
-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 & _ranges, QWidget *parent = nullptr);
+ explicit PropertiesDialog(Spreadsheet::Sheet* _sheet,
+ const std::vector& _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 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
diff --git a/src/Mod/Spreadsheet/Gui/SheetModel.cpp b/src/Mod/Spreadsheet/Gui/SheetModel.cpp
index 86cd2f099d..1a1c2eec23 100644
--- a/src/Mod/Spreadsheet/Gui/SheetModel.cpp
+++ b/src/Mod/Spreadsheet/Gui/SheetModel.cpp
@@ -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::const_iterator i = deps.begin(); i != deps.end(); ++i)
+ for (std::set::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::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 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(prop)->getValue();
+ }
else {
isInteger = true;
l = static_cast(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;
}
diff --git a/src/Mod/Spreadsheet/Gui/SheetModel.h b/src/Mod/Spreadsheet/Gui/SheetModel.h
index db8d5cd865..e47a6b2c36 100644
--- a/src/Mod/Spreadsheet/Gui/SheetModel.h
+++ b/src/Mod/Spreadsheet/Gui/SheetModel.h
@@ -28,43 +28,45 @@
#include
-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
diff --git a/src/Mod/Spreadsheet/Gui/SheetTableView.cpp b/src/Mod/Spreadsheet/Gui/SheetTableView.cpp
index 46e9ead2d4..b7f74fceab 100644
--- a/src/Mod/Spreadsheet/Gui/SheetTableView.cpp
+++ b/src/Mod/Spreadsheet/Gui/SheetTableView.cpp
@@ -23,15 +23,15 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include
-# include
-# include
-# include
-# include
-# include
-# include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#endif
-# include
+#include
#include
#include
@@ -45,11 +45,11 @@
#include
#include
-#include "SheetTableView.h"
#include "DlgBindSheet.h"
#include "DlgSheetConf.h"
#include "LineEdit.h"
#include "PropertiesDialog.h"
+#include "SheetTableView.h"
using namespace SpreadsheetGui;
@@ -57,23 +57,25 @@ using namespace Spreadsheet;
using namespace App;
namespace sp = std::placeholders;
-void SheetViewHeader::mouseReleaseEvent(QMouseEvent *event)
+void SheetViewHeader::mouseReleaseEvent(QMouseEvent* event)
{
QHeaderView::mouseReleaseEvent(event);
Q_EMIT resizeFinished();
}
-bool SheetViewHeader::viewportEvent(QEvent *e) {
- if(e->type() == QEvent::ContextMenu) {
- auto *ce = static_cast(e);
+bool SheetViewHeader::viewportEvent(QEvent* e)
+{
+ if (e->type() == QEvent::ContextMenu) {
+ auto* ce = static_cast(e);
int section = logicalIndexAt(ce->pos());
- if(section>=0) {
- if(orientation() == Qt::Horizontal) {
- if(!owner->selectionModel()->isColumnSelected(section,owner->rootIndex())) {
+ if (section >= 0) {
+ if (orientation() == Qt::Horizontal) {
+ if (!owner->selectionModel()->isColumnSelected(section, owner->rootIndex())) {
owner->clearSelection();
owner->selectColumn(section);
}
- }else if(!owner->selectionModel()->isRowSelected(section,owner->rootIndex())) {
+ }
+ else if (!owner->selectionModel()->isRowSelected(section, owner->rootIndex())) {
owner->clearSelection();
owner->selectRow(section);
}
@@ -86,7 +88,7 @@ static std::pair selectedMinMaxRows(QModelIndexList list)
{
int min = std::numeric_limits::max();
int max = 0;
- for (const auto & item : list) {
+ for (const auto& item : list) {
int row = item.row();
min = std::min(row, min);
max = std::max(row, max);
@@ -98,7 +100,7 @@ static std::pair selectedMinMaxColumns(QModelIndexList list)
{
int min = std::numeric_limits::max();
int max = 0;
- for (const auto & item : list) {
+ for (const auto& item : list) {
int column = item.column();
min = std::min(column, min);
max = std::max(column, max);
@@ -106,65 +108,71 @@ static std::pair selectedMinMaxColumns(QModelIndexList list)
return {min, max};
}
-SheetTableView::SheetTableView(QWidget *parent)
+SheetTableView::SheetTableView(QWidget* parent)
: QTableView(parent)
, sheet(nullptr)
, tabCounter(0)
{
- setHorizontalHeader(new SheetViewHeader(this,Qt::Horizontal));
- setVerticalHeader(new SheetViewHeader(this,Qt::Vertical));
+ setHorizontalHeader(new SheetViewHeader(this, Qt::Horizontal));
+ setVerticalHeader(new SheetViewHeader(this, Qt::Vertical));
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
- connect(verticalHeader(), &QWidget::customContextMenuRequested,
- [this](const QPoint &point){
- QMenu menu(this);
- const auto selection = selectionModel()->selectedRows();
- const auto & [min, max] = selectedMinMaxRows(selection);
- if (bool isContiguous = max - min == selection.size() - 1) {
- Q_UNUSED(isContiguous)
- /*: This is shown in the context menu for the vertical header in a spreadsheet.
- The number refers to how many lines are selected and will be inserted. */
- auto insertBefore = menu.addAction(tr("Insert %n row(s) above", "", selection.size()));
- connect(insertBefore, &QAction::triggered, this, &SheetTableView::insertRows);
+ connect(verticalHeader(), &QWidget::customContextMenuRequested, [this](const QPoint& point) {
+ QMenu menu(this);
+ const auto selection = selectionModel()->selectedRows();
+ const auto& [min, max] = selectedMinMaxRows(selection);
+ if (bool isContiguous = max - min == selection.size() - 1) {
+ Q_UNUSED(isContiguous)
+ /*: This is shown in the context menu for the vertical header in a spreadsheet.
+ The number refers to how many lines are selected and will be inserted. */
+ auto insertBefore = menu.addAction(tr("Insert %n row(s) above", "", selection.size()));
+ connect(insertBefore, &QAction::triggered, this, &SheetTableView::insertRows);
- if (max < model()->rowCount() - 1) {
- auto insertAfter = menu.addAction(tr("Insert %n row(s) below", "", selection.size()));
- connect(insertAfter, &QAction::triggered, this, &SheetTableView::insertRowsAfter);
- }
- } else {
- auto insert = menu.addAction(tr("Insert %n non-contiguous rows", "", selection.size()));
- connect(insert, &QAction::triggered, this, &SheetTableView::insertRows);
+ if (max < model()->rowCount() - 1) {
+ auto insertAfter =
+ menu.addAction(tr("Insert %n row(s) below", "", selection.size()));
+ connect(insertAfter, &QAction::triggered, this, &SheetTableView::insertRowsAfter);
}
- auto remove = menu.addAction(tr("Remove row(s)", "", selection.size()));
- connect(remove, &QAction::triggered, this, &SheetTableView::removeRows);
- menu.exec(verticalHeader()->mapToGlobal(point));
- });
+ }
+ else {
+ auto insert = menu.addAction(tr("Insert %n non-contiguous rows", "", selection.size()));
+ connect(insert, &QAction::triggered, this, &SheetTableView::insertRows);
+ }
+ auto remove = menu.addAction(tr("Remove row(s)", "", selection.size()));
+ connect(remove, &QAction::triggered, this, &SheetTableView::removeRows);
+ menu.exec(verticalHeader()->mapToGlobal(point));
+ });
- connect(horizontalHeader(), &QWidget::customContextMenuRequested,
- [this](const QPoint &point){
- QMenu menu(this);
- const auto selection = selectionModel()->selectedColumns();
- const auto & [min, max] = selectedMinMaxColumns(selection);
- if (bool isContiguous = max - min == selection.size() - 1) {
- Q_UNUSED(isContiguous)
- /*: This is shown in the context menu for the horizontal header in a spreadsheet.
- The number refers to how many lines are selected and will be inserted. */
- auto insertAbove = menu.addAction(tr("Insert %n column(s) left", "", selection.size()));
- connect(insertAbove, &QAction::triggered, this, &SheetTableView::insertColumns);
+ connect(horizontalHeader(), &QWidget::customContextMenuRequested, [this](const QPoint& point) {
+ QMenu menu(this);
+ const auto selection = selectionModel()->selectedColumns();
+ const auto& [min, max] = selectedMinMaxColumns(selection);
+ if (bool isContiguous = max - min == selection.size() - 1) {
+ Q_UNUSED(isContiguous)
+ /*: This is shown in the context menu for the horizontal header in a spreadsheet.
+ The number refers to how many lines are selected and will be inserted. */
+ auto insertAbove = menu.addAction(tr("Insert %n column(s) left", "", selection.size()));
+ connect(insertAbove, &QAction::triggered, this, &SheetTableView::insertColumns);
- if (max < model()->columnCount() - 1) {
- auto insertAfter = menu.addAction(tr("Insert %n column(s) right", "", selection.size()));
- connect(insertAfter, &QAction::triggered, this, &SheetTableView::insertColumnsAfter);
- }
- } else {
- auto insert = menu.addAction(tr("Insert %n non-contiguous columns", "", selection.size()));
- connect(insert, &QAction::triggered, this, &SheetTableView::insertColumns);
+ if (max < model()->columnCount() - 1) {
+ auto insertAfter =
+ menu.addAction(tr("Insert %n column(s) right", "", selection.size()));
+ connect(insertAfter,
+ &QAction::triggered,
+ this,
+ &SheetTableView::insertColumnsAfter);
}
- auto remove = menu.addAction(tr("Remove column(s)", "", selection.size()));
- connect(remove, &QAction::triggered, this, &SheetTableView::removeColumns);
- menu.exec(horizontalHeader()->mapToGlobal(point));
- });
+ }
+ else {
+ auto insert =
+ menu.addAction(tr("Insert %n non-contiguous columns", "", selection.size()));
+ connect(insert, &QAction::triggered, this, &SheetTableView::insertColumns);
+ }
+ auto remove = menu.addAction(tr("Remove column(s)", "", selection.size()));
+ connect(remove, &QAction::triggered, this, &SheetTableView::removeColumns);
+ menu.exec(horizontalHeader()->mapToGlobal(point));
+ });
actionProperties = new QAction(tr("Properties..."), this);
addAction(actionProperties);
@@ -178,15 +186,15 @@ SheetTableView::SheetTableView(QWidget *parent)
connect(actionProperties, &QAction::triggered, this, &SheetTableView::cellProperties);
contextMenu->addSeparator();
- actionRecompute = new QAction(tr("Recompute"),this);
+ actionRecompute = new QAction(tr("Recompute"), this);
connect(actionRecompute, &QAction::triggered, this, &SheetTableView::onRecompute);
contextMenu->addAction(actionRecompute);
- actionBind = new QAction(tr("Bind..."),this);
+ actionBind = new QAction(tr("Bind..."), this);
connect(actionBind, &QAction::triggered, this, &SheetTableView::onBind);
contextMenu->addAction(actionBind);
- actionConf = new QAction(tr("Configuration table..."),this);
+ actionConf = new QAction(tr("Configuration table..."), this);
connect(actionConf, &QAction::triggered, this, &SheetTableView::onConfSetup);
contextMenu->addAction(actionConf);
@@ -212,31 +220,39 @@ SheetTableView::SheetTableView(QWidget *parent)
setTabKeyNavigation(false);
timer.setSingleShot(true);
- QObject::connect(&timer, &QTimer::timeout, [this](){updateCellSpan();});
+ QObject::connect(&timer, &QTimer::timeout, [this]() {
+ updateCellSpan();
+ });
}
-void SheetTableView::onRecompute() {
+void SheetTableView::onRecompute()
+{
Gui::Command::openCommand("Recompute cells");
- for(auto &range : selectedRanges()) {
- Gui::cmdAppObjectArgs(sheet, "recomputeCells('%s', '%s')",
- range.fromCellString(), range.toCellString());
+ for (auto& range : selectedRanges()) {
+ Gui::cmdAppObjectArgs(sheet,
+ "recomputeCells('%s', '%s')",
+ range.fromCellString(),
+ range.toCellString());
}
Gui::Command::commitCommand();
}
-void SheetTableView::onBind() {
+void SheetTableView::onBind()
+{
auto ranges = selectedRanges();
- if(!ranges.empty() && ranges.size()<=2) {
- DlgBindSheet dlg(sheet,ranges,this);
+ if (!ranges.empty() && ranges.size() <= 2) {
+ DlgBindSheet dlg(sheet, ranges, this);
dlg.exec();
}
}
-void SheetTableView::onConfSetup() {
+void SheetTableView::onConfSetup()
+{
auto ranges = selectedRanges();
- if(ranges.empty())
+ if (ranges.empty()) {
return;
- DlgSheetConf dlg(sheet,ranges.back(),this);
+ }
+ DlgSheetConf dlg(sheet, ranges.back(), this);
dlg.exec();
}
@@ -254,9 +270,11 @@ std::vector SheetTableView::selectedRanges() const
std::vector result;
if (!sheet->getCells()->hasSpan()) {
- for (const auto &sel : selectionModel()->selection())
+ for (const auto& sel : selectionModel()->selection()) {
result.emplace_back(sel.top(), sel.left(), sel.bottom(), sel.right());
- } else {
+ }
+ }
+ else {
// If there is spanning cell, QItemSelection returned by
// QTableView::selection() does not merge selected indices into ranges.
// So we have to do it by ourselves. Qt records selection in the order
@@ -267,32 +285,28 @@ std::vector SheetTableView::selectedRanges() const
// together. For example, consecutive single column selections that
// form a rectangle will be merged together, but single row selections
// will not be merged.
- for (const auto &sel : selectionModel()->selection()) {
+ for (const auto& sel : selectionModel()->selection()) {
if (!result.empty() && sel.bottom() == sel.top() && sel.right() == sel.left()) {
- auto &last = result.back();
- if (last.colCount() == 1
- && last.from().col() == sel.left()
- && sel.top() == last.to().row() + 1)
- {
+ auto& last = result.back();
+ if (last.colCount() == 1 && last.from().col() == sel.left()
+ && sel.top() == last.to().row() + 1) {
// This is the case of rectangle selection. We keep
// accumulating the last column, and try to merge the
// column to previous range whenever possible.
last = Range(last.from(), CellAddress(sel.top(), sel.left()));
if (result.size() > 1) {
- auto &secondLast = result[result.size()-2];
+ auto& secondLast = result[result.size() - 2];
if (secondLast.to().col() + 1 == last.to().col()
- && secondLast.from().row() == last.from().row()
- && secondLast.rowCount() == last.rowCount()) {
+ && secondLast.from().row() == last.from().row()
+ && secondLast.rowCount() == last.rowCount()) {
secondLast = Range(secondLast.from(), last.to());
result.pop_back();
}
}
continue;
}
- else if (last.rowCount() == 1
- && last.from().row() == sel.top()
- && last.to().col() + 1 == sel.left())
- {
+ else if (last.rowCount() == 1 && last.from().row() == sel.top()
+ && last.to().col() + 1 == sel.left()) {
// This is the case of single row selection
last = Range(last.from(), CellAddress(sel.top(), sel.left()));
continue;
@@ -337,8 +351,9 @@ void SheetTableView::insertRows()
++count;
++it;
}
- else
+ else {
break;
+ }
}
Gui::cmdAppObjectArgs(sheet, "insertRows('%s', %d)", rowName(prev).c_str(), count);
@@ -351,7 +366,7 @@ void SheetTableView::insertRowsAfter()
{
assert(sheet);
const auto rows = selectionModel()->selectedRows();
- const auto & [min, max] = selectedMinMaxRows(rows);
+ const auto& [min, max] = selectedMinMaxRows(rows);
assert(max - min == rows.size() - 1);
Q_UNUSED(min)
@@ -411,12 +426,12 @@ void SheetTableView::insertColumns()
++count;
++it;
}
- else
+ else {
break;
+ }
}
- Gui::cmdAppObjectArgs(sheet, "insertColumns('%s', %d)",
- columnName(prev).c_str(), count);
+ Gui::cmdAppObjectArgs(sheet, "insertColumns('%s', %d)", columnName(prev).c_str(), count);
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
@@ -431,7 +446,10 @@ void SheetTableView::insertColumnsAfter()
Q_UNUSED(min)
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Insert columns"));
- Gui::cmdAppObjectArgs(sheet, "insertColumns('%s', %d)", columnName(max + 1).c_str(), columns.size());
+ Gui::cmdAppObjectArgs(sheet,
+ "insertColumns('%s', %d)",
+ columnName(max + 1).c_str(),
+ columns.size());
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
@@ -452,8 +470,7 @@ void SheetTableView::removeColumns()
/* Remove columns */
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Remove rows"));
for (const auto& it : sortedColumns) {
- Gui::cmdAppObjectArgs(sheet, "removeColumns('%s', %d)",
- columnName(it).c_str(), 1);
+ Gui::cmdAppObjectArgs(sheet, "removeColumns('%s', %d)", columnName(it).c_str(), 1);
}
Gui::Command::commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
@@ -466,15 +483,17 @@ void SheetTableView::updateCellSpan()
int rows, cols;
// Unspan first to avoid overlap
- for (const auto &addr : spanChanges) {
- if (rowSpan(addr.row(), addr.col()) > 1 || columnSpan(addr.row(), addr.col()) > 1)
+ for (const auto& addr : spanChanges) {
+ if (rowSpan(addr.row(), addr.col()) > 1 || columnSpan(addr.row(), addr.col()) > 1) {
setSpan(addr.row(), addr.col(), 1, 1);
+ }
}
- for (const auto &addr : spanChanges) {
+ for (const auto& addr : spanChanges) {
sheet->getSpans(addr, rows, cols);
- if (rows > 1 || cols > 1)
+ if (rows > 1 || cols > 1) {
setSpan(addr.row(), addr.col(), rows, cols);
+ }
}
spanChanges.clear();
}
@@ -482,7 +501,7 @@ void SheetTableView::updateCellSpan()
void SheetTableView::setSheet(Sheet* _sheet)
{
sheet = _sheet;
- cellSpanChangedConnection = sheet->cellSpanChanged.connect([&](const CellAddress &addr) {
+ cellSpanChangedConnection = sheet->cellSpanChanged.connect([&](const CellAddress& addr) {
spanChanges.insert(addr);
timer.start(10);
});
@@ -505,18 +524,19 @@ void SheetTableView::setSheet(Sheet* _sheet)
for (std::map::const_iterator i = columWidths.begin(); i != columWidths.end(); ++i) {
int newSize = i->second;
- if (newSize > 0 && horizontalHeader()->sectionSize(i->first) != newSize)
+ if (newSize > 0 && horizontalHeader()->sectionSize(i->first) != newSize) {
setColumnWidth(i->first, newSize);
+ }
}
std::map rowHeights = sheet->getRowHeights();
for (std::map::const_iterator i = rowHeights.begin(); i != rowHeights.end(); ++i) {
int newSize = i->second;
- if (newSize > 0 && verticalHeader()->sectionSize(i->first) != newSize)
+ if (newSize > 0 && verticalHeader()->sectionSize(i->first) != newSize) {
setRowHeight(i->first, newSize);
+ }
}
-
}
void SheetTableView::commitData(QWidget* editor)
@@ -526,8 +546,11 @@ void SheetTableView::commitData(QWidget* editor)
bool SheetTableView::edit(const QModelIndex& index, EditTrigger trigger, QEvent* event)
{
- if (trigger & (QAbstractItemView::DoubleClicked | QAbstractItemView::AnyKeyPressed | QAbstractItemView::EditKeyPressed))
+ if (trigger
+ & (QAbstractItemView::DoubleClicked | QAbstractItemView::AnyKeyPressed
+ | QAbstractItemView::EditKeyPressed)) {
currentEditIndex = index;
+ }
return QTableView::edit(index, trigger, event);
}
@@ -538,27 +561,36 @@ bool SheetTableView::event(QEvent* event)
// and handle them.
QKeyEvent* kevent = static_cast(event);
switch (kevent->key()) {
- case Qt::Key_Return: [[fallthrough]];
- case Qt::Key_Enter: [[fallthrough]];
- case Qt::Key_Home: [[fallthrough]];
- case Qt::Key_End: [[fallthrough]];
- case Qt::Key_Left: [[fallthrough]];
- case Qt::Key_Right: [[fallthrough]];
- case Qt::Key_Up: [[fallthrough]];
- case Qt::Key_Down: [[fallthrough]];
- case Qt::Key_Tab: [[fallthrough]];
- case Qt::Key_Backtab:
- finishEditWithMove(kevent->key(), kevent->modifiers(), true);
- return true;
- // Also handle the delete key here:
- case Qt::Key_Delete:
- deleteSelection();
- return true;
- case Qt::Key_Escape:
- sheet->setCopyOrCutRanges({});
- return true;
- default:
- break;
+ case Qt::Key_Return:
+ [[fallthrough]];
+ case Qt::Key_Enter:
+ [[fallthrough]];
+ case Qt::Key_Home:
+ [[fallthrough]];
+ case Qt::Key_End:
+ [[fallthrough]];
+ case Qt::Key_Left:
+ [[fallthrough]];
+ case Qt::Key_Right:
+ [[fallthrough]];
+ case Qt::Key_Up:
+ [[fallthrough]];
+ case Qt::Key_Down:
+ [[fallthrough]];
+ case Qt::Key_Tab:
+ [[fallthrough]];
+ case Qt::Key_Backtab:
+ finishEditWithMove(kevent->key(), kevent->modifiers(), true);
+ return true;
+ // Also handle the delete key here:
+ case Qt::Key_Delete:
+ deleteSelection();
+ return true;
+ case Qt::Key_Escape:
+ sheet->setCopyOrCutRanges({});
+ return true;
+ default:
+ break;
}
if (kevent->matches(QKeySequence::Cut)) {
cutSelection();
@@ -574,21 +606,30 @@ bool SheetTableView::event(QEvent* event)
}
}
else if (event && event->type() == QEvent::ShortcutOverride) {
- QKeyEvent * kevent = static_cast(event);
- if (kevent->modifiers() == Qt::NoModifier ||
- kevent->modifiers() == Qt::ShiftModifier ||
- kevent->modifiers() == Qt::KeypadModifier) {
+ QKeyEvent* kevent = static_cast(event);
+ if (kevent->modifiers() == Qt::NoModifier || kevent->modifiers() == Qt::ShiftModifier
+ || kevent->modifiers() == Qt::KeypadModifier) {
switch (kevent->key()) {
- case Qt::Key_Return: [[fallthrough]];
- case Qt::Key_Enter: [[fallthrough]];
- case Qt::Key_Delete: [[fallthrough]];
- case Qt::Key_Home: [[fallthrough]];
- case Qt::Key_End: [[fallthrough]];
- case Qt::Key_Backspace: [[fallthrough]];
- case Qt::Key_Left: [[fallthrough]];
- case Qt::Key_Right: [[fallthrough]];
- case Qt::Key_Up: [[fallthrough]];
- case Qt::Key_Down: [[fallthrough]];
+ case Qt::Key_Return:
+ [[fallthrough]];
+ case Qt::Key_Enter:
+ [[fallthrough]];
+ case Qt::Key_Delete:
+ [[fallthrough]];
+ case Qt::Key_Home:
+ [[fallthrough]];
+ case Qt::Key_End:
+ [[fallthrough]];
+ case Qt::Key_Backspace:
+ [[fallthrough]];
+ case Qt::Key_Left:
+ [[fallthrough]];
+ case Qt::Key_Right:
+ [[fallthrough]];
+ case Qt::Key_Up:
+ [[fallthrough]];
+ case Qt::Key_Down:
+ [[fallthrough]];
case Qt::Key_Tab:
kevent->accept();
break;
@@ -636,7 +677,9 @@ void SheetTableView::deleteSelection()
std::vector::const_iterator i = ranges.begin();
for (; i != ranges.end(); ++i) {
- Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.clear('%s')", sheet->getNameInDocument(),
+ Gui::Command::doCommand(Gui::Command::Doc,
+ "App.ActiveDocument.%s.clear('%s')",
+ sheet->getNameInDocument(),
i->rangeString().c_str());
}
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
@@ -651,13 +694,13 @@ void SheetTableView::copySelection()
_copySelection(selectedRanges(), true);
}
-void SheetTableView::_copySelection(const std::vector &ranges, bool copy)
+void SheetTableView::_copySelection(const std::vector& ranges, bool copy)
{
int minRow = INT_MAX;
int maxRow = 0;
int minCol = INT_MAX;
int maxCol = 0;
- for (auto &range : ranges) {
+ for (auto& range : ranges) {
minRow = std::min(minRow, range.from().row());
maxRow = std::max(maxRow, range.to().row());
minCol = std::min(minCol, range.from().col());
@@ -665,23 +708,25 @@ void SheetTableView::_copySelection(const std::vector &ranges, bool
}
QString selectedText;
- for (int i=minRow; i<=maxRow; i++) {
- for (int j=minCol; j<=maxCol; j++) {
- QModelIndex index = model()->index(i,j);
+ for (int i = minRow; i <= maxRow; i++) {
+ for (int j = minCol; j <= maxCol; j++) {
+ QModelIndex index = model()->index(i, j);
QString cell = index.data(Qt::EditRole).toString();
- if (j < maxCol)
+ if (j < maxCol) {
cell.append(QChar::fromLatin1('\t'));
+ }
selectedText += cell;
}
- if (i < maxRow)
+ if (i < maxRow) {
selectedText.append(QChar::fromLatin1('\n'));
+ }
}
Base::StringWriter writer;
- sheet->getCells()->copyCells(writer,ranges);
- QMimeData *mime = new QMimeData();
+ sheet->getCells()->copyCells(writer, ranges);
+ QMimeData* mime = new QMimeData();
mime->setText(selectedText);
- mime->setData(_SheetMime,QByteArray(writer.getString().c_str()));
+ mime->setData(_SheetMime, QByteArray(writer.getString().c_str()));
QApplication::clipboard()->setMimeData(mime);
sheet->setCopyOrCutRanges(std::move(ranges), copy);
@@ -698,20 +743,22 @@ void SheetTableView::pasteClipboard()
try {
bool copy = true;
auto ranges = sheet->getCopyOrCutRange(copy);
- if(ranges.empty()) {
+ if (ranges.empty()) {
copy = false;
ranges = sheet->getCopyOrCutRange(copy);
}
- if(!ranges.empty())
+ if (!ranges.empty()) {
_copySelection(ranges, copy);
+ }
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
- if(!mimeData || !mimeData->hasText())
+ if (!mimeData || !mimeData->hasText()) {
return;
+ }
- if(!copy) {
- for(auto &range : ranges) {
+ if (!copy) {
+ for (auto& range : ranges) {
do {
sheet->clear(*range);
} while (range.next());
@@ -719,46 +766,51 @@ void SheetTableView::pasteClipboard()
}
ranges = selectedRanges();
- if(ranges.empty())
+ if (ranges.empty()) {
return;
+ }
Range range = ranges.back();
if (!mimeData->hasFormat(_SheetMime)) {
CellAddress current = range.from();
QString text = mimeData->text();
QStringList cells = text.split(QLatin1Char('\n'));
- int i=0;
+ int i = 0;
for (const auto& it : cells) {
QStringList cols = it.split(QLatin1Char('\t'));
- int j=0;
+ int j = 0;
for (const auto& jt : cols) {
- QModelIndex index = model()->index(current.row()+i, current.col()+j);
+ QModelIndex index = model()->index(current.row() + i, current.col() + j);
model()->setData(index, jt);
j++;
}
i++;
}
- }else{
+ }
+ else {
QByteArray res = mimeData->data(_SheetMime);
Base::ByteArrayIStreambuf buf(res);
std::istream in(nullptr);
in.rdbuf(&buf);
Base::XMLReader reader("", in);
- sheet->getCells()->pasteCells(reader,range);
+ sheet->getCells()->pasteCells(reader, range);
}
GetApplication().getActiveDocument()->recompute();
-
- }catch(Base::Exception &e) {
+ }
+ catch (Base::Exception& e) {
e.ReportException();
- QMessageBox::critical(Gui::getMainWindow(), QObject::tr("Copy & Paste failed"),
- QString::fromLatin1(e.what()));
+ QMessageBox::critical(Gui::getMainWindow(),
+ QObject::tr("Copy & Paste failed"),
+ QString::fromLatin1(e.what()));
return;
}
clearSelection();
}
-void SheetTableView::finishEditWithMove(int keyPressed, Qt::KeyboardModifiers modifiers, bool handleTabMotion)
+void SheetTableView::finishEditWithMove(int keyPressed,
+ Qt::KeyboardModifiers modifiers,
+ bool handleTabMotion)
{
// A utility lambda for finding the beginning and ending of data regions
auto scanForRegionBoundary = [this](int& r, int& c, int dr, int dc) {
@@ -797,119 +849,140 @@ void SheetTableView::finishEditWithMove(int keyPressed, Qt::KeyboardModifiers mo
int rowSpan;
sheet->getSpans(CellAddress(targetRow, targetColumn), rowSpan, colSpan);
switch (keyPressed) {
- case Qt::Key_Return:
- case Qt::Key_Enter:
- if (modifiers == Qt::NoModifier) {
- targetRow += rowSpan;
- targetColumn -= tabCounter;
- }
- else if (modifiers == Qt::ShiftModifier) {
- targetRow -= 1;
- targetColumn -= tabCounter;
- }
- else {
- // For an unrecognized modifier, just go down
- targetRow += rowSpan;
- }
- tabCounter = 0;
- break;
-
- case Qt::Key_Home:
- // Home: row 1, same column
- // Ctrl-Home: row 1, column 1
- targetRow = 0;
- if (modifiers == Qt::ControlModifier)
- targetColumn = 0;
- tabCounter = 0;
- break;
-
- case Qt::Key_End:
- {
- // End should take you to the last occupied cell in the current column
- // Ctrl-End takes you to the last cell in the sheet
- auto usedCells = sheet->getCells()->getNonEmptyCells();
- for (const auto& cell : usedCells) {
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
if (modifiers == Qt::NoModifier) {
- if (cell.col() == targetColumn)
- targetRow = std::max(targetRow, cell.row());
+ targetRow += rowSpan;
+ targetColumn -= tabCounter;
}
- else if (modifiers == Qt::ControlModifier) {
- targetRow = std::max(targetRow, cell.row());
- targetColumn = std::max(targetColumn, cell.col());
+ else if (modifiers == Qt::ShiftModifier) {
+ targetRow -= 1;
+ targetColumn -= tabCounter;
+ }
+ else {
+ // For an unrecognized modifier, just go down
+ targetRow += rowSpan;
}
- }
- tabCounter = 0;
- break;
- }
-
- case Qt::Key_Left:
- if (targetColumn == 0)
- break; // Nothing to do, we're already in the first column
- if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier)
- targetColumn--;
- else if (modifiers == Qt::ControlModifier ||
- modifiers == (Qt::ControlModifier | Qt::ShiftModifier))
- scanForRegionBoundary(targetRow, targetColumn, 0, -1);
- else
- targetColumn--; //Unrecognized modifier combination: default to just moving one cell
- tabCounter = 0;
- break;
- case Qt::Key_Right:
- if (targetColumn >= this->model()->columnCount() - 1)
- break; // Nothing to do, we're already in the last column
- if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier)
- targetColumn += colSpan;
- else if (modifiers == Qt::ControlModifier ||
- modifiers == (Qt::ControlModifier | Qt::ShiftModifier))
- scanForRegionBoundary(targetRow, targetColumn, 0, 1);
- else
- targetColumn += colSpan; //Unrecognized modifier combination: default to just moving one cell
- tabCounter = 0;
- break;
- case Qt::Key_Up:
- if (targetRow == 0)
- break; // Nothing to do, we're already in the first column
- if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier)
- targetRow--;
- else if (modifiers == Qt::ControlModifier ||
- modifiers == (Qt::ControlModifier | Qt::ShiftModifier))
- scanForRegionBoundary(targetRow, targetColumn, -1, 0);
- else
- targetRow--; //Unrecognized modifier combination: default to just moving one cell
- tabCounter = 0;
- break;
- case Qt::Key_Down:
- if (targetRow >= this->model()->rowCount() - 1)
- break; // Nothing to do, we're already in the last row
- if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier)
- targetRow += rowSpan;
- else if (modifiers == Qt::ControlModifier ||
- modifiers == (Qt::ControlModifier | Qt::ShiftModifier))
- scanForRegionBoundary(targetRow, targetColumn, 1, 0);
- else
- targetRow += rowSpan; //Unrecognized modifier combination: default to just moving one cell
- tabCounter = 0;
- break;
- case Qt::Key_Tab:
- if (modifiers == Qt::NoModifier) {
- tabCounter++;
- if (handleTabMotion)
- targetColumn += colSpan;
- }
- else if (modifiers == Qt::ShiftModifier) {
tabCounter = 0;
- if (handleTabMotion)
+ break;
+
+ case Qt::Key_Home:
+ // Home: row 1, same column
+ // Ctrl-Home: row 1, column 1
+ targetRow = 0;
+ if (modifiers == Qt::ControlModifier) {
+ targetColumn = 0;
+ }
+ tabCounter = 0;
+ break;
+
+ case Qt::Key_End: {
+ // End should take you to the last occupied cell in the current column
+ // Ctrl-End takes you to the last cell in the sheet
+ auto usedCells = sheet->getCells()->getNonEmptyCells();
+ for (const auto& cell : usedCells) {
+ if (modifiers == Qt::NoModifier) {
+ if (cell.col() == targetColumn) {
+ targetRow = std::max(targetRow, cell.row());
+ }
+ }
+ else if (modifiers == Qt::ControlModifier) {
+ targetRow = std::max(targetRow, cell.row());
+ targetColumn = std::max(targetColumn, cell.col());
+ }
+ }
+ tabCounter = 0;
+ break;
+ }
+
+ case Qt::Key_Left:
+ if (targetColumn == 0) {
+ break;// Nothing to do, we're already in the first column
+ }
+ if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier) {
targetColumn--;
- }
- break;
- case Qt::Key_Backtab:
- if (modifiers == Qt::NoModifier) {
- targetColumn--;
- }
- tabCounter = 0;
- break;
- default:
- break;
+ }
+ else if (modifiers == Qt::ControlModifier
+ || modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) {
+ scanForRegionBoundary(targetRow, targetColumn, 0, -1);
+ }
+ else {
+ targetColumn--;// Unrecognized modifier combination: default to just moving one cell
+ }
+ tabCounter = 0;
+ break;
+ case Qt::Key_Right:
+ if (targetColumn >= this->model()->columnCount() - 1) {
+ break;// Nothing to do, we're already in the last column
+ }
+ if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier) {
+ targetColumn += colSpan;
+ }
+ else if (modifiers == Qt::ControlModifier
+ || modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) {
+ scanForRegionBoundary(targetRow, targetColumn, 0, 1);
+ }
+ else {
+ targetColumn +=
+ colSpan;// Unrecognized modifier combination: default to just moving one cell
+ }
+ tabCounter = 0;
+ break;
+ case Qt::Key_Up:
+ if (targetRow == 0) {
+ break;// Nothing to do, we're already in the first column
+ }
+ if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier) {
+ targetRow--;
+ }
+ else if (modifiers == Qt::ControlModifier
+ || modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) {
+ scanForRegionBoundary(targetRow, targetColumn, -1, 0);
+ }
+ else {
+ targetRow--;// Unrecognized modifier combination: default to just moving one cell
+ }
+ tabCounter = 0;
+ break;
+ case Qt::Key_Down:
+ if (targetRow >= this->model()->rowCount() - 1) {
+ break;// Nothing to do, we're already in the last row
+ }
+ if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier) {
+ targetRow += rowSpan;
+ }
+ else if (modifiers == Qt::ControlModifier
+ || modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) {
+ scanForRegionBoundary(targetRow, targetColumn, 1, 0);
+ }
+ else {
+ targetRow +=
+ rowSpan;// Unrecognized modifier combination: default to just moving one cell
+ }
+ tabCounter = 0;
+ break;
+ case Qt::Key_Tab:
+ if (modifiers == Qt::NoModifier) {
+ tabCounter++;
+ if (handleTabMotion) {
+ targetColumn += colSpan;
+ }
+ }
+ else if (modifiers == Qt::ShiftModifier) {
+ tabCounter = 0;
+ if (handleTabMotion) {
+ targetColumn--;
+ }
+ }
+ break;
+ case Qt::Key_Backtab:
+ if (modifiers == Qt::NoModifier) {
+ targetColumn--;
+ }
+ tabCounter = 0;
+ break;
+ default:
+ break;
}
if (this->sheet->isMergedCell(CellAddress(targetRow, targetColumn))) {
@@ -924,16 +997,18 @@ void SheetTableView::finishEditWithMove(int keyPressed, Qt::KeyboardModifiers mo
targetRow = std::max(0, std::min(targetRow, maxRow));
targetColumn = std::max(0, std::min(targetColumn, maxCol));
- if (!(modifiers & Qt::ShiftModifier) || keyPressed == Qt::Key_Tab || keyPressed == Qt::Key_Enter || keyPressed == Qt::Key_Return) {
- // We have to use this method so that Ctrl-modifier combinations don't result in multiple selection
+ if (!(modifiers & Qt::ShiftModifier) || keyPressed == Qt::Key_Tab || keyPressed == Qt::Key_Enter
+ || keyPressed == Qt::Key_Return) {
+ // We have to use this method so that Ctrl-modifier combinations don't result in multiple
+ // selection
this->selectionModel()->setCurrentIndex(model()->index(targetRow, targetColumn),
- QItemSelectionModel::ClearAndSelect);
+ QItemSelectionModel::ClearAndSelect);
}
else if (modifiers & Qt::ShiftModifier) {
- // With shift down, this motion becomes a block selection command, rather than just simple motion:
+ // With shift down, this motion becomes a block selection command, rather than just simple
+ // motion:
ModifyBlockSelection(targetRow, targetColumn);
}
-
}
void SheetTableView::ModifyBlockSelection(int targetRow, int targetCol)
@@ -945,23 +1020,29 @@ void SheetTableView::ModifyBlockSelection(int targetRow, int targetCol)
auto selection = this->selectionModel()->selection();
for (const auto& range : selection) {
if (range.contains(currentIndex())) {
- // This range contains the current cell, so it's the one we're going to modify (assuming we're at one of the corners)
+ // This range contains the current cell, so it's the one we're going to modify (assuming
+ // we're at one of the corners)
int rangeMinRow = range.top();
int rangeMaxRow = range.bottom();
int rangeMinCol = range.left();
int rangeMaxCol = range.right();
- if ((startingRow == rangeMinRow || startingRow == rangeMaxRow) &&
- (startingCol == rangeMinCol || startingCol == rangeMaxCol)) {
+ if ((startingRow == rangeMinRow || startingRow == rangeMaxRow)
+ && (startingCol == rangeMinCol || startingCol == rangeMaxCol)) {
if (range.contains(model()->index(targetRow, targetCol))) {
- // If the range already contains the target cell, then we're making the range smaller
- if (startingRow == rangeMinRow)
+ // If the range already contains the target cell, then we're making the range
+ // smaller
+ if (startingRow == rangeMinRow) {
rangeMinRow = targetRow;
- if (startingRow == rangeMaxRow)
+ }
+ if (startingRow == rangeMaxRow) {
rangeMaxRow = targetRow;
- if (startingCol == rangeMinCol)
+ }
+ if (startingCol == rangeMinCol) {
rangeMinCol = targetCol;
- if (startingCol == rangeMaxCol)
+ }
+ if (startingCol == rangeMaxCol) {
rangeMaxCol = targetCol;
+ }
}
else {
// We're making the range bigger
@@ -972,25 +1053,29 @@ void SheetTableView::ModifyBlockSelection(int targetRow, int targetCol)
}
QItemSelection oldRange(range.topLeft(), range.bottomRight());
this->selectionModel()->select(oldRange, QItemSelectionModel::Deselect);
- QItemSelection newRange(model()->index(rangeMinRow, rangeMinCol), model()->index(rangeMaxRow, rangeMaxCol));
+ QItemSelection newRange(model()->index(rangeMinRow, rangeMinCol),
+ model()->index(rangeMaxRow, rangeMaxCol));
this->selectionModel()->select(newRange, QItemSelectionModel::Select);
}
break;
}
}
- this->selectionModel()->setCurrentIndex(model()->index(targetRow, targetCol), QItemSelectionModel::Current);
+ this->selectionModel()->setCurrentIndex(model()->index(targetRow, targetCol),
+ QItemSelectionModel::Current);
}
-void SheetTableView::mergeCells() {
+void SheetTableView::mergeCells()
+{
Gui::Application::Instance->commandManager().runCommandByName("Spreadsheet_MergeCells");
}
-void SheetTableView::splitCell() {
+void SheetTableView::splitCell()
+{
Gui::Application::Instance->commandManager().runCommandByName("Spreadsheet_SplitCell");
}
-void SheetTableView::closeEditor(QWidget * editor, QAbstractItemDelegate::EndEditHint hint)
+void SheetTableView::closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint)
{
QTableView::closeEditor(editor, hint);
}
@@ -1001,19 +1086,20 @@ void SheetTableView::mousePressEvent(QMouseEvent* event)
QTableView::mousePressEvent(event);
}
-void SheetTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+void SheetTableView::selectionChanged(const QItemSelection& selected,
+ const QItemSelection& deselected)
{
Gui::getMainWindow()->updateActions();
QTableView::selectionChanged(selected, deselected);
}
-void SheetTableView::edit ( const QModelIndex & index )
+void SheetTableView::edit(const QModelIndex& index)
{
currentEditIndex = index;
QTableView::edit(index);
}
-void SheetTableView::contextMenuEvent(QContextMenuEvent *)
+void SheetTableView::contextMenuEvent(QContextMenuEvent*)
{
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
if (!selectionModel()->hasSelection()) {
@@ -1029,13 +1115,14 @@ void SheetTableView::contextMenuEvent(QContextMenuEvent *)
actionCut->setEnabled(true);
actionCopy->setEnabled(true);
actionDel->setEnabled(true);
- actionSplit->setEnabled(selectedIndexesRaw().size() == 1 &&
- sheet->isMergedCell(CellAddress(currentIndex().row(),currentIndex().column())));
+ actionSplit->setEnabled(
+ selectedIndexesRaw().size() == 1
+ && sheet->isMergedCell(CellAddress(currentIndex().row(), currentIndex().column())));
actionMerge->setEnabled(selectedIndexesRaw().size() > 1);
}
auto ranges = selectedRanges();
- actionBind->setEnabled(!ranges.empty() && ranges.size()<=2);
+ actionBind->setEnabled(!ranges.empty() && ranges.size() <= 2);
contextMenu->exec(QCursor::pos());
}
@@ -1076,11 +1163,11 @@ QString SheetTableView::toHtml() const
QTextCharFormat bgFormat;
bgFormat.setBackground(QBrush(bgColor));
- QTextTable *table = cursor.insertTable(rowCount + 2, colCount + 2, tableFormat);
+ QTextTable* table = cursor.insertTable(rowCount + 2, colCount + 2, tableFormat);
// The header cells of the rows
for (int row = 0; row < rowCount + 1; row++) {
- QTextTableCell headerCell = table->cellAt(row+1, 0);
+ QTextTableCell headerCell = table->cellAt(row + 1, 0);
headerCell.setFormat(bgFormat);
QTextCursor headerCellCursor = headerCell.firstCursorPosition();
QString data = model()->headerData(row, Qt::Vertical).toString();
@@ -1089,7 +1176,7 @@ QString SheetTableView::toHtml() const
// The header cells of the columns
for (int col = 0; col < colCount + 1; col++) {
- QTextTableCell headerCell = table->cellAt(0, col+1);
+ QTextTableCell headerCell = table->cellAt(0, col + 1);
headerCell.setFormat(bgFormat);
QTextCursor headerCellCursor = headerCell.firstCursorPosition();
QTextBlockFormat blockFormat = headerCellCursor.blockFormat();
diff --git a/src/Mod/Spreadsheet/Gui/SheetTableView.h b/src/Mod/Spreadsheet/Gui/SheetTableView.h
index 311df2852b..974011630a 100644
--- a/src/Mod/Spreadsheet/Gui/SheetTableView.h
+++ b/src/Mod/Spreadsheet/Gui/SheetTableView.h
@@ -30,34 +30,39 @@
#include
-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 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 &ranges, bool copy);
+ void _copySelection(const std::vector& 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 spanChanges;
};
-}
+}// namespace SpreadsheetGui
-#endif // SHEETTABLEVIEW_H
+#endif// SHEETTABLEVIEW_H
diff --git a/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.cpp b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.cpp
index eec525e35c..9caff067fd 100644
--- a/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.cpp
+++ b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.cpp
@@ -24,65 +24,67 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include
-# include
-# include
-# include
-# include
-# include
-# include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#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(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(obj));
+ }
+ return nullptr;
+}
+}// namespace SpreadsheetGui
diff --git a/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.h b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.h
index fa63c52e58..51e1a3c3b1 100644
--- a/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.h
+++ b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.h
@@ -27,32 +27,33 @@
#include
#include
-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
diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp b/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp
index 862d9ebe81..f0ae0de079 100644
--- a/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp
+++ b/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp
@@ -25,16 +25,16 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include
-# include
+#include
+#include
#endif
#include
#include
#include
-#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(editor);
+ QLineEdit* edit = qobject_cast(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(editor);
+ QLineEdit* edit = qobject_cast(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"
-
diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.h b/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.h
index c05f761279..d09fb99cc2 100644
--- a/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.h
+++ b/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.h
@@ -27,35 +27,42 @@
#include
-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
diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp
index c4586c4602..1a7a6da151 100644
--- a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp
+++ b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp
@@ -23,12 +23,12 @@
#include "PreCompiled.h"
#ifndef _PreComp_
-# include
-# include
-# include
-# include
-# include
-# include
+#include
+#include
+#include