[qet] [1546] Title block template editor: the "Merge cells" and "Splti cell" actions are now enabled and disabled depending on what is currently selected . |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
- To: qet@xxxxxxxxxxxxxxxxxxx
- Subject: [qet] [1546] Title block template editor: the "Merge cells" and "Splti cell" actions are now enabled and disabled depending on what is currently selected .
- From: subversion@xxxxxxxxxxxxx
- Date: Sun, 04 Mar 2012 19:27:37 +0100
Revision: 1546
Author: xavier
Date: 2012-03-04 19:27:37 +0100 (Sun, 04 Mar 2012)
Log Message:
-----------
Title block template editor: the "Merge cells" and "Splti cell" actions are now enabled and disabled depending on what is currently selected.
Modified Paths:
--------------
branches/0.3/sources/titleblock/qettemplateeditor.cpp
branches/0.3/sources/titleblock/templatecommands.cpp
branches/0.3/sources/titleblock/templatecommands.h
branches/0.3/sources/titleblock/templateview.cpp
branches/0.3/sources/titleblock/templateview.h
Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp 2012-03-04 17:42:25 UTC (rev 1545)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp 2012-03-04 18:27:37 UTC (rev 1546)
@@ -499,6 +499,7 @@
} else {
template_cell_editor_widget_ -> setVisible(false);
}
+ updateActions();
}
/**
@@ -561,10 +562,15 @@
adequate actions.
*/
void QETTitleBlockTemplateEditor::updateActions() {
- /// TODO complete this method
save_ -> setEnabled(!read_only_);
- merge_cells_ -> setEnabled(!read_only_);
- split_cell_ -> setEnabled(!read_only_);
+
+ bool can_merge;
+ bool can_split;
+ if (!read_only_) {
+ template_edition_area_view_ -> analyzeSelectedCells(&can_merge, &can_split);
+ }
+ merge_cells_ -> setEnabled(!read_only_ && can_merge);
+ split_cell_ -> setEnabled(!read_only_ && can_split);
}
/**
Modified: branches/0.3/sources/titleblock/templatecommands.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatecommands.cpp 2012-03-04 17:42:25 UTC (rev 1545)
+++ branches/0.3/sources/titleblock/templatecommands.cpp 2012-03-04 18:27:37 UTC (rev 1546)
@@ -577,8 +577,7 @@
row_span_after_(-1),
col_span_after_(-1)
{
- // basic check
- if (merged_cells.count() < 2) return;
+ if (!canMerge(merged_cells, tbtemplate)) return;
// the spanning cell is the top left cell
TitleBlockTemplateVisualCell *top_left_cell = merged_cells.topLeftCell();
@@ -618,6 +617,25 @@
}
/**
+ @param merged_cells Cell sto be merged.
+ @param tbtemplate Modified title block template.
+ @return true if the merge is feasible, false otherwise
+*/
+bool MergeCellsCommand::canMerge(const TitleBlockTemplateCellsSet &merged_cells, TitleBlockTemplate *tbtemplate) {
+ // basic checks
+ if (!merged_cells.isRectangle()) return(false);
+ if (merged_cells.count() < 2) return(false);
+
+ // the spanning cell is the top left cell
+ TitleBlockTemplateVisualCell *top_left_cell = merged_cells.topLeftCell();
+ if (!top_left_cell || !top_left_cell -> cell()) return(false);
+
+ if (!getBottomRightCell(merged_cells)) return(false);
+
+ return(true);
+}
+
+/**
@return true if this command object is valid and usable, false otherwise.
*/
bool MergeCellsCommand::isValid() const {
@@ -703,17 +721,10 @@
row_span_before_(-1),
col_span_before_(-1)
{
- // basic check: the command applies to a single visual cell only
- if (splitted_cells.count() != 1) return;
+ if (!canSplit(splitted_cells, tbtemplate)) return;
- // fetch the spanning cell
+ // retrieve values necessary for the undo operation
spanning_cell_ = splitted_cells.first() -> cell();
- if (!spanning_cell_) return;
-
- // ensure the cell spans over other cells and therefore can be splitted
- if (!spanning_cell_ -> spans()) return;
-
- // retrieve values necessary for the undo operation
spanned_cells_ = tbtemplate_ -> spannedCells(spanning_cell_);
row_span_before_ = spanning_cell_ -> row_span;
col_span_before_ = spanning_cell_ -> col_span;
@@ -735,6 +746,27 @@
}
/**
+ @param splitted_cells Cell to be splitted.
+ @param tbtemplate Modified title block template.
+ @return true if the split is feasible, false otherwise
+*/
+bool SplitCellsCommand::canSplit(const TitleBlockTemplateCellsSet &splitted_cells, TitleBlockTemplate *tbtemplate) {
+ Q_UNUSED(tbtemplate)
+
+ // basic check: the command applies to a single visual cell only
+ if (splitted_cells.count() != 1) return(false);
+
+ // fetch the spanning cell
+ TitleBlockCell *spanning_cell = splitted_cells.first() -> cell();
+ if (!spanning_cell) return(false);
+
+ // ensure the cell spans over other cells and therefore can be splitted
+ if (!spanning_cell -> spans()) return(false);
+
+ return(true);
+}
+
+/**
@return true if this command object is valid and usable, false otherwise.
*/
bool SplitCellsCommand::isValid() const {
Modified: branches/0.3/sources/titleblock/templatecommands.h
===================================================================
--- branches/0.3/sources/titleblock/templatecommands.h 2012-03-04 17:42:25 UTC (rev 1545)
+++ branches/0.3/sources/titleblock/templatecommands.h 2012-03-04 18:27:37 UTC (rev 1546)
@@ -180,6 +180,7 @@
// methods
public:
+ static bool canMerge(const TitleBlockTemplateCellsSet &, TitleBlockTemplate *);
bool isValid() const;
virtual void undo();
virtual void redo();
@@ -210,6 +211,7 @@
// methods
public:
+ static bool canSplit(const TitleBlockTemplateCellsSet &splitted_cells, TitleBlockTemplate *tbtemplate);
bool isValid() const;
virtual void undo();
virtual void redo();
Modified: branches/0.3/sources/titleblock/templateview.cpp
===================================================================
--- branches/0.3/sources/titleblock/templateview.cpp 2012-03-04 17:42:25 UTC (rev 1545)
+++ branches/0.3/sources/titleblock/templateview.cpp 2012-03-04 18:27:37 UTC (rev 1546)
@@ -251,19 +251,6 @@
// retrieve the selected cells
TitleBlockTemplateCellsSet selected_cells = selectedCellsSet();
- // merging applies only to cells composing a rectangle
- if (!selected_cells.isRectangle()) {
- qDebug() << "selected cells are not composing a rectangle";
- return;
- }
-
- // the merge area may also be too small
- if (selected_cells.count() < 2) {
- qDebug() << "the merge area does not even contain 2 selected and mergeable cells";
- return;
- }
-
- qDebug() << Q_FUNC_INFO << "ok, ready for cells merge";
MergeCellsCommand *merge_command = new MergeCellsCommand(selected_cells, tbtemplate_);
if (merge_command -> isValid()) requestGridModification(merge_command);
}
@@ -275,12 +262,6 @@
// retrieve the selected cells
TitleBlockTemplateCellsSet selected_cells = selectedCellsSet();
- // we expect only one visual cell to be selected
- if (selected_cells.count() != 1) {
- qDebug() << "please select a single cell";
- return;
- }
-
SplitCellsCommand *split_command = new SplitCellsCommand(selected_cells, tbtemplate_);
if (split_command -> isValid()) requestGridModification(split_command);
}
@@ -320,6 +301,30 @@
}
/**
+ @param can_merge If non-zero, will be changed to reflect whether selected cells may be merged
+ @param can_merge If non-zero, will be changed to reflect whether selected cells may be splitted
+*/
+void TitleBlockTemplateView::analyzeSelectedCells(bool *can_merge, bool *can_split) {
+ if (!can_merge && !can_split) return;
+
+ if (!tbtemplate_) {
+ if (can_merge) *can_merge = false;
+ if (can_split) *can_split = false;
+ return;
+ }
+
+ // retrieve the selected cells
+ TitleBlockTemplateCellsSet selected_cells = selectedCellsSet();
+
+ if (can_merge) {
+ *can_merge = MergeCellsCommand::canMerge(selected_cells, tbtemplate_);
+ }
+ if (can_split) {
+ *can_split = SplitCellsCommand::canSplit(selected_cells, tbtemplate_);
+ }
+}
+
+/**
@return the current size of the rendered title block template
*/
QSizeF TitleBlockTemplateView::templateSize() const {
Modified: branches/0.3/sources/titleblock/templateview.h
===================================================================
--- branches/0.3/sources/titleblock/templateview.h 2012-03-04 17:42:25 UTC (rev 1545)
+++ branches/0.3/sources/titleblock/templateview.h 2012-03-04 18:27:37 UTC (rev 1546)
@@ -46,6 +46,7 @@
virtual QList<TitleBlockCell *> selectedCells() const;
virtual TitleBlockTemplateCellsSet selectedCellsSet() const;
virtual TitleBlockTemplateCellsSet cells(const QRectF &) const;
+ virtual void analyzeSelectedCells(bool *, bool *);
virtual QSizeF templateSize() const;
virtual qreal templateWidth() const;
virtual qreal templateHeight() const;