Back to index

fet  5.18.0
activitytagsform.cpp
Go to the documentation of this file.
00001 //
00002 //
00003 // Description: This file is part of FET
00004 //
00005 //
00006 // Author: Lalescu Liviu <Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)>
00007 // Copyright (C) 2005 Liviu Lalescu <http://lalescu.ro/liviu/>
00008 //
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "timetable_defs.h"
00019 #include "timetable.h"
00020 #include "fet.h"
00021 #include "activitytagsform.h"
00022 #include "studentsset.h"
00023 #include "teacher.h"
00024 #include "subject.h"
00025 #include "activitytag.h"
00026 
00027 #include <QInputDialog>
00028 
00029 #include <QMessageBox>
00030 
00031 #include <QListWidget>
00032 #include <QAbstractItemView>
00033 
00034 #include <QSplitter>
00035 #include <QSettings>
00036 #include <QObject>
00037 #include <QMetaObject>
00038 
00039 extern const QString COMPANY;
00040 extern const QString PROGRAM;
00041 
00042 ActivityTagsForm::ActivityTagsForm(QWidget* parent): QDialog(parent)
00043 {
00044        setupUi(this);
00045        
00046        currentActivityTagTextEdit->setReadOnly(true);
00047 
00048        renameActivityTagPushButton->setDefault(true);
00049 
00050        activityTagsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00051 
00052        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00053        connect(addActivityTagPushButton, SIGNAL(clicked()), this, SLOT(addActivityTag()));
00054        connect(removeActivityTagPushButton, SIGNAL(clicked()), this, SLOT(removeActivityTag()));
00055        connect(renameActivityTagPushButton, SIGNAL(clicked()), this, SLOT(renameActivityTag()));
00056        connect(sortActivityTagsPushButton, SIGNAL(clicked()), this, SLOT(sortActivityTags()));
00057        connect(activityTagsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(activityTagChanged(int)));
00058        connect(activateActivityTagPushButton, SIGNAL(clicked()), this, SLOT(activateActivityTag()));
00059        connect(deactivateActivityTagPushButton, SIGNAL(clicked()), this, SLOT(deactivateActivityTag()));
00060        connect(activityTagsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(renameActivityTag()));
00061        connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
00062 
00063        centerWidgetOnScreen(this);
00064        restoreFETDialogGeometry(this);
00065        //restore splitter state
00066        QSettings settings(COMPANY, PROGRAM);
00067        if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
00068               splitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
00069               
00070        activityTagsListWidget->clear();
00071        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00072               ActivityTag* sbt=gt.rules.activityTagsList[i];
00073               activityTagsListWidget->addItem(sbt->name);
00074        }
00075               
00076        if(activityTagsListWidget->count()>0)
00077               activityTagsListWidget->setCurrentRow(0);
00078 }
00079 
00080 
00081 ActivityTagsForm::~ActivityTagsForm()
00082 {
00083        saveFETDialogGeometry(this);
00084        //save splitter state
00085        QSettings settings(COMPANY, PROGRAM);
00086        settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
00087 }
00088 
00089 void ActivityTagsForm::addActivityTag()
00090 {
00091        bool ok = FALSE;
00092        ActivityTag* sbt=new ActivityTag();
00093        sbt->name = QInputDialog::getText( this, tr("Add activity tag"), tr("Please enter activity tag's name") ,
00094         QLineEdit::Normal, QString(), &ok );
00095 
00096        if ( ok && !((sbt->name).isEmpty()) ){
00097               // user entered something and pressed OK
00098               if(!gt.rules.addActivityTag(sbt)){
00099                      QMessageBox::information( this, tr("Activity tag insertion dialog"),
00100                             tr("Could not insert item. Must be a duplicate"));
00101                      delete sbt;
00102               }
00103               else{
00104                      activityTagsListWidget->addItem(sbt->name);
00105                      activityTagsListWidget->setCurrentRow(activityTagsListWidget->count()-1);
00106               }
00107        }
00108        else{
00109               if(ok){ //the user entered nothing
00110                      QMessageBox::information(this, tr("FET information"), tr("Incorrect name"));
00111               }
00112               delete sbt;// user entered nothing or pressed Cancel
00113        }
00114 }
00115 
00116 void ActivityTagsForm::removeActivityTag()
00117 {
00118        int i=activityTagsListWidget->currentRow();
00119        if(activityTagsListWidget->currentRow()<0){
00120               QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
00121               return;
00122        }
00123 
00124        QString text=activityTagsListWidget->currentItem()->text();
00125        int activity_tag_ID=gt.rules.searchActivityTag(text);
00126        if(activity_tag_ID<0){
00127               QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
00128               return;
00129        }
00130 
00131        if(QMessageBox::warning( this, tr("FET"),
00132               tr("Are you sure you want to delete this activity tag?"),
00133               tr("Yes"), tr("No"), 0, 0, 1 ) == 1)
00134               return;
00135 
00136        int tmp=gt.rules.removeActivityTag(text);
00137        if(tmp){
00138               activityTagsListWidget->setCurrentRow(-1);
00139               QListWidgetItem* item;
00140               item=activityTagsListWidget->takeItem(i);
00141               delete item;
00142               
00143               if(i>=activityTagsListWidget->count())
00144                      i=activityTagsListWidget->count()-1;
00145               if(i>=0)
00146                      activityTagsListWidget->setCurrentRow(i);
00147               else
00148                      currentActivityTagTextEdit->setPlainText(QString(""));
00149        }
00150 }
00151 
00152 void ActivityTagsForm::renameActivityTag()
00153 {
00154        int i=activityTagsListWidget->currentRow();
00155        if(activityTagsListWidget->currentRow()<0){
00156               QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
00157               return;
00158        }
00159        
00160        QString initialActivityTagName=activityTagsListWidget->currentItem()->text();
00161 
00162        int activity_tag_ID=gt.rules.searchActivityTag(initialActivityTagName);
00163        if(activity_tag_ID<0){
00164               QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
00165               return;
00166        }
00167 
00168        bool ok = FALSE;
00169        QString finalActivityTagName;
00170        finalActivityTagName = QInputDialog::getText( this, tr("Rename activity tag"), tr("Please enter new activity tag's name") ,
00171         QLineEdit::Normal, initialActivityTagName, &ok );
00172 
00173        if ( ok && !(finalActivityTagName.isEmpty()) ){
00174               // user entered something and pressed OK
00175               if(gt.rules.searchActivityTag(finalActivityTagName)>=0){
00176                      QMessageBox::information( this, tr("Activity tag insertion dialog"),
00177                             tr("Could not modify item. New name must be a duplicate"));
00178               }
00179               else{
00180                      gt.rules.modifyActivityTag(initialActivityTagName, finalActivityTagName);
00181                      activityTagsListWidget->item(i)->setText(finalActivityTagName);
00182                      activityTagChanged(activityTagsListWidget->currentRow());
00183               }
00184        }
00185 }
00186 
00187 void ActivityTagsForm::sortActivityTags()
00188 {
00189        gt.rules.sortActivityTagsAlphabetically();
00190 
00191        activityTagsListWidget->clear();
00192        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00193               ActivityTag* sbt=gt.rules.activityTagsList[i];
00194               activityTagsListWidget->addItem(sbt->name);
00195        }
00196 
00197        if(activityTagsListWidget->count()>0)
00198               activityTagsListWidget->setCurrentRow(0);
00199 }
00200 
00201 void ActivityTagsForm::activityTagChanged(int index)
00202 {
00203        if(index<0){
00204               currentActivityTagTextEdit->setPlainText(QString(""));
00205               return;
00206        }
00207        
00208        ActivityTag* st=gt.rules.activityTagsList.at(index);
00209        assert(st);
00210        QString s=st->getDetailedDescriptionWithConstraints(gt.rules);
00211        currentActivityTagTextEdit->setPlainText(s);
00212 }
00213 
00214 void ActivityTagsForm::activateActivityTag()
00215 {
00216        if(activityTagsListWidget->currentRow()<0){
00217               QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
00218               return;
00219        }
00220 
00221        QString text=activityTagsListWidget->currentItem()->text();
00222        int count=gt.rules.activateActivityTag(text);
00223        QMessageBox::information(this, tr("FET information"), tr("Activated a number of %1 activities").arg(count));
00224 }
00225 
00226 void ActivityTagsForm::deactivateActivityTag()
00227 {
00228        if(activityTagsListWidget->currentRow()<0){
00229               QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
00230               return;
00231        }
00232 
00233        QString text=activityTagsListWidget->currentItem()->text();
00234        int count=gt.rules.deactivateActivityTag(text);
00235        QMessageBox::information(this, tr("FET information"), tr("De-activated a number of %1 activities").arg(count));
00236 }
00237 
00238 void ActivityTagsForm::help()
00239 {
00240        QMessageBox::information(this, tr("FET help on activity tags"), 
00241         tr("Activity tag is a field which can be used or not, depending on your wish (optional field)."
00242         " It is designed to help you with some constraints. Each activity has a possible empty list of activity tags"
00243         " (if you don't use activity tags, the list will be empty)"));
00244 }