Skip to content

Commit

Permalink
More useful names for exported data tabs (#77)
Browse files Browse the repository at this point in the history
Instead of naming all exported tabs simply `exported data`,
provide more meaningful tab names.
  • Loading branch information
vogelsgesang authored Nov 23, 2017
1 parent c1a42c2 commit 4c63f8f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,23 @@ enum COL : short {
Value
};

inline const char* GetColumnName(COL column) {
switch (column) {
case ID: return "ID";
case File: return "File";
case Time: return "Time";
case Elapsed: return "Elapsed";
case PID: return "PID";
case TID: return "TID";
case Severity: return "Severity";
case Request: return "Request";
case Session: return "Session";
case Site: return "Site";
case User: return "User";
case Key: return "Key";
case Value: return "Value";
}
return "unknown column";
}

#endif // COLUMN_H
11 changes: 9 additions & 2 deletions src/logtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,18 +818,25 @@ void LogTab::ExportToNewTab()
std::sort(idxList.begin(), idxList.end(), [](QModelIndex a, QModelIndex b) {
return a.row() < b.row();
});
emit exportToTab(idxList);
emit exportToTab(idxList,"exported data");
}

void LogTab::ExportToNewTab(COL column)
{
// Generate the list of selected values
auto selectionList = ui->treeView->selectionModel()->selectedRows();
QSet<QString> exportedValues;
for (const auto& selected : selectionList) {
QString value = selected.model()->index(selected.row(), column, selected.parent()).data().toString();
exportedValues.insert(value);
}

// Build the name for the new tab
QStringList sortedValues=QStringList::fromSet(exportedValues);
sortedValues.sort();
QString name = QString(GetColumnName(column)) + " " + sortedValues.join(",");

// Generate the index list
const int count = m_treeModel->rowCount();
const QModelIndex root;
QModelIndexList exportedIdxList;
Expand All @@ -842,7 +849,7 @@ void LogTab::ExportToNewTab(COL column)
}
}

emit exportToTab(exportedIdxList);
emit exportToTab(exportedIdxList, name);
}

void LogTab::OpenSelectedFile()
Expand Down
2 changes: 1 addition & 1 deletion src/logtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private slots:

signals:
void menuUpdateNeeded();
void exportToTab(QModelIndexList list);
void exportToTab(QModelIndexList list, QString name);
void openFile(QString);
};

Expand Down
6 changes: 4 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ EventListPtr MainWindow::GetEventsFromFile(QString path, int & skippedCount)
return events;
}

void MainWindow::ExportEventsToTab(QModelIndexList list)
void MainWindow::ExportEventsToTab(QModelIndexList list, QString name)
{
auto events = std::make_shared<EventList>();
TreeModel * model = GetCurrentTreeModel();
Expand Down Expand Up @@ -334,7 +334,9 @@ void MainWindow::ExportEventsToTab(QModelIndexList list)
actionTail_current_tab->setEnabled(false);
connect(logTab, &LogTab::menuUpdateNeeded, this, &MainWindow::UpdateMenuAndStatusBar);
connect(logTab, &LogTab::exportToTab, this, &MainWindow::ExportEventsToTab);
int idx = tabWidget->addTab(logTab, "exported data");
QString shortName = name.size() < 30 ? name : (name.left(27) + "...");
int idx = tabWidget->addTab(logTab, shortName);
tabWidget->setTabToolTip(idx, name);
tabWidget->setCurrentIndex(idx);
logTab->setFocus();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private slots:
void Recent_files_triggered(QAction * action);
void UpdateTheme();
void UpdateMenuAndStatusBar();
void ExportEventsToTab(QModelIndexList list);
void ExportEventsToTab(QModelIndexList list, QString name);
bool LoadLogFile(QString);

//Slots use underscores as per QT's automatic connection syntax
Expand Down

0 comments on commit 4c63f8f

Please sign in to comment.