diff options
Diffstat (limited to 'src/gui/profileDialog.cpp')
-rw-r--r-- | src/gui/profileDialog.cpp | 186 |
1 files changed, 50 insertions, 136 deletions
diff --git a/src/gui/profileDialog.cpp b/src/gui/profileDialog.cpp index 2cbc155..07a97cf 100644 --- a/src/gui/profileDialog.cpp +++ b/src/gui/profileDialog.cpp @@ -15,165 +15,79 @@ */ #include "profileDialog.h" -#include "ui_profileDialog.h" -#include <src/gui/mainWindow.h> -#include <iostream> -profileDialog::profileDialog(QWidget * parent): - QDialog(parent), - uidiag(new Ui::Dialog) +profileDialog::profileDialog(QWidget * parent) : + QDialog(parent) { - uidiag->setupUi(this); - content = new QTableView(uidiag->widget); - uidiag->gridLayout->addWidget(content); + setupUi(this); - /*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(); + _profiles = new QSettings("openslx", "profiles", this); + _current = _profiles->value("current").toString(); + listWidget->addItems(_profiles->childGroups()); + connect(addButton, SIGNAL(clicked()), this, SLOT(add())); + connect(loadButton, SIGNAL(clicked()), this, SLOT(load())); + connect(removeButton, SIGNAL(clicked()), this, SLOT(remove())); } profileDialog::~profileDialog() { - // TODO Auto-generated destructor stub } -void profileDialog::setUpProfile() +void profileDialog::add() { - QStringList list = MainWindow::getWindow()->getProfilList(); - for (int i=0; i<list.size(); i++) - { - model->insertRow(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); - } + _current = ""; + save(); } -void profileDialog::removeProfile() +void profileDialog::remove() { - QTableView *temp = static_cast<QTableView*>(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(); + if (listWidget->currentItem()) + { + _profiles->remove(listWidget->currentItem()->text()); + listWidget->clear(); + listWidget->addItems(_profiles->childGroups()); + } } -void profileDialog::onLoad() +void profileDialog::save() { - QTableView *temp = static_cast<QTableView*>(content); - QItemSelectionModel *selectionModel = temp->selectionModel(); - - QModelIndexList indexes = selectionModel->selectedRows(); - QModelIndex index; - if (indexes.size()>1) + if (_current == "") { - QMessageBox::information(this, "PVS", tr("You can only load one profile at time")); + QString profile = QInputDialog::getText(this, tr("New Profile"), tr("Save profile as:")); + if (!profile.isEmpty()) + { + _current = profile; + _profiles->setValue("current", _current); + } + else + return; } - else if(indexes.size() == 1) + QList<ConnectionFrame*> clients = MainWindow::getConnectionWindow()->getAllFrameOnWindow(); + _profiles->beginGroup(_current); + foreach (ConnectionFrame *client, clients) { - foreach(index, indexes) - { - //int row = content->currentIndex().row(); - QString current = model->index(content->currentIndex().row(), 0).data(Qt::DisplayRole).toString(); - MainWindow::getWindow()->loadSettings(current); - } + QString key = client->getTaskbarTitle(); + QPoint value = client->pos(); + _profiles->setValue(key, value); } - - emit accept(); + _profiles->endGroup(); + listWidget->clear(); + listWidget->addItems(_profiles->childGroups()); } -void profileDialog::selectionChange(const QModelIndex & index) +void profileDialog::load() { - uidiag->remove->setDisabled(false); - uidiag->edit->setDisabled(false); - uidiag->add->setDisabled(false); - uidiag->load->setDisabled(false); + if (listWidget->currentItem()) + _current = listWidget->currentItem()->text(); + QList<ConnectionFrame*> clients = MainWindow::getConnectionWindow()->getAllFrameOnWindow(); + _profiles->beginGroup(_current); + foreach (ConnectionFrame *client, clients) + { + QString key = client->getTaskbarTitle(); + client->move(_profiles->value(key).toPoint()); + } + _profiles->endGroup(); + _profiles->setValue("current", _current); } - -void profileDialog::close() -{ - close(); -} - - |