"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.42.0/src/interface/activitytagsform.cpp" (20 Jul 2018, 12929 Bytes) of package /linux/privat/fet-5.42.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "activitytagsform.cpp" see the Fossies "Dox" file reference documentation.

    1 //
    2 //
    3 // Description: This file is part of FET
    4 //
    5 //
    6 // Author: Lalescu Liviu <Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)>
    7 // Copyright (C) 2005 Liviu Lalescu <https://lalescu.ro/liviu/>
    8 //
    9 /***************************************************************************
   10  *                                                                         *
   11  *   This program is free software: you can redistribute it and/or modify  *
   12  *   it under the terms of the GNU Affero General Public License as        *
   13  *   published by the Free Software Foundation, either version 3 of the    *
   14  *   License, or (at your option) any later version.                       *
   15  *                                                                         *
   16  ***************************************************************************/
   17 
   18 #include "timetable_defs.h"
   19 #include "timetable.h"
   20 #include "fet.h"
   21 #include "activitytagsform.h"
   22 #include "studentsset.h"
   23 #include "teacher.h"
   24 #include "subject.h"
   25 #include "activitytag.h"
   26 
   27 #include <QInputDialog>
   28 
   29 #include <QMessageBox>
   30 
   31 #include <QListWidget>
   32 #include <QAbstractItemView>
   33 
   34 #include <QSplitter>
   35 #include <QSettings>
   36 #include <QObject>
   37 #include <QMetaObject>
   38 
   39 extern const QString COMPANY;
   40 extern const QString PROGRAM;
   41 
   42 extern bool students_schedule_ready;
   43 extern bool rooms_schedule_ready;
   44 extern bool teachers_schedule_ready;
   45 
   46 ActivityTagsForm::ActivityTagsForm(QWidget* parent): QDialog(parent)
   47 {
   48     setupUi(this);
   49     
   50     currentActivityTagTextEdit->setReadOnly(true);
   51 
   52     renameActivityTagPushButton->setDefault(true);
   53 
   54     activityTagsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
   55 
   56     connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
   57     connect(addActivityTagPushButton, SIGNAL(clicked()), this, SLOT(addActivityTag()));
   58     connect(removeActivityTagPushButton, SIGNAL(clicked()), this, SLOT(removeActivityTag()));
   59     connect(renameActivityTagPushButton, SIGNAL(clicked()), this, SLOT(renameActivityTag()));
   60 
   61     connect(moveActivityTagUpPushButton, SIGNAL(clicked()), this, SLOT(moveActivityTagUp()));
   62     connect(moveActivityTagDownPushButton, SIGNAL(clicked()), this, SLOT(moveActivityTagDown()));
   63 
   64     connect(sortActivityTagsPushButton, SIGNAL(clicked()), this, SLOT(sortActivityTags()));
   65     connect(activityTagsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(activityTagChanged(int)));
   66     connect(activateActivityTagPushButton, SIGNAL(clicked()), this, SLOT(activateActivityTag()));
   67     connect(deactivateActivityTagPushButton, SIGNAL(clicked()), this, SLOT(deactivateActivityTag()));
   68     connect(activityTagsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(renameActivityTag()));
   69     connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
   70 
   71     connect(printablePushButton, SIGNAL(clicked()), this, SLOT(printableActivityTag()));
   72     connect(notPrintablePushButton, SIGNAL(clicked()), this, SLOT(notPrintableActivityTag()));
   73 
   74     connect(commentsPushButton, SIGNAL(clicked()), this, SLOT(comments()));
   75 
   76     centerWidgetOnScreen(this);
   77     restoreFETDialogGeometry(this);
   78     //restore splitter state
   79     QSettings settings(COMPANY, PROGRAM);
   80     if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
   81         splitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
   82         
   83     activityTagsListWidget->clear();
   84     for(int i=0; i<gt.rules.activityTagsList.size(); i++){
   85         ActivityTag* sbt=gt.rules.activityTagsList[i];
   86         activityTagsListWidget->addItem(sbt->name);
   87     }
   88         
   89     if(activityTagsListWidget->count()>0)
   90         activityTagsListWidget->setCurrentRow(0);
   91 }
   92 
   93 
   94 ActivityTagsForm::~ActivityTagsForm()
   95 {
   96     saveFETDialogGeometry(this);
   97     //save splitter state
   98     QSettings settings(COMPANY, PROGRAM);
   99     settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
  100 }
  101 
  102 void ActivityTagsForm::addActivityTag()
  103 {
  104     bool ok = false;
  105     ActivityTag* sbt=new ActivityTag();
  106     sbt->name = QInputDialog::getText( this, tr("Add activity tag"), tr("Please enter activity tag's name") ,
  107      QLineEdit::Normal, QString(), &ok );
  108 
  109     if ( ok && !((sbt->name).isEmpty()) ){
  110         // user entered something and pressed OK
  111         if(!gt.rules.addActivityTag(sbt)){
  112             QMessageBox::information( this, tr("Activity tag insertion dialog"),
  113                 tr("Could not insert item. Must be a duplicate"));
  114             delete sbt;
  115         }
  116         else{
  117             activityTagsListWidget->addItem(sbt->name);
  118             activityTagsListWidget->setCurrentRow(activityTagsListWidget->count()-1);
  119         }
  120     }
  121     else{
  122         if(ok){ //the user entered nothing
  123             QMessageBox::information(this, tr("FET information"), tr("Incorrect name"));
  124         }
  125         delete sbt;// user entered nothing or pressed Cancel
  126     }
  127 }
  128 
  129 void ActivityTagsForm::removeActivityTag()
  130 {
  131     int i=activityTagsListWidget->currentRow();
  132     if(activityTagsListWidget->currentRow()<0){
  133         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  134         return;
  135     }
  136 
  137     QString text=activityTagsListWidget->currentItem()->text();
  138     int activity_tag_ID=gt.rules.searchActivityTag(text);
  139     if(activity_tag_ID<0){
  140         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  141         return;
  142     }
  143 
  144     if(QMessageBox::warning( this, tr("FET"),
  145         tr("Are you sure you want to delete this activity tag?"),
  146         tr("Yes"), tr("No"), 0, 0, 1 ) == 1)
  147         return;
  148 
  149     int tmp=gt.rules.removeActivityTag(text);
  150     if(tmp){
  151         activityTagsListWidget->setCurrentRow(-1);
  152         QListWidgetItem* item;
  153         item=activityTagsListWidget->takeItem(i);
  154         delete item;
  155         
  156         if(i>=activityTagsListWidget->count())
  157             i=activityTagsListWidget->count()-1;
  158         if(i>=0)
  159             activityTagsListWidget->setCurrentRow(i);
  160         else
  161             currentActivityTagTextEdit->setPlainText(QString(""));
  162     }
  163 }
  164 
  165 void ActivityTagsForm::renameActivityTag()
  166 {
  167     int i=activityTagsListWidget->currentRow();
  168     if(activityTagsListWidget->currentRow()<0){
  169         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  170         return;
  171     }
  172     
  173     QString initialActivityTagName=activityTagsListWidget->currentItem()->text();
  174 
  175     int activity_tag_ID=gt.rules.searchActivityTag(initialActivityTagName);
  176     if(activity_tag_ID<0){
  177         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  178         return;
  179     }
  180 
  181     bool ok = false;
  182     QString finalActivityTagName;
  183     finalActivityTagName = QInputDialog::getText( this, tr("Rename activity tag"), tr("Please enter new activity tag's name") ,
  184      QLineEdit::Normal, initialActivityTagName, &ok );
  185 
  186     if ( ok && !(finalActivityTagName.isEmpty()) ){
  187         // user entered something and pressed OK
  188         if(gt.rules.searchActivityTag(finalActivityTagName)>=0){
  189             QMessageBox::information( this, tr("Activity tag insertion dialog"),
  190                 tr("Could not modify item. New name must be a duplicate"));
  191         }
  192         else{
  193             gt.rules.modifyActivityTag(initialActivityTagName, finalActivityTagName);
  194             activityTagsListWidget->item(i)->setText(finalActivityTagName);
  195             activityTagChanged(activityTagsListWidget->currentRow());
  196         }
  197     }
  198 }
  199 
  200 void ActivityTagsForm::moveActivityTagUp()
  201 {
  202     if(activityTagsListWidget->count()<=1)
  203         return;
  204     int i=activityTagsListWidget->currentRow();
  205     if(i<0 || i>=activityTagsListWidget->count())
  206         return;
  207     if(i==0)
  208         return;
  209         
  210     QString s1=activityTagsListWidget->item(i)->text();
  211     QString s2=activityTagsListWidget->item(i-1)->text();
  212     
  213     ActivityTag* at1=gt.rules.activityTagsList.at(i);
  214     ActivityTag* at2=gt.rules.activityTagsList.at(i-1);
  215     
  216     gt.rules.internalStructureComputed=false;
  217     setRulesModifiedAndOtherThings(&gt.rules);
  218 
  219     teachers_schedule_ready=false;
  220     students_schedule_ready=false;
  221     rooms_schedule_ready=false;
  222     
  223     activityTagsListWidget->item(i)->setText(s2);
  224     activityTagsListWidget->item(i-1)->setText(s1);
  225     
  226     gt.rules.activityTagsList[i]=at2;
  227     gt.rules.activityTagsList[i-1]=at1;
  228     
  229     activityTagsListWidget->setCurrentRow(i-1);
  230     activityTagChanged(i-1);
  231 }
  232 
  233 void ActivityTagsForm::moveActivityTagDown()
  234 {
  235     if(activityTagsListWidget->count()<=1)
  236         return;
  237     int i=activityTagsListWidget->currentRow();
  238     if(i<0 || i>=activityTagsListWidget->count())
  239         return;
  240     if(i==activityTagsListWidget->count()-1)
  241         return;
  242         
  243     QString s1=activityTagsListWidget->item(i)->text();
  244     QString s2=activityTagsListWidget->item(i+1)->text();
  245     
  246     ActivityTag* at1=gt.rules.activityTagsList.at(i);
  247     ActivityTag* at2=gt.rules.activityTagsList.at(i+1);
  248     
  249     gt.rules.internalStructureComputed=false;
  250     setRulesModifiedAndOtherThings(&gt.rules);
  251     
  252     teachers_schedule_ready=false;
  253     students_schedule_ready=false;
  254     rooms_schedule_ready=false;
  255 
  256     activityTagsListWidget->item(i)->setText(s2);
  257     activityTagsListWidget->item(i+1)->setText(s1);
  258     
  259     gt.rules.activityTagsList[i]=at2;
  260     gt.rules.activityTagsList[i+1]=at1;
  261     
  262     activityTagsListWidget->setCurrentRow(i+1);
  263     activityTagChanged(i+1);
  264 }
  265 
  266 void ActivityTagsForm::sortActivityTags()
  267 {
  268     gt.rules.sortActivityTagsAlphabetically();
  269 
  270     activityTagsListWidget->clear();
  271     for(int i=0; i<gt.rules.activityTagsList.size(); i++){
  272         ActivityTag* sbt=gt.rules.activityTagsList[i];
  273         activityTagsListWidget->addItem(sbt->name);
  274     }
  275 
  276     if(activityTagsListWidget->count()>0)
  277         activityTagsListWidget->setCurrentRow(0);
  278 }
  279 
  280 void ActivityTagsForm::activityTagChanged(int index)
  281 {
  282     if(index<0){
  283         currentActivityTagTextEdit->setPlainText(QString(""));
  284         return;
  285     }
  286     
  287     ActivityTag* st=gt.rules.activityTagsList.at(index);
  288     assert(st);
  289     QString s=st->getDetailedDescriptionWithConstraints(gt.rules);
  290     currentActivityTagTextEdit->setPlainText(s);
  291 }
  292 
  293 void ActivityTagsForm::activateActivityTag()
  294 {
  295     if(activityTagsListWidget->currentRow()<0){
  296         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  297         return;
  298     }
  299 
  300     QString text=activityTagsListWidget->currentItem()->text();
  301     int count=gt.rules.activateActivityTag(text);
  302     QMessageBox::information(this, tr("FET information"), tr("Activated a number of %1 activities").arg(count));
  303 }
  304 
  305 void ActivityTagsForm::deactivateActivityTag()
  306 {
  307     if(activityTagsListWidget->currentRow()<0){
  308         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  309         return;
  310     }
  311 
  312     QString text=activityTagsListWidget->currentItem()->text();
  313     int count=gt.rules.deactivateActivityTag(text);
  314     QMessageBox::information(this, tr("FET information"), tr("De-activated a number of %1 activities").arg(count));
  315 }
  316 
  317 void ActivityTagsForm::printableActivityTag()
  318 {
  319     if(activityTagsListWidget->currentRow()<0){
  320         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  321         return;
  322     }
  323 
  324     QString text=activityTagsListWidget->currentItem()->text();
  325     
  326     gt.rules.makeActivityTagPrintable(text);
  327 
  328     activityTagChanged(activityTagsListWidget->currentRow());
  329 }
  330 
  331 void ActivityTagsForm::notPrintableActivityTag()
  332 {
  333     if(activityTagsListWidget->currentRow()<0){
  334         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  335         return;
  336     }
  337 
  338     QString text=activityTagsListWidget->currentItem()->text();
  339     
  340     gt.rules.makeActivityTagNotPrintable(text);
  341 
  342     activityTagChanged(activityTagsListWidget->currentRow());
  343 }
  344 
  345 void ActivityTagsForm::help()
  346 {
  347     QMessageBox::information(this, tr("FET help on activity tags"),
  348      tr("Activity tag is a field which can be used or not, depending on your wish (optional field)."
  349      " It is designed to help you with some constraints. Each activity has a list of activity tags"
  350      " (which may be empty)."));
  351 }
  352 
  353 void ActivityTagsForm::comments()
  354 {
  355     int ind=activityTagsListWidget->currentRow();
  356     if(ind<0){
  357         QMessageBox::information(this, tr("FET information"), tr("Invalid selected activity tag"));
  358         return;
  359     }
  360     
  361     ActivityTag* at=gt.rules.activityTagsList[ind];
  362     assert(at!=NULL);
  363 
  364     QDialog getCommentsDialog(this);
  365     
  366     getCommentsDialog.setWindowTitle(tr("Activity tag comments"));
  367     
  368     QPushButton* okPB=new QPushButton(tr("OK"));
  369     okPB->setDefault(true);
  370     QPushButton* cancelPB=new QPushButton(tr("Cancel"));
  371     
  372     connect(okPB, SIGNAL(clicked()), &getCommentsDialog, SLOT(accept()));
  373     connect(cancelPB, SIGNAL(clicked()), &getCommentsDialog, SLOT(reject()));
  374 
  375     QHBoxLayout* hl=new QHBoxLayout();
  376     hl->addStretch();
  377     hl->addWidget(okPB);
  378     hl->addWidget(cancelPB);
  379     
  380     QVBoxLayout* vl=new QVBoxLayout();
  381     
  382     QPlainTextEdit* commentsPT=new QPlainTextEdit();
  383     commentsPT->setPlainText(at->comments);
  384     commentsPT->selectAll();
  385     commentsPT->setFocus();
  386     
  387     vl->addWidget(commentsPT);
  388     vl->addLayout(hl);
  389     
  390     getCommentsDialog.setLayout(vl);
  391     
  392     const QString settingsName=QString("ActivityTagCommentsDialog");
  393     
  394     getCommentsDialog.resize(500, 320);
  395     centerWidgetOnScreen(&getCommentsDialog);
  396     restoreFETDialogGeometry(&getCommentsDialog, settingsName);
  397     
  398     int t=getCommentsDialog.exec();
  399     saveFETDialogGeometry(&getCommentsDialog, settingsName);
  400     
  401     if(t==QDialog::Accepted){
  402         at->comments=commentsPT->toPlainText();
  403     
  404         gt.rules.internalStructureComputed=false;
  405         setRulesModifiedAndOtherThings(&gt.rules);
  406 
  407         activityTagChanged(ind);
  408     }
  409 }