19 #include <QHeaderView>
20 #include <QMessageBox>
21 #include <QTableWidgetItem>
24 : QDialog(parent, f), m_TableModel(nullptr), m_SortModel(this)
28 QObject::connect(addButton, SIGNAL(clicked()),
this, SLOT(
addPreset()));
29 QObject::connect(removeButton, SIGNAL(clicked()),
this, SLOT(
removePreset()));
30 QObject::connect(changeButton, SIGNAL(clicked()),
this, SLOT(
changePreset()));
32 QObject::connect(presetView->horizontalHeader(), SIGNAL(sectionClicked(
int)),
this, SLOT(
sortPresets(
int)));
34 presetView->verticalHeader()->setVisible(
false);
35 presetView->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
47 static Qt::SortOrder order[3] = {Qt::AscendingOrder};
49 presetView->sortByColumn(index, order[index]);
50 if (order[index] == Qt::AscendingOrder)
51 order[index] = Qt::DescendingOrder;
53 order[index] = Qt::AscendingOrder;
58 QDialog::resizeEvent(event);
67 QDialog::showEvent(event);
72 int width = presetView->viewport()->size().width() - presetView->columnWidth(1) - presetView->columnWidth(2);
76 presetView->setColumnWidth(0, width);
81 std::string name(presetnameLineEdit->text().toStdString());
84 QMessageBox::critical(
this,
86 "Presetname already exists.\n"
87 "You have to enter another one.");
89 else if (presetnameLineEdit->text() ==
"")
91 QMessageBox::critical(
this,
93 "Presetname has to be set.\n"
94 "You have to enter a Presetname.");
104 QModelIndex index(presetView->selectionModel()->currentIndex());
105 if (!index.isValid())
113 if (presetView->selectionModel()->hasSelection())
115 std::string name(presetnameLineEdit->text().toStdString());
118 QMessageBox::critical(
this,
120 "Presetname has to be set.\n"
121 "You have to enter a Presetname.");
126 QMessageBox::critical(
this,
128 "Presetname already exists.\n"
129 "You have to enter another one.");
134 presetView->selectionModel()->currentIndex().row(), name, levelSpinBox->value(), windowSpinBox->value());
140 std::map<std::string, double> &window,
144 levelSpinBox->setValue(initLevel.toInt());
145 windowSpinBox->setValue(initWindow.toInt());
152 QObject::connect(presetView->selectionModel(),
153 SIGNAL(selectionChanged(
const QItemSelection &,
const QItemSelection &)),
159 presetView->resizeColumnsToContents();
164 std::map<std::string, double> levels;
171 std::map<std::string, double> windows;
177 const QItemSelection & )
179 QModelIndexList indexes(selected.indexes());
182 presetnameLineEdit->setText(
"");
183 levelSpinBox->setValue(0);
184 windowSpinBox->setValue(0);
190 presetnameLineEdit->setText(QString(entry.
name.c_str()));
191 levelSpinBox->setValue((
int)entry.
level);
192 windowSpinBox->setValue((
int)entry.
window);
197 std::map<std::string, double> &windows,
199 : QAbstractTableModel(parent)
201 for (
auto iter = levels.begin(); iter != levels.end(); ++iter)
203 m_Entries.push_back(
Entry(iter->first, iter->second, windows[iter->first]));
209 for (
auto iter = m_Entries.begin(); iter != m_Entries.end(); ++iter)
211 levels[iter->name] = iter->level;
217 for (
auto iter = m_Entries.begin(); iter != m_Entries.end(); ++iter)
219 windows[iter->name] = iter->window;
225 this->beginInsertRows(QModelIndex(), (
int)m_Entries.size(), (int)m_Entries.size());
227 m_Entries.push_back(
Entry(name, level, window));
229 this->endInsertRows();
234 for (
auto iter = m_Entries.begin(); iter != m_Entries.end(); ++iter)
236 if (iter->name == name)
245 int row = index.row();
247 this->beginRemoveRows(QModelIndex(), row, row);
249 m_Entries.erase(m_Entries.begin() + row);
251 this->endRemoveRows();
259 m_Entries[row].name = name;
260 m_Entries[row].level = level;
261 m_Entries[row].window = window;
263 this->dataChanged(index(row, 0), index(row, 2));
269 int row = index.row();
271 if (row < 0 || (
unsigned int)row >= m_Entries.size())
272 return Entry(
"", 0, 0);
274 return m_Entries[row];
279 return (
int)m_Entries.size();
289 if (role == Qt::DisplayRole)
291 switch (index.column())
294 return QVariant(QString(m_Entries[index.row()].name.c_str()));
297 return QVariant(m_Entries[index.row()].level);
300 return QVariant(m_Entries[index.row()].window);
308 Qt::Orientation orientation,
311 if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
316 return QVariant(
"Preset");
318 return QVariant(
"Level");
320 return QVariant(
"Window");
PresetTableModel(std::map< std::string, double > &levels, std::map< std::string, double > &windows, QObject *parent=nullptr)
void getWindows(std::map< std::string, double > &windows)
void ListViewSelectionChanged(const QItemSelection &, const QItemSelection &)
bool contains(std::string &name)
int columnCount(const QModelIndex &) const override
void removePreset(const QModelIndex &)
void addPreset(std::string &name, double level, double window)
int rowCount(const QModelIndex &) const override
QVariant data(const QModelIndex &index, int) const override
std::map< std::string, double > getLevelPresets()
PresetTableModel * m_TableModel
void setPresets(std::map< std::string, double > &level, std::map< std::string, double > &window, QString initLevel, QString initWindow)
std::map< std::string, double > getWindowPresets()
QmitkLevelWindowPresetDefinitionDialog(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
void changePreset(int row, std::string &name, double level, double window)
void sortPresets(int index)
void showEvent(QShowEvent *event) override
~QmitkLevelWindowPresetDefinitionDialog()
Entry getPreset(const QModelIndex &) const
void getLevels(std::map< std::string, double > &levels)
QSortFilterProxyModel m_SortModel
QVariant headerData(int section, Qt::Orientation orientation, int) const override
void resizeEvent(QResizeEvent *event) override