1#include "HistoryTreeWidget.h"
6#include "ProgressBar.h"
21 headers.append(
"Operation");
22 headers.append(
"Progress");
23 headers.append(
"Time Executed");
25 setHeaderLabels(headers);
27 connect(m_project, SIGNAL(workOrderStarting(
WorkOrder *)),
29 connect(m_project, SIGNAL(projectLoaded(
Project *)),
31 connect(m_project->
undoStack(), SIGNAL(indexChanged(
int)),
60 QFontMetrics metrics(invisibleRootItem()->font(1));
61 int dateTimeColumnWidth = qRound(metrics.horizontalAdvance(QDateTime::currentDateTime().toString()) * 1.10);
63 int progressBarColumnWidth = 200;
67 int operationColumnWidth = width() - dateTimeColumnWidth - progressBarColumnWidth - 12;
69 if (operationColumnWidth > 0) {
71 result = operationColumnWidth;
73 result = progressBarColumnWidth;
75 result = dateTimeColumnWidth;
87 resizeColumnToContents(0);
88 resizeColumnToContents(1);
89 resizeColumnToContents(2);
97 updateStatus(workOrder);
109 QString data = workOrder->bestText();
112 connect(workOrder, SIGNAL(destroyed(
QObject *)),
116 columnData.append(data);
117 columnData.append(
"");
118 columnData.append(workOrder->executionTime().toString());
121 newItem->setData(0, Qt::UserRole, QVariant::fromValue(workOrder));
124 if (workOrder->createsCleanState() || !workOrder->isUndoable()) {
125 QFont saveFont = newItem->font(0);
126 saveFont.setBold(
true);
127 saveFont.setItalic(
true);
128 newItem->setFont(0, saveFont);
129 newItem->setForeground(0, Qt::gray);
133 QFont progressFont = newItem->font(1);
134 progressFont.setItalic(
true);
135 newItem->setFont(1, progressFont);
136 newItem->setForeground(1, Qt::gray);
138 this->insertTopLevelItem(0, newItem);
140 connect(workOrder, SIGNAL(statusChanged(
WorkOrder *)),
142 connect(workOrder, SIGNAL(creatingProgress(
WorkOrder *)),
144 connect(workOrder, SIGNAL(deletingProgress(
WorkOrder *)),
152 if(workOrder->progressBar() ) {
153 this->setItemWidget(newItem, 1, workOrder->progressBar() );
155 scrollToItem(newItem);
167 QString data = historyEntry;
170 columnData.append(data);
176 QFont progressFont = newItem->font(1);
177 progressFont.setItalic(
true);
178 newItem->setFont(1, progressFont);
179 newItem->setForeground(1, Qt::gray);
181 this->insertTopLevelItem(0, newItem);
192 scrollToItem(newItem);
206 if( !m_project->clearing() ){
207 for (
int i = 0; i < invisibleRootItem()->childCount(); i++) {
209 if (item->data(0, Qt::UserRole).toString() !=
"") {
211 if (workOrder && itemWidget(item, 1) != workOrder->progressBar()) {
212 setItemWidget(item, 1, workOrder->progressBar());
228 treeItem->setForeground(0, Qt::black);
229 updateStatus(treeItem);
242 treeItem->setForeground(0, Qt::gray);
243 updateStatus(treeItem);
253 m_project->
undoStack()->command(newIndex - 1));
261 scrollToItem(prevItem);
262 scrollToItem(curItem);
274 int indexToDelete = invisibleRootItem()->indexOfChild(itemToRemove);
275 if (indexToDelete < invisibleRootItem()->childCount()) {
278 setItemWidget(invisibleRootItem()->child(indexToDelete), 1, NULL);
281 delete invisibleRootItem()->takeChild(indexToDelete);
297 for (
int i = invisibleRootItem()->childCount() - 1; !result && i >= 0; i--) {
299 if (item->data(0, Qt::UserRole).toString() !=
"" ) {
302 if (undoCommand == workOrder)
328 void HistoryTreeWidget::updateStatus(
WorkOrder *workOrder) {
void updateProgressWidgets()
We need to manually manage these progress widgets because QTreeWidget does a poor job of it.
void handleUndoIndexChanged(int)
The project's undo stack has changed.
void showHistory()
This resets the tree widget and re-initializes.
virtual ~HistoryTreeWidget()
Clean up allocated memory.
void markNotUndone(QTreeWidgetItem *)
Display the item as not an item that has been undone - it's working or done.
void addToHistory(QString historyEntry)
Add a non-workorder history to the display.
int sizeHintForColumn(int column) const
Get the preferred size of a given column.
QTreeWidgetItem * undoCommandToTreeItem(const QUndoCommand *)
Get the QTreeWidgetItem associated with the given undo command (work order).
void removeFromHistory(QObject *)
A work order was lost... compensate by removing it from the tree.
void markUndone(QTreeWidgetItem *)
Display the item as an item that has been undone.
HistoryTreeWidget(Project *project, QWidget *parent=0)
Construct a history tree widget.
void refit()
This resizes the columns to an okay width for viewing all of the data cleanly.
The main project for ipce.
QUndoStack * undoStack()
Returns the Projects stack of QUndoCommands.
QList< WorkOrder * > workOrderHistory()
Get the entire list of work orders that have executed.
Provide Undo/redo abilities, serialization, and history for an operation.
This is free and unencumbered software released into the public domain.