Ignore:
Timestamp:
Apr 6, 2012, 11:57:19 AM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
818201
Parents:
575343
git-author:
Michael Ankele <ankele@…> (03/22/12 12:27:01)
git-committer:
Frederik Heber <heber@…> (04/06/12 11:57:19)
Message:

made QtWorldView a QTreeWidget

Location:
src/UIElements/Views/Qt4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/QtWorldView.cpp

    r575343 r79b59b  
    3636// these attributes are skiped so far
    3737const int QtWorldView::COLUMNCOUNT = COLUMNTYPES_MAX;
    38 const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula"/*,"Size"*/};
     38const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula","Occurrence"/*,"Size"*/};
    3939
    4040QtWorldView::QtWorldView(QWidget * _parent) :
    41   QTableWidget (_parent),
     41  QTreeWidget (_parent),
    4242  Observer("QtWorldView")
    4343{
    44   setRowCount(0);
    4544  setColumnCount(COLUMNCOUNT);
     45  setSelectionMode(QAbstractItemView::MultiSelection);
    4646
    47   for(int i=0; i<COLUMNCOUNT;++i) {
    48     QTableWidgetItem *heading = new QTableWidgetItem();
    49     std::cout << "Creating heading item " << heading << "." << std::endl;
    50     heading->setText(QString(COLUMNNAMES[i]));
    51     setHorizontalHeaderItem(i,heading);
    52   }
     47  QStringList header;
     48  for(int i=0; i<COLUMNCOUNT;++i)
     49    header << COLUMNNAMES[i];
     50  setHeaderLabels(header);
    5351
    5452  molecules = World::getInstance().getMolecules();
     
    5654  update(molecules);
    5755
    58   connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
    59   connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int)));
     56  //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
     57  connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
    6058
    6159}
     
    6866void QtWorldView::update(Observable *publisher) {
    6967  int numMolecules = molecules->ListOfMolecules.size();
    70   setRowCount(numMolecules);
     68  clear();
    7169  molSelection.resize(numMolecules);
     70
     71  // list of (unique) formulas in the world
     72  std::vector<Formula> formula;
     73
    7274  int i;
    7375  MoleculeList::iterator iter;
     
    7678      ++i,++iter) {
    7779
     80    // find group if already in list
     81    QTreeWidgetItem *groupItem = NULL;
     82    for (unsigned int j=0;j<formula.size();j++)
     83      if ((*iter)->getFormula() == formula[j]){
     84        groupItem = topLevelItem(j);
     85        break;
     86      }
     87
     88    // new molecule type -> create new group
     89    if (!groupItem){
     90      formula.push_back((*iter)->getFormula());
     91      groupItem = new QTreeWidgetItem(this);
     92      groupItem->setText(0, QString((*iter)->getName().c_str()));
     93      groupItem->setText(1, QString::number((*iter)->getAtomCount()));
     94      groupItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
     95      groupItem->setText(3, "0");
     96    }
     97
     98    // add molecule
     99    QTreeWidgetItem *molItem = new QTreeWidgetItem(groupItem);
     100    molItem->setText(0, QString((*iter)->getName().c_str()));
     101    molItem->setText(1, QString::number((*iter)->getAtomCount()));
     102    molItem->setText(2, QString((*iter)->getFormula().toString().c_str()));
    78103    const int index = (*iter)->IndexNr;
    79     QTableWidgetItem *indexWidget = new QTableWidgetItem();
    80     //std::cout << "Creating index item " << indexWidget << "." << std::endl;
    81     indexWidget->setText(QString::number(index));
    82     indexWidget->setData(Qt::UserRole,QVariant(index));
    83     setVerticalHeaderItem(i,indexWidget);
     104    molItem->setData(0, Qt::UserRole, QVariant(index));
    84105
    85     const string name = (*iter)->getName();
    86     QTableWidgetItem *nameWidget = new QTableWidgetItem();
    87     //std::cout << "Creating name item " << nameWidget << " at " << i << "," << NAME << "." << std::endl;
    88     nameWidget->setText(QString(name.c_str()));
    89     setItem(i,NAME,nameWidget);
    90106
    91     const int atomCount = (*iter)->getAtomCount();
    92     QTableWidgetItem *countWidget= new QTableWidgetItem();
    93     //std::cout << "Creating count item " << countWidget << " at " << i << "," << ATOMCOUNT << "." << std::endl;
    94     countWidget->setText(QString::number(atomCount));
    95     countWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
    96     setItem(i,ATOMCOUNT,countWidget);
     107    // increase group occurrence
     108    int count = groupItem->text(3).toInt() + 1;
     109    groupItem->setText(3, QString::number(count));
    97110
    98     const Formula formula = (*iter)->getFormula();
    99     QTableWidgetItem *formulaWidget= new QTableWidgetItem();
    100     //std::cout << "Creating formula item " << formulaWidget << " at " << i << "," << FORMULA << "." << std::endl;
    101     formulaWidget->setText(QString(formula.toString().c_str()));
    102     formulaWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
    103     setItem(i,FORMULA,formulaWidget);
    104 
    105     molSelection[i]=nameWidget->isSelected();
     111    //molSelection[i]=nameWidget->isSelected();
    106112  }
    107113}
     
    110116}
    111117
    112 void QtWorldView::moleculeChanged(int row, int column) {
    113   int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
     118void QtWorldView::moleculeChanged() {
     119  /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
    114120  molecule *mol = molecules->ReturnIndex(idx);
    115121  string cellValue = item(row,NAME)->text().toStdString();
     
    119125  else if(cellValue==""){
    120126    item(row,NAME)->setText(QString(mol->getName().c_str()));
    121   }
     127  }*/
    122128}
    123129
    124130
    125 void QtWorldView::cellSelected(int row, int column){
     131void QtWorldView::rowSelected(){
    126132  //std::cout << "Selection in (" << row << "," << column << "): " << item(row,column) << std::endl;
    127   bool state = item(row,column)->isSelected();
     133  /*bool state = item(row,column)->isSelected();
    128134  for(int i = 0; i<COLUMNCOUNT; i++){
    129135    //std::cout << "Setting " << i << "-th item " << item(row,i) << " in row " << row << " to state selected." << std::endl;
     
    144150      molSelection[i]=state;
    145151    }
    146   }
     152  }*/
    147153}
  • src/UIElements/Views/Qt4/QtWorldView.hpp

    r575343 r79b59b  
    1515
    1616
    17 #include <QtGui/QTableWidget>
     17#include <QtGui/QTreeWidget>
    1818#include "CodePatterns/Observer/Observer.hpp"
    1919
     
    2121class MoleculeListClass;
    2222
    23 class QtWorldView : public QTableWidget, public Observer
     23class QtWorldView : public QTreeWidget, public Observer
    2424{
    2525  Q_OBJECT
     
    3434
    3535  static const int COLUMNCOUNT;
    36   enum {NAME,ATOMCOUNT,FORMULA,COLUMNTYPES_MAX} COLUMNTYPES;
     36  enum {NAME,ATOMCOUNT,FORMULA,OCCURRENCE,COLUMNTYPES_MAX} COLUMNTYPES;
    3737  static const char *COLUMNNAMES[];
    3838
    3939private slots:
    40   void moleculeChanged(int row, int column);
     40  void moleculeChanged();
    4141
    42   void cellSelected(int row, int column);
     42  void rowSelected();
    4343
    4444signals:
Note: See TracChangeset for help on using the changeset viewer.