Changeset 8ccf3b for src/UIElements


Ignore:
Timestamp:
Jan 27, 2015, 5:18:30 PM (10 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:
1c3390
Parents:
6770fa
git-author:
Frederik Heber <heber@…> (01/14/15 22:32:34)
git-committer:
Frederik Heber <heber@…> (01/27/15 17:18:30)
Message:

First change to convert QtMoleculeList into QStandardItemModel.

Location:
src/UIElements
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/QtMainWindow.cpp

    r6770fa r8ccf3b  
    9595  QVBoxLayout *layout = new QVBoxLayout(layoutwidget);
    9696
    97   moleculeList = new QtMoleculeList(worldTab);
     97  QTreeView *moleculeListView = new QTreeView(worldTab);
     98  moleculeList = new QtMoleculeList;
     99  moleculeListView->setModel(moleculeList);
    98100  elementList = new QtElementList(worldTab);
    99101  homologyList = new QtHomologyList(worldTab);
     
    129131  layout->addWidget(worldTab);
    130132  splitter2->addWidget(layoutwidget);
    131   worldTab->addTab(moleculeList, "Molecules");
     133  worldTab->addTab(moleculeListView, "Molecules");
    132134  worldTab->addTab(elementList, "All Elements");
    133135  worldTab->addTab(fragmentList, "All Fragments");
  • src/UIElements/Views/Qt4/QtMoleculeList.cpp

    r6770fa r8ccf3b  
    5959const char *QtMoleculeList::COLUMNNAMES[QtMoleculeList::COLUMNCOUNT]={"Name","Visibility", "Atoms","Formula","Occurrence"/*,"Size"*/};
    6060
    61 QtMoleculeList::QtMoleculeList(QWidget * _parent) :
    62   QTreeWidget (_parent),
     61QtMoleculeList::QtMoleculeList() :
    6362  Observer("QtMoleculeList")
    6463{
    6564  setColumnCount(COLUMNCOUNT);
    66   setSelectionMode(QAbstractItemView::MultiSelection);
    67 
    68   QStringList header;
    69   for(int i=0; i<COLUMNCOUNT;++i)
    70     header << COLUMNNAMES[i];
    71   setHeaderLabels(header);
     65//  setSelectionMode(QAbstractItemView::MultiSelection);
     66
     67//  QStringList header;
     68//  for(int i=0; i<COLUMNCOUNT;++i)
     69//    header << COLUMNNAMES[i];
     70//  setHeaderLabels(header);
    7271
    7372  World::getInstance().signOn(this, World::MoleculeInserted);
    7473  World::getInstance().signOn(this, World::MoleculeRemoved);
    75 
    7674
    7775  dirty = true;
     
    8280  refill();
    8381
    84   qRegisterMetaType<QItemSelection>("QItemSelection");
     82//  qRegisterMetaType<QItemSelection>("QItemSelection");
    8583  //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
    86   connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection)));
    87   connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(visibilityChanged(QTreeWidgetItem*, int)));
     84//  connect(selectionModel(),SIGNAL(selectionChanged(QItemSelection, QItemSelection)),this,SLOT(rowsSelected(QItemSelection, QItemSelection)));
     85//  connect(this, SIGNAL(itemChanged(QStandardItem*, int)), this, SLOT(visibilityChanged(QStandardItem*, int)));
    8886}
    8987
     
    9795  ASSERT(0,
    9896      "QtMoleculeList::update() - we did not sign up for any global updates.");
     97}
     98
     99QStandardItem * QtMoleculeList::MoleculeToItem(const molecule * const _mol)
     100{
     101  MoleculeItemBiMap_t::left_const_iterator iter =
     102      MoleculeItemBiMap.left.find(_mol);
     103  ASSERT( iter != MoleculeItemBiMap.left.end(),
     104      "QtMoleculeList - could not find molecule "+_mol->getName()+" in my list.");
     105  return iter->second;
    99106}
    100107
     
    106113      {
    107114        const molecule * const mol = World::getInstance().lastChanged<molecule>();
    108         addItem(mol);
     115        addItem( mol );
    109116        break;
    110117      }
     
    112119      {
    113120        const molecule * const mol = World::getInstance().lastChanged<molecule>();
    114         removeItem(mol);
     121        removeItem(  mol );
    115122        break;
    116123      }
     
    129136
    130137void QtMoleculeList::addGroupItem(
    131     QTreeWidgetItem *&_groupItem,
     138    QStandardItem *&mainitem,
    132139    const std::string &_molecule_formula)
    133140{
    134   _groupItem = new QTreeWidgetItem(this);
    135   formula.insert( std::make_pair(_molecule_formula, _groupItem) );
    136   // fill item
    137   _groupItem->setText(NAME, QString("default"));
    138   _groupItem->setFlags((_groupItem->flags() | Qt::ItemIsUserCheckable) ^ Qt::ItemIsSelectable);
    139   _groupItem->setCheckState(VISIBILITY, Qt::Unchecked);
    140   _groupItem->setText(ATOMCOUNT, QString::number(0));
    141   _groupItem->setText(FORMULA, QString(""));
    142   _groupItem->setText(OCCURRENCE, "0");
    143   _groupItem->setData(0, Qt::UserRole, QVariant(-1));
     141  QList<QStandardItem *> groupItems;
     142  // fill item list
     143  mainitem = new QStandardItem(QString("default"));
     144  mainitem->setFlags(mainitem->flags() ^ Qt::ItemIsSelectable);
     145  formula.insert( std::make_pair(_molecule_formula, mainitem) );
     146  groupItems << mainitem;
     147  QStandardItem *visitem = new QStandardItem;
     148  visitem->setCheckState(Qt::Unchecked);
     149  visitem->setFlags(mainitem->flags() | Qt::ItemIsUserCheckable);
     150  groupItems << visitem;
     151  groupItems << new QStandardItem(QString::number(0));
     152  groupItems << new QStandardItem(QString(""));
     153  groupItems << new QStandardItem(QString::number(0));
     154  invisibleRootItem()->appendRow(groupItems);
     155//  _groupItem->setData(0, Qt::UserRole, QVariant(-1));
    144156}
    145157
    146158void QtMoleculeList::addMoleculeItem(
    147     QTreeWidgetItem *&_groupItem,
     159    QStandardItem *_groupitem,
    148160    const molecule *_mol,
    149161    const std::string &_molecule_formula)
    150162{
    151   QTreeWidgetItem *molItem = new QTreeWidgetItem(_groupItem);
    152   molItem->setText(NAME, QString(_mol->getName().c_str()));
    153   molItem->setFlags(molItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
    154   molItem->setCheckState(VISIBILITY, Qt::Unchecked);
    155   molItem->setText(ATOMCOUNT, QString::number(_mol->getAtomCount()));
    156   molItem->setText(FORMULA, QString(_molecule_formula.c_str()));
    157   const int index = _mol->getId();
    158   molItem->setData(0, Qt::UserRole, QVariant(index));
    159   molItem->setSelected(World::getInstance().isSelected(_mol));
     163  QList<QStandardItem *> molItems;
     164  QStandardItem *mainitem = new QStandardItem(QString(_mol->getName().c_str()));
     165  mainitem->setFlags(mainitem->flags() | Qt::ItemIsSelectable);
     166//  mainitem->setSelected(World::getInstance().isSelected(_mol));
     167  MoleculeItemBiMap.left.insert( std::make_pair(_mol, mainitem) );
     168  molItems << mainitem;
     169  QStandardItem *visitem = new QStandardItem();
     170  visitem->setCheckState(Qt::Unchecked);
     171  visitem->setFlags(mainitem->flags() | Qt::ItemIsUserCheckable);
     172  molItems << visitem;
     173  molItems << new QStandardItem(QString::number(_mol->getAtomCount()));
     174  molItems << new QStandardItem(QString(_molecule_formula.c_str()));
     175  molItems << new QStandardItem(QString::number(0));
     176//  const int index = _mol->getId();
     177//  molItem->setData(0, Qt::UserRole, QVariant(index));
     178  _groupitem->appendRow(molItems);
    160179}
    161180
     
    166185  changing = true;
    167186  // find group if already in list
    168   QTreeWidgetItem *groupItem = NULL;
     187  QStandardItem *groupItem = NULL;
    169188
    170189  const std::string &molecule_formula = _mol->getFormula().toString();
     
    197216
    198217  // increase group occurrence
    199   int count = groupItem->text(OCCURRENCE).toInt() + 1;
    200   groupItem->setText(OCCURRENCE, QString::number(count));
     218  const int index = groupItem->index().row();
     219  QStandardItem *occ_item = invisibleRootItem()->child(index, OCCURRENCE);
     220  int count = occ_item->text().toInt() + 1;
     221  occ_item->setText(QString::number(count));
    201222
    202223  changing = false;
     
    225246  formula.clear();
    226247  FormulaVisibilityCountMap.clear();
     248  MoleculeItemBiMap.clear();
    227249
    228250  for (std::vector<molecule*>::const_iterator iter = molecules.begin();
     
    236258}
    237259
     260/*
    238261void QtMoleculeList::paintEvent(QPaintEvent * event)
    239262{
     
    242265  QTreeWidget::paintEvent(event);
    243266}
     267*/
    244268
    245269void QtMoleculeList::subjectKilled(Observable *publisher) {
    246270}
    247271
    248 void QtMoleculeList::visibilityChanged(QTreeWidgetItem* item, int column)
     272/*
     273void QtMoleculeList::visibilityChanged(QStandardItem* item, int column)
    249274{
    250275  if ((!changing) && (!clearing) && (!ChangingChildrensVisibility))
     
    313338    }
    314339}
     340*/
    315341
    316342void QtMoleculeList::moleculeChanged() {
     
    326352}
    327353
     354/*
    328355void QtMoleculeList::rowsSelected(const QItemSelection & selected, const QItemSelection & deselected){
    329356
     
    369396  selecting = false;
    370397}
     398
     399*/
  • src/UIElements/Views/Qt4/QtMoleculeList.hpp

    r6770fa r8ccf3b  
    1414#endif
    1515
    16 #include <QtGui/QTreeWidget>
     16#include <QtGui/QStandardItem>
     17#include <QtGui/QStandardItemModel>
    1718
     19#include <boost/bimap.hpp>
    1820#include <map>
    1921#include <string>
     
    2628class MoleculeListClass;
    2729
    28 class QtMoleculeList : public QTreeWidget, public Observer
     30class QtMoleculeList : public QStandardItemModel, public Observer
    2931{
    3032  Q_OBJECT
    3133
    3234public:
    33   QtMoleculeList(QWidget * _parent=0);
     35  QtMoleculeList();
    3436  virtual ~QtMoleculeList();
    3537
     
    3840  virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
    3941  virtual void subjectKilled(Observable *publisher);
    40   virtual void paintEvent(QPaintEvent * event);
     42//  virtual void paintEvent(QPaintEvent * event);
    4143  void refill();
    4244
     
    4749private slots:
    4850  void moleculeChanged();
    49   void visibilityChanged(QTreeWidgetItem*, int);
     51//  void visibilityChanged(QStandardItem*, int);
    5052
    51   void rowsSelected(const QItemSelection & selected, const QItemSelection & deselected);
     53//  void rowsSelected(const QItemSelection & selected, const QItemSelection & deselected);
     54
    5255
    5356signals:
     
    6366  bool ChangingChildrensVisibility;
    6467
    65   void addItem(const molecule *_mol);
    66   void addGroupItem(QTreeWidgetItem *&_groupItem, const std::string &_molecule_formula);
    67   void addMoleculeItem(QTreeWidgetItem *&_groupItem, const molecule *_mol, const std::string &molecule_formula);
    68   void removeItem(const molecule *_mol);
     68  QStandardItem * MoleculeToItem(const molecule * const _mol);
     69
     70  void addItem(const molecule * const _mol);
     71  void addGroupItem(QStandardItem *&mainitem, const std::string &_molecule_formula);
     72  void addMoleculeItem(QStandardItem *_groupitem, const molecule *_mol, const std::string &molecule_formula);
     73  void removeItem(const molecule * const _mol);
    6974
    7075  typedef std::map<std::string, unsigned int> FormulaVisibilityCountMap_t;
    7176  FormulaVisibilityCountMap_t FormulaVisibilityCountMap;
    7277
    73   typedef std::map<std::string, QTreeWidgetItem*> FormulaTreeItemMap_t;
     78  typedef std::map<std::string, QStandardItem*> FormulaTreeItemMap_t;
    7479  //!> map of (unique) formulas in the world
    7580  FormulaTreeItemMap_t formula;
     81
     82  typedef boost::bimap<const molecule *, QStandardItem*> MoleculeItemBiMap_t;
     83  MoleculeItemBiMap_t MoleculeItemBiMap;
    7684};
    7785
Note: See TracChangeset for help on using the changeset viewer.