/* # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING # # If you have any feedback please consult http://openslx.org/feedback and # send your suggestions, praise, or complaints to feedback@openslx.org # # General information about OpenSLX can be found at http://openslx.org/ # ----------------------------------------------------------------------------- # profileDialog.cpp # - GUI to define the profile. # ----------------------------------------------------------------------------- */ #include "profileDialog.h" #include "ui_profileDialog.h" #include #include profileDialog::profileDialog(QWidget * parent): QDialog(parent), uidiag(new Ui::Dialog) { uidiag->setupUi(this); content = new QTableView(uidiag->widget); uidiag->gridLayout->addWidget(content); /*Das Modelfestlegen, wo die Clientname angezeigt werden.*/ model = new QStandardItemModel(0,1,content); //Leere Tabelle mit einer Spalte erstellen model->setHeaderData(0, Qt::Horizontal, tr("Profile")); //Spalte name definieren content->setModel(model); QItemSelectionModel *selectionModel = new QItemSelectionModel(model); content->setSelectionModel(selectionModel); QHeaderView *headerView = content->horizontalHeader(); headerView->setStretchLastSection(true); content->setEditTriggers(QAbstractItemView::NoEditTriggers); //Die Einträge in der Tabelle werden nicht editierbar. content->setSelectionMode(QAbstractItemView::ExtendedSelection); //Damit mehere Einträge selektierbar werden. content->resizeColumnToContents(0); uidiag->add->setDisabled(true); uidiag->edit->setDisabled(true); uidiag->edit->setVisible(false); uidiag->remove->setDisabled(true); uidiag->load->setDisabled(true); uidiag->lineEdit->setDisabled(true); setUpProfile(); connect(uidiag->add, SIGNAL(clicked ()), this, SLOT(AddProfile())); connect(uidiag->new_2, SIGNAL(clicked ()), this, SLOT(onNew())); connect(uidiag->load, SIGNAL(clicked ()), this, SLOT(onLoad())); connect(uidiag->remove, SIGNAL(clicked ()), this, SLOT(removeProfile())); connect(uidiag->close, SIGNAL(clicked ()), this, SLOT(accept())); connect(content, SIGNAL(clicked(const QModelIndex)), this, SLOT(selectionChange(const QModelIndex))); //show(); } profileDialog::~profileDialog() { // TODO Auto-generated destructor stub } void profileDialog::setUpProfile() { QStringList list = MainWindow::getWindow()->getProfilList(); for (int i=0; iinsertRow(0, QModelIndex()); model->setData(model->index(0, 0, QModelIndex()),list.at(i)); } } void profileDialog::AddProfile() { QString name = QString(uidiag->lineEdit->text()); if (!ProfilList.contains(name)) { if (!name.isEmpty()) { model->insertRow(0, QModelIndex()); model->setData(model->index(0, 0, QModelIndex()),name); ProfilList.append(name); MainWindow::getWindow()->saveSettings(name); uidiag->lineEdit->setText(""); } else { QString message = QString(tr("This field can't be empty.")); QMessageBox::information(this, "PVS", message); } } else { QString message = QString(tr("This name is already in the list.")); QMessageBox::information(this, "PVS", message); } } void profileDialog::removeProfile() { QTableView *temp = static_cast(content); QItemSelectionModel *selectionModel = temp->selectionModel(); QModelIndexList indexes = selectionModel->selectedRows(); QModelIndex index; foreach(index, indexes) { int row = content->currentIndex().row(); QString current = model->index(content->currentIndex().row(), 0).data(Qt::DisplayRole).toString(); model->removeRow(row, QModelIndex()); ProfilList.removeOne(current); MainWindow::getWindow()->removeProfil(current); } /* if (temp->model()->rowCount()<=0) {*/ uidiag->remove->setDisabled(true); uidiag->edit->setDisabled(true); uidiag->add->setDisabled(true); uidiag->load->setDisabled(true); //} } void profileDialog::onNew() { uidiag->add->setDisabled(false); uidiag->lineEdit->setDisabled(false); uidiag->lineEdit->setFocus(); } void profileDialog::onLoad() { QTableView *temp = static_cast(content); QItemSelectionModel *selectionModel = temp->selectionModel(); QModelIndexList indexes = selectionModel->selectedRows(); QModelIndex index; if (indexes.size()>1) { QMessageBox::information(this, "PVS", tr("You can only load one profile at time")); } else if(indexes.size() == 1) { foreach(index, indexes) { //int row = content->currentIndex().row(); QString current = model->index(content->currentIndex().row(), 0).data(Qt::DisplayRole).toString(); MainWindow::getWindow()->loadSettings(current); } } emit accept(); } void profileDialog::selectionChange(const QModelIndex & index) { uidiag->remove->setDisabled(false); uidiag->edit->setDisabled(false); uidiag->add->setDisabled(false); uidiag->load->setDisabled(false); } void profileDialog::close() { close(); }