Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help with extending QTableWidgetItem
Forum Updated to NodeBB v4.3 + New Features

Help with extending QTableWidgetItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 115 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leotocca
    wrote on last edited by leotocca
    #1

    Hi, this is my first time programming a gui using QtWidgets (and my first time programming with a gui other than VB5). I need to develop for a university lab a simplified spreadsheet (with only average, maximum, minimum and sum as possible operations) using Qt and the observer design pattern. From what I understand I can create a Cell class that extends QTableWidgetItem (which needs to be both an observer and a subject,), and a Spreadsheet that extends QTableWidget instead. I would like to be able to "save" in the cell either a double value or a formula (so I think a string). however, I can't figure out how to make it so that through the GUI I can edit the cell in such a way that it can then be used by other cells. Unfortunately, I don't think I can use "signals" (for example the cellActivated signal) since the logical part of updating the values is up to me.

    Here are the definitions of my class in the Cell.h file

    class Cell : public QTableWidgetItem, public Subject, public Observer {
        // every cell is both a Subject and an Observer
    public:
        // TODO: find how the constructor must be
        //Cell(double v);
        ~Cell() override = default;
    
        void setValue(double v);
        double getValue() const;
    
        void setData(int role, const QVariant &value) override;
        double getData();
    
        void setCustomValue(bool cv);
        bool checkCustomValue() const;
    
        void selectCells(std::list<std::shared_ptr<Cell>> cs);
        void addCell(Cell& c);
        std::list<double> extractValues(std::list<std::shared_ptr<Cell>>& cs);
    
        void Cell::setFormula(int fType, std::list<std::shared_ptr<Cell>>& involvedCells, const std::string& f);
        const std::shared_ptr<Formula>& Cell::getFormula() const ;
        void Cell::removeFormula();
    
        // from subject and observer
    
        void notify() override; // virtual is redundant
        void update() override;
        void subscribe(Observer *o) override;
        void unsubscribe(Observer *o) override;
    
    private:
        // TODO find QT variables
        // TODO Qstring for saving formula
        QVariant value;
        // QString formula = nullptr;
        // double value;
        bool customValue = false; // variable to check if the cell has been modified since its creation
        // bool isText; maybe to check if the formula is correct or is only text
        std::shared_ptr<Formula> formula;
        std::list<std::shared_ptr<Cell>> cellSelection; // list of shared pointers to involved cells-> I want to be able to do a cell selection
        std::list<Observer *> observers;
    };
    

    For example I don't know if I need to store the variable as a double variable or a QVariant etc.

    Thanks in advance to anyone who would like to answer me.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved