Skip to content

Commit 2bf445f

Browse files
committed
Remove repeated code, remove TODOs
Signed-off-by: Danilo Aimini <[email protected]>
1 parent 9012675 commit 2bf445f

File tree

2 files changed

+63
-62
lines changed

2 files changed

+63
-62
lines changed

Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.cpp

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,41 @@ namespace AzToolsFramework
196196
return { (m_enforceMinWidth ? cumulativeWidth : 0), minimumHeight };
197197
}
198198

199+
void DPELayout::CloseColumn(
200+
QHBoxLayout* currentColumnLayout,
201+
QRect& itemGeometry,
202+
int& currentColumnCount,
203+
const int columnWidth,
204+
bool allWidgetsUnstretched,
205+
bool startSpacer,
206+
bool endSpacer
207+
)
208+
{
209+
// if all widgets in this shared column take up only their minimum width, set the appropriate alignment with spacers
210+
if (allWidgetsUnstretched)
211+
{
212+
if (startSpacer)
213+
{
214+
currentColumnLayout->insertSpacerItem(0, new QSpacerItem(columnWidth, 1, QSizePolicy::Expanding, QSizePolicy::Fixed));
215+
}
216+
if (endSpacer)
217+
{
218+
currentColumnLayout->addSpacerItem(new QSpacerItem(columnWidth, 1, QSizePolicy::Expanding, QSizePolicy::Fixed));
219+
}
220+
}
221+
222+
// Correctly set the geometry based on the column.
223+
if (currentColumnCount > 0)
224+
{
225+
itemGeometry.setLeft(itemGeometry.right() + 1);
226+
itemGeometry.setRight(itemGeometry.left() + columnWidth);
227+
}
228+
currentColumnLayout->setGeometry(itemGeometry);
229+
230+
// Count completed columns.
231+
++currentColumnCount;
232+
}
233+
199234
void DPELayout::setGeometry(const QRect& rect)
200235
{
201236
QLayout::setGeometry(rect);
@@ -310,34 +345,15 @@ namespace AzToolsFramework
310345
// Close previous column.
311346
if (!isFirstColumn)
312347
{
313-
// if all widgets in this shared column take up only their minimum width, set the appropriate alignment with spacers
314-
if (currentColumnNonStretchedWidgetsCount == currentColumnWidgetsCount)
315-
{
316-
QSpacerItem* spacer = new QSpacerItem(columnWidth, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
317-
if (startSpacer)
318-
{
319-
currentColumnLayout->insertSpacerItem(0, spacer);
320-
}
321-
if (endSpacer)
322-
{
323-
currentColumnLayout->addSpacerItem(spacer);
324-
}
325-
}
326-
327-
// Correctly set the geometry based on the column.
328-
if (currentColumnCount == 0)
329-
{
330-
currentColumnLayout->setGeometry(itemGeometry);
331-
}
332-
else
333-
{
334-
itemGeometry.setLeft(itemGeometry.right() + 1);
335-
itemGeometry.setRight(itemGeometry.left() + columnWidth);
336-
currentColumnLayout->setGeometry(itemGeometry);
337-
}
338-
339-
// Count completed columns.
340-
++currentColumnCount;
348+
CloseColumn(
349+
currentColumnLayout,
350+
itemGeometry,
351+
currentColumnCount,
352+
columnWidth,
353+
(currentColumnNonStretchedWidgetsCount == currentColumnWidgetsCount),
354+
startSpacer,
355+
endSpacer
356+
);
341357
}
342358

343359
// Create new column.
@@ -370,38 +386,15 @@ namespace AzToolsFramework
370386
}
371387

372388
// Close the last column
373-
// TODO - Avoid repeated code...
374-
// TODO - Check for edge cases of already closed column just in case...
375-
{
376-
// if all widgets in this shared column take up only their minimum width, set the appropriate alignment with spacers
377-
if (currentColumnNonStretchedWidgetsCount == currentColumnWidgetsCount)
378-
{
379-
QSpacerItem* spacer = new QSpacerItem(columnWidth, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
380-
if (startSpacer)
381-
{
382-
currentColumnLayout->insertSpacerItem(0, spacer);
383-
}
384-
if (endSpacer)
385-
{
386-
currentColumnLayout->addSpacerItem(spacer);
387-
}
388-
}
389-
390-
// Correctly set the geometry based on the column.
391-
if (currentColumnCount == 0)
392-
{
393-
currentColumnLayout->setGeometry(itemGeometry);
394-
}
395-
else
396-
{
397-
itemGeometry.setLeft(itemGeometry.right() + 1);
398-
itemGeometry.setRight(itemGeometry.left() + columnWidth);
399-
currentColumnLayout->setGeometry(itemGeometry);
400-
}
401-
402-
// Count completed columns.
403-
++currentColumnCount;
404-
}
389+
CloseColumn(
390+
currentColumnLayout,
391+
itemGeometry,
392+
currentColumnCount,
393+
columnWidth,
394+
(currentColumnNonStretchedWidgetsCount == currentColumnWidgetsCount),
395+
startSpacer,
396+
endSpacer
397+
);
405398
}
406399

407400
Qt::Orientations DPELayout::expandingDirections() const
@@ -942,8 +935,6 @@ namespace AzToolsFramework
942935
childWidget->hide();
943936
m_columnLayout->removeWidget(childWidget);
944937
DocumentPropertyEditor::ReleaseHandler(handlerInfo);
945-
// TODO - Check if we still need something here!
946-
//m_columnLayout->RemoveSharePriorColumn(childIndex);
947938

948939
// Replace the existing handler widget with one appropriate for the new type
949940
auto replacementWidget = theDPE->CreateWidgetForHandler(handlerId, valueAtSubPath);

Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ namespace AzToolsFramework
8080
AZStd::unordered_set<size_t> m_columnStarts;
8181

8282
private:
83+
void CloseColumn(
84+
QHBoxLayout* currentColumnLayout,
85+
QRect& itemGeometry,
86+
int& currentColumnCount,
87+
const int columnWidth,
88+
bool allWidgetsUnstretched,
89+
bool startSpacer,
90+
bool endSpacer
91+
);
92+
8393
// These cached sizes must be mutable since they are set inside of an overidden const function
8494
mutable QSize m_cachedLayoutSize;
8595
mutable QSize m_cachedMinLayoutSize;

0 commit comments

Comments
 (0)